prismic 1.30.0 → 1.30.1-canary.30ca7c4

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.
@@ -1,4 +1,4 @@
1
- import{n as e}from"./package-DZJSt_MI.mjs";import{$ as t,A as n,B as r,D as i,F as a,G as o,H as s,I as c,J as l,K as u,L as d,N as f,O as p,P as m,Q as h,R as g,S as _,T as v,U as ee,V as y,W as b,X as x,Y as S,Z as C,_ as w,a as T,at as E,b as D,et as O,g as te,h as ne,it as k,j as A,l as re,m as j,nt as M,ot as N,p as P,q as F,r as ie,rt as I,t as L,tt as R,w as z,y as B,z as V}from"./packageJson-BEVwXn1i.mjs";import{i as H,r as ae,t as oe}from"./segment-BpOvsf06.mjs";import{parseArgs as U}from"node:util";import{chmod as se,lstat as W,mkdir as ce,open as le,readFile as ue,realpath as de,rename as fe,rm as pe,stat as me,utimes as he,writeFile as ge}from"node:fs/promises";import{sep as _e}from"node:path";import{fileURLToPath as ve,pathToFileURL as ye}from"node:url";import*as be from"node:crypto";import{createCipheriv as xe,createDecipheriv as Se,createHash as Ce,randomBytes as we,randomUUID as Te}from"node:crypto";import*as Ee from"fs";import{readdir as De,readdirSync as Oe,realpath as ke,realpathSync as Ae,stat as je,statSync as Me}from"fs";import{basename as Ne,dirname as Pe,isAbsolute as Fe,normalize as Ie,posix as Le,relative as Re,resolve as ze,sep as Be}from"path";import{fileURLToPath as Ve}from"url";import{createRequire as He}from"module";import{homedir as Ue,hostname as We,release as Ge}from"node:os";import{setTimeout as Ke}from"node:timers/promises";import{constants as qe,existsSync as Je}from"node:fs";import{exec as Ye,spawn as Xe}from"node:child_process";var Ze=Object.create,Qe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,et=Object.getOwnPropertyNames,tt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty,rt=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),it=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=et(t),a=0,o=i.length,s;a<o;a++)s=i[a],!nt.call(e,s)&&s!==n&&Qe(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=$e(t,s))||r.enumerable});return e},at=(e,t,n)=>(n=e==null?{}:Ze(tt(e)),it(t||!e||!e.__esModule||!nt.call(e,`default`)?Qe(n,`default`,{value:e,enumerable:!0}):n,e));const ot=/([\p{Ll}\d])(\p{Lu})/gu,st=/(\p{Lu})([\p{Lu}][\p{Ll}])/gu,ct=/(\d)\p{Ll}|(\p{L})\d/u,lt=/[^\p{L}\d]+/giu,ut=`$1\0$2`;function dt(e){let t=e.trim();t=t.replace(ot,ut).replace(st,ut),t=t.replace(lt,`\0`);let n=0,r=t.length;for(;t.charAt(n)===`\0`;)n++;if(n===r)return[];for(;t.charAt(r-1)===`\0`;)r--;return t.slice(n,r).split(/\0/g)}function ft(e){let t=dt(e);for(let e=0;e<t.length;e++){let n=t[e],r=ct.exec(n);if(r){let i=r.index+(r[1]??r[2]).length;t.splice(e,1,n.slice(0,i),n.slice(i))}}return t}function pt(e,t){let[n,r,i]=St(e,t);return n+r.map(vt(t?.locale)).join(t?.delimiter??` `)+i}function mt(e,t){let[n,r,i]=St(e,t),a=vt(t?.locale),o=yt(t?.locale),s=t?.mergeAmbiguousCharacters?bt(a,o):xt(a,o);return n+r.map((e,t)=>t===0?a(e):s(e,t)).join(t?.delimiter??``)+i}function ht(e,t){let[n,r,i]=St(e,t),a=vt(t?.locale),o=yt(t?.locale),s=t?.mergeAmbiguousCharacters?bt(a,o):xt(a,o);return n+r.map(s).join(t?.delimiter??``)+i}function gt(e,t){let[n,r,i]=St(e,t),a=vt(t?.locale),o=yt(t?.locale);return n+r.map(bt(a,o)).join(t?.delimiter??` `)+i}function _t(e,t){return pt(e,{delimiter:`_`,...t})}function vt(e){return e===!1?e=>e.toLowerCase():t=>t.toLocaleLowerCase(e)}function yt(e){return e===!1?e=>e.toUpperCase():t=>t.toLocaleUpperCase(e)}function bt(e,t){return n=>`${t(n[0])}${e(n.slice(1))}`}function xt(e,t){return(n,r)=>{let i=n[0];return(r>0&&i>=`0`&&i<=`9`?`_`+i:t(i))+e(n.slice(1))}}function St(e,t={}){let n=t.split??(t.separateNumbers?ft:dt),r=t.prefixCharacters??``,i=t.suffixCharacters??``,a=0,o=e.length;for(;a<e.length;){let t=e.charAt(a);if(!r.includes(t))break;a++}for(;o>a;){let t=o-1,n=e.charAt(t);if(!i.includes(n))break;o=t}return[e.slice(0,a),n(e.slice(a,o)),e.slice(o)]}function Ct(e,t){return(!e||e.endsWith(`
1
+ import{n as e}from"./package-BqcQdJJC.mjs";import{$ as t,A as n,B as r,D as i,F as a,G as o,H as s,I as c,J as l,K as u,L as d,N as f,O as p,P as m,Q as h,R as g,S as _,T as v,U as ee,V as y,W as b,X as x,Y as S,Z as C,_ as w,a as T,at as E,b as D,et as O,g as te,h as ne,it as k,j as A,l as re,m as j,nt as M,ot as N,p as P,q as F,r as ie,rt as I,t as L,tt as R,w as z,y as B,z as V}from"./packageJson-BEVwXn1i.mjs";import{i as H,r as ae,t as oe}from"./segment-VjiN7y08.mjs";import{parseArgs as U}from"node:util";import{chmod as se,lstat as W,mkdir as ce,open as le,readFile as ue,realpath as de,rename as fe,rm as pe,stat as me,utimes as he,writeFile as ge}from"node:fs/promises";import{sep as _e}from"node:path";import{fileURLToPath as ve,pathToFileURL as ye}from"node:url";import*as be from"node:crypto";import{createCipheriv as xe,createDecipheriv as Se,createHash as Ce,randomBytes as we,randomUUID as Te}from"node:crypto";import*as Ee from"fs";import{readdir as De,readdirSync as Oe,realpath as ke,realpathSync as Ae,stat as je,statSync as Me}from"fs";import{basename as Ne,dirname as Pe,isAbsolute as Fe,normalize as Ie,posix as Le,relative as Re,resolve as ze,sep as Be}from"path";import{fileURLToPath as Ve}from"url";import{createRequire as He}from"module";import{homedir as Ue,hostname as We,release as Ge}from"node:os";import{setTimeout as Ke}from"node:timers/promises";import{constants as qe,existsSync as Je}from"node:fs";import{exec as Ye,spawn as Xe}from"node:child_process";var Ze=Object.create,Qe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,et=Object.getOwnPropertyNames,tt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty,rt=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),it=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=et(t),a=0,o=i.length,s;a<o;a++)s=i[a],!nt.call(e,s)&&s!==n&&Qe(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=$e(t,s))||r.enumerable});return e},at=(e,t,n)=>(n=e==null?{}:Ze(tt(e)),it(t||!e||!e.__esModule||!nt.call(e,`default`)?Qe(n,`default`,{value:e,enumerable:!0}):n,e));const ot=/([\p{Ll}\d])(\p{Lu})/gu,st=/(\p{Lu})([\p{Lu}][\p{Ll}])/gu,ct=/(\d)\p{Ll}|(\p{L})\d/u,lt=/[^\p{L}\d]+/giu,ut=`$1\0$2`;function dt(e){let t=e.trim();t=t.replace(ot,ut).replace(st,ut),t=t.replace(lt,`\0`);let n=0,r=t.length;for(;t.charAt(n)===`\0`;)n++;if(n===r)return[];for(;t.charAt(r-1)===`\0`;)r--;return t.slice(n,r).split(/\0/g)}function ft(e){let t=dt(e);for(let e=0;e<t.length;e++){let n=t[e],r=ct.exec(n);if(r){let i=r.index+(r[1]??r[2]).length;t.splice(e,1,n.slice(0,i),n.slice(i))}}return t}function pt(e,t){let[n,r,i]=St(e,t);return n+r.map(vt(t?.locale)).join(t?.delimiter??` `)+i}function mt(e,t){let[n,r,i]=St(e,t),a=vt(t?.locale),o=yt(t?.locale),s=t?.mergeAmbiguousCharacters?bt(a,o):xt(a,o);return n+r.map((e,t)=>t===0?a(e):s(e,t)).join(t?.delimiter??``)+i}function ht(e,t){let[n,r,i]=St(e,t),a=vt(t?.locale),o=yt(t?.locale),s=t?.mergeAmbiguousCharacters?bt(a,o):xt(a,o);return n+r.map(s).join(t?.delimiter??``)+i}function gt(e,t){let[n,r,i]=St(e,t),a=vt(t?.locale),o=yt(t?.locale);return n+r.map(bt(a,o)).join(t?.delimiter??` `)+i}function _t(e,t){return pt(e,{delimiter:`_`,...t})}function vt(e){return e===!1?e=>e.toLowerCase():t=>t.toLocaleLowerCase(e)}function yt(e){return e===!1?e=>e.toUpperCase():t=>t.toLocaleUpperCase(e)}function bt(e,t){return n=>`${t(n[0])}${e(n.slice(1))}`}function xt(e,t){return(n,r)=>{let i=n[0];return(r>0&&i>=`0`&&i<=`9`?`_`+i:t(i))+e(n.slice(1))}}function St(e,t={}){let n=t.split??(t.separateNumbers?ft:dt),r=t.prefixCharacters??``,i=t.suffixCharacters??``,a=0,o=e.length;for(;a<e.length;){let t=e.charAt(a);if(!r.includes(t))break;a++}for(;o>a;){let t=o-1,n=e.charAt(t);if(!i.includes(n))break;o=t}return[e.slice(0,a),n(e.slice(a,o)),e.slice(o)]}function Ct(e,t){return(!e||e.endsWith(`
2
2
  `))&&!t?.force?e:e+`
3
3
  `}function G(e,t){return Ct(t)+e}function wt(e,t){return(!e||e.endsWith(`
4
4
 
@@ -36,7 +36,7 @@ import{n as e}from"./package-DZJSt_MI.mjs";import{$ as t,A as n,B as r,D as i,F
36
36
  * Slice for *${Rt({path:[...e.path,{name:e.name,model:e.field}]})}*
37
37
  */
38
38
  export type ${o} = prismic.Slice<"${t}", ${s?`Simplify<${s}>`:`Record<string, never>`}, ${c?`Simplify<${c}>`:`never`}>
39
- `}),a.push(o)}}let o=J(e.path[0].name,`Document`,`Data`,e.name,`Slice`),s=Tt(a);n.push({name:o,code:`type ${o} = ${s}`}),r.push(o),t=G(`${i}: prismic.SliceZone<${o}>;`,t);break}default:t=G(`${i}: unknown;`,t)}return{code:t,auxiliaryTypes:n,contentTypeNames:r}}function Gt(e){let t=``,n=[],r=[];for(let i in e.fields){let a=e.fields[i],o=Wt({name:i,field:a,path:e.path,fieldConfigs:e.fieldConfigs,tabName:e.tabName});t=K(o.code,t),n.push(...o.auxiliaryTypes),r.push(...o.contentTypeNames)}return{code:t,auxiliaryTypes:n,contentTypeNames:r}}function Kt(e){let t=``,n=[],r=[],i=J(e.model.id,`Document`,`Data`),a=Lt({name:e.model.id,model:e.model}),o=``;for(let t in e.model.json){let{uid:i,...a}=e.model.json[t],s=Gt({fields:a,fieldConfigs:e.fieldConfigs,path:[{name:e.model.id,model:e.model}],tabName:t});o+=s.code,n.push(...s.auxiliaryTypes),r.push(...s.contentTypeNames)}return t=o?q`
39
+ `}),a.push(o)}}let o=J(e.path[0].name,`Document`,`Data`,e.name,`Slice`),s=Tt(a);n.push({name:o,code:`type ${o} = ${s}`}),r.push(o),t=G(`${i}: prismic.SliceZone<${o}>;`,t);break}default:t=G(`${i}: unknown;`,t)}return{code:t,auxiliaryTypes:n,contentTypeNames:r}}function Gt(e){let t=``,n=[],r=[];for(let i in e.fields){let a=Wt({name:i,field:e.fields[i],path:e.path,fieldConfigs:e.fieldConfigs,tabName:e.tabName});t=K(a.code,t),n.push(...a.auxiliaryTypes),r.push(...a.contentTypeNames)}return{code:t,auxiliaryTypes:n,contentTypeNames:r}}function Kt(e){let t=``,n=[],r=[],i=J(e.model.id,`Document`,`Data`),a=Lt({name:e.model.id,model:e.model}),o=``;for(let t in e.model.json){let{uid:i,...a}=e.model.json[t],s=Gt({fields:a,fieldConfigs:e.fieldConfigs,path:[{name:e.model.id,model:e.model}],tabName:t});o+=s.code,n.push(...s.auxiliaryTypes),r.push(...s.contentTypeNames)}return t=o?q`
40
40
  /**
41
41
  * Content for ${a} documents
42
42
  */
@@ -194,4 +194,4 @@ function Br(e){return M(a,e)}const Vr=`prismic.io`,Hr=l({PROD:h(),PRISMIC_SENTRY
194
194
  ${r??n}
195
195
  ${r===void 0?`Enter the code ${t}.`:`Check that the page shows the code ${t}.`}
196
196
  Waiting for the login (the code expires in ${i} ${i===1?`minute`:`minutes`})...
197
- `)}async function ec(e,t){let n=new AbortController,r=setInterval(async()=>{let r=await Z().catch(()=>void 0);e.cancelled||r&&r.login?.session.pendingLogin?.deviceCode!==t.deviceCode&&n.abort()},js),i=Number.isFinite(e.deadline)?AbortSignal.timeout(Math.max(0,e.deadline-Date.now())):void 0;try{return await ri(t,{signal:i?AbortSignal.any([i,n.signal]):n.signal,onUpdate:n=>tc(t,{...n,host:e.host})})}catch(e){if(e instanceof X)throw await tc(t,void 0),e;if(n.signal.aborted)return{status:`logged-out`};if(i?.aborted)return{status:`wait-limit`};throw e}finally{clearInterval(r)}}async function tc(e,t){await Wi(async n=>{let r=(await Z()).login;r?.session.pendingLogin?.deviceCode===e.deviceCode&&await Hi(n,{...r,session:{...r.session,pendingLogin:t}})}).catch(()=>{})}async function nc(e,t,n){return Wi(async r=>{let i=await Z().catch(()=>void 0);if(i&&i.login?.session.pendingLogin?.deviceCode!==t.deviceCode){await oi(n.refreshToken,t).catch(()=>{});return}let a=i?.login?{store:i.login.store,storeReason:i.login.storeReason}:await Vi(r),o={host:e.host,...e.auth0,...n};await Hi(r,{...a,session:o}),e.saved={...a,token:n.accessToken};let s=i?.login?.session;return s?.refreshToken&&await oi(s.refreshToken,s).catch(()=>{}),e.saved})}async function rc(){let e;try{e=await ue(Ns,`utf-8`)}catch{return}try{let t=JSON.parse(e);if(!t||t.latestKnownVersion===void 0&&t.lastUpdateCheckAt===void 0)return}catch{return}try{await pe(Ns,{force:!0})}catch{}}function ic(e,t,n){let{getKey:r,equals:i=(e,t)=>JSON.stringify(e)===JSON.stringify(t)}=n,a={insert:[],update:[],delete:[]};for(let n of e){let e=t.find(e=>r(e)===r(n));e?i(n,e)||a.update.push(n):a.insert.push(n)}for(let n of t)e.some(e=>r(e)===r(n))||a.delete.push(n);return a}function ac(e){return e.insert.length+e.update.length+e.delete.length>0}const oc=[`Slices`,`UID`,`Choice`];function sc(e,t,n){if(t in e)throw new Sc(t);e[t]=n}function cc(e,t){let n=e[t];if(!n)throw new Cc(t);return n}function lc(e,t,n){let r=new Map(n.map(e=>[e.id,e])),i=r.get(t);if(!i)throw new Tc(`Custom type "${t}" does not exist.`);let a=(e,t,n,i)=>{let o=/* @__PURE__ */ new Map;for(let t of e){let[e,...n]=t.split(`.`),r=o.get(e)??[];r.push(n.join(`.`)),o.set(e,r)}return Array.from(o,([e,o])=>{let s=t[e];if(!s)throw new Tc(`Field "${e}" does not exist on type "${n}".`);let c=o.filter(Boolean);if(c.length===0){if(oc.includes(s.type)||e===`uid`)throw new Tc(`Field "${e}" cannot be fetched from a content relationship.`);if(s.type===`Group`)throw new Tc(`Field "${e}" is a group. Select specific subfields.`);return e}if(c.length!==o.length)throw new Tc(`Field "${e}" cannot be selected both directly and through its subfields.`);if(s.type===`Group`)return{id:e,fields:a(c,s.config?.fields??{},n,i)};if(s.type===`Link`&&s.config?.select===`document`){if(!i)throw new Tc(`Content relationships cannot be nested more than once.`);let t=s.config?.customtypes;if(!t||t.length!==1)throw new Tc(`Field "${e}" must target exactly one custom type to select its fields.`);let n=typeof t[0]==`string`?t[0]:t[0].id,o=r.get(n);if(!o)throw new Tc(`Custom type "${n}" does not exist.`);let l=Object.assign({},...Object.values(o.json));return{id:e,customtypes:[{id:n,fields:a(c,l,n,!1)}]}}throw new Tc(`Field "${e}" is not a group or content relationship field.`)})};return a(e,Object.assign({},...Object.values(i.json)),i.id,!0)}function uc(e,t,n){let r;if(n){if(r=t.json[n],!r)throw new Ec(n,t.id)}else{let[n]=e.split(`.`);if(r=Object.values(t.json).find(e=>n in e),!r)throw new Cc(n)}return bc(e,r)}function dc(e,t,n,r=!1){let i=t.variations.find(e=>e.id===n);if(!i)throw new Dc(n,t.id);if(r){if(!i.items||Object.keys(i.items).length===0)throw new Oc(n,t.id);return bc(e,i.items)}return i.primary??={},bc(e,i.primary)}async function fc(e){let[t,n]=await Promise.all([La(e),Ra(e)]);return{customTypes:t,slices:n}}async function pc({customTypes:e,slices:t},n){let r=(e,t)=>({type:e,id:t.id,payload:t}),i=[...e.insert.map(e=>r(`CUSTOM_TYPE_INSERT`,e)),...e.update.map(e=>r(`CUSTOM_TYPE_UPDATE`,e)),...e.delete.map(({id:e})=>r(`CUSTOM_TYPE_DELETE`,{id:e})),...t.insert.map(e=>r(`SLICE_INSERT`,e)),...t.update.map(e=>r(`SLICE_UPDATE`,e)),...t.delete.map(({id:e})=>r(`SLICE_DELETE`,{id:e}))];i.length>0&&await za(i,n)}function mc(e,t,n={}){let{treatNonCanonicalAsChanged:r=!1}=n;return{customTypes:ic(e.customTypes,t.customTypes,{getKey:e=>e.id,equals:(e,t)=>JSON.stringify(hc(e))===JSON.stringify(r?t:hc(t))}),slices:ic(e.slices,t.slices,{getKey:e=>e.id,equals:(e,t)=>JSON.stringify(gc(e))===JSON.stringify(r?t:gc(t))})}}function hc(e){return{...yc(e),json:Object.fromEntries(Object.entries(e.json).map(([e,t])=>[e,_c(t)]))}}function gc(e){return{...yc(e),variations:e.variations.map(e=>{let t=yc(e);return e.primary&&(t.primary=_c(e.primary)),e.items&&(t.items=_c(e.items)),t})}}function _c(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=yc(t);return t.type===`Group`&&t.config?.fields&&n.type===`Group`&&n.config?.fields&&(n.config.fields=_c(t.config.fields)),t.type===`Slices`&&t.config?.choices&&n.type===`Slices`&&n.config?.choices&&(n.config.choices=vc(t.config.choices)),[e,n]}))}function vc(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=yc(t);return t.type===`Slice`&&n.type===`Slice`&&(t[`non-repeat`]&&(n[`non-repeat`]=_c(t[`non-repeat`])),t.repeat&&(n.repeat=_c(t.repeat))),[e,n]}))}function yc(e){return Array.isArray(e)?e.map(yc):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,yc(t)]))}function bc(e,t){let[n,...r]=e.split(`.`);if(r.length===0)return{fields:t,fieldId:n};let i=cc(t,n);if(i.type!==`Group`)throw new wc(n);return i.config??={},i.config.fields??={},bc(r.join(`.`),i.config.fields)}function xc(e){return e.flatMap(e=>Object.values(e.json).flatMap(t=>Object.entries(t).flatMap(([t,n])=>n.type===`Slices`?Object.entries(n.config?.choices??{}).flatMap(([r,i])=>i.type===`SharedSlice`?[]:[{id:r,customTypeId:e.id,sliceZoneId:t,sliceZone:n,model:i}]):[])))}var Sc=class extends Error{name=`FieldExistsError`;constructor(e){super(`Field "${e}" already exists.`)}},Cc=class extends Error{name=`FieldNotFoundError`;constructor(e){super(`Field "${e}" does not exist.`)}},wc=class extends Error{name=`UnsupportedNestedFieldError`;constructor(e){super(`Field "${e}" does not support nested fields.`)}},Tc=class extends Error{name=`FieldSelectionError`},Ec=class extends Error{name=`TabNotFoundError`;constructor(e,t){super(`Tab "${e}" does not exist on type "${t}".`)}},Dc=class extends Error{name=`SliceVariationNotFoundError`;constructor(e,t){super(`Variation "${e}" does not exist on slice "${t}".`)}},Oc=class extends Error{name=`SliceItemsNotFoundError`;constructor(e,t){super(`Variation "${e}" of slice "${t}" has no legacy items zone. To add repeatable fields, add a repeatable group to the slice.`)}};const kc=`prismic.config.json`,Ac=l({type:C(),path:C(),uid:S(C()),lang:S(C()),resolvers:S(x(C(),C()))}),jc=l({repositoryName:C(),documentAPIEndpoint:S(R()),libraries:S(V(C())),routes:S(V(Ac))});async function Mc(e){let t=await Rc();return await ge(t,P(e)),t}async function Nc(){let e=await Ic();try{return await w(e,{schema:jc})}catch{throw new Pc}}var Pc=class extends Error{name=`InvalidPrismicConfigError`;message=`${kc} is invalid. Run \`prismic init\` to re-create a config.`};async function Fc(e){let t=await Ic(),n={...await Nc(),...e};return await ge(t,P(n)),n}async function Ic(){let e=await ne(kc,{stop:`package.json`});if(!e)throw new Lc;return e}var Lc=class extends Error{name=`MissingPrismicConfigError`;message=`Could not find a ${kc} file. Run \`prismic init\` to create a config.`};async function Rc(){try{let e=await ie();return new URL(kc,e)}catch(e){throw e instanceof L?new zc({cause:e}):e}}var zc=class extends Error{name=`UnknownProjectRootError`;constructor(e){super(`Could not find your project root.`,e)}};async function Bc(e){let{routes:t=[]}=await Nc();if(t.some(t=>t.type===e.id))return;let n=Wc(e),r={type:e.id,path:n};await Fc({routes:[...t,r].sort((e,t)=>e.type.localeCompare(t.type))})}async function Vc(e){e.format===`page`?await Bc(e):await Hc(e.id)}async function Hc(e){let{routes:t=[]}=await Nc(),n=t.filter(t=>t.type!==e);t.length!==n.length&&await Fc({routes:n})}function Uc(e,t){return e.find(e=>e.type===t&&!e.uid&&!/[?*+]/.test(e.path))}function Wc(e){let{id:t,repeatable:n}=e,r=t.replaceAll(`_`,`-`).toLowerCase();return n?t===`page`?`/:uid`:`/${r}/:uid`:t===`homepage`?`/`:`/${r}`}const Gc=`slicemachine.config.json`,Kc=l({repositoryName:C(),libraries:S(V(C()))});async function qc(){let e=await Xc();try{return await w(e,{schema:Kc})}catch{throw new Jc}}var Jc=class extends Error{name=`InvalidLegacySliceMachineConfigError`;message=`${Gc} is invalid.`};async function Yc(){let e=await Xc();await pe(e)}async function Xc(){let e=await ne(Gc,{stop:`package.json`});if(!e)throw new Zc;return e}var Zc=class extends Error{name=`MissingLegacySliceMachineConfigError`;message=`Could not find a ${Gc} file.`};async function Qc(){let e;try{e=await Ic()}catch(t){if(t instanceof Lc)e=await Rc();else throw t}let t=new URL(`.`,e);return A(ye(await de(ve(t))))}async function $c(){try{return(await Nc()).repositoryName}catch(e){if(e instanceof Lc)try{return(await qc()).repositoryName}catch{}throw e}}async function el(){let e=(await Nc()).libraries;if(!e||e.length<1)return;let t=await Qc();return e.map(e=>A(new URL(e.replace(/^\//,``),t)))}async function tl(){let e=await Qc();return j(new URL(`tsconfig.json`,e))}const nl=[`next`,`nuxt`,`sveltekit`];async function rl(){let{dependencies:e,devDependencies:t,peerDependencies:n}=await re(),r={...e,...t,...n};if(`next`in r){let{NextJsAdapter:e}=await import(`./nextjs-4lBT3LWb.mjs`);return new e}if(`nuxt`in r){let{NuxtAdapter:e}=await import(`./nuxt-CXMFa4cT.mjs`);return new e}if(`@sveltejs/kit`in r){if(await T(`@sveltejs/kit`)<3){let{SvelteKit2Adapter:e}=await import(`./sveltekit2-xFDbKhF_.mjs`);return new e}let{SvelteKitAdapter:e}=await import(`./sveltekit-B-_UPD7T.mjs`);return new e}throw new il}var il=class extends Error{name=`NoSupportedFrameworkError`;message=`No supported framework found. Run this command in a Next.js, Nuxt, or SvelteKit project.`},al=class extends Error{name=`ModelExistsError`},ol=class extends Error{name=`SliceNotFoundError`;constructor(e){super(`Slice "${e}" does not exist. Run \`prismic slice list\` to see available IDs.`)}},sl=class extends Error{name=`CustomTypeNotFoundError`;constructor(e){super(`Type "${e}" does not exist. Run \`prismic type list\` to see available IDs.`)}};async function cl(e,t,n,r){let i=r.find(e=>e.model.id===t||e.directory.href===n.href);if(!i&&!await j(n))return;let a=m(await Qc(),i?.directory??n),o=i?` (id: ${i.model.id})`:``;throw new al(`A ${e} already exists at ${a}${_e}${o}.`)}async function ll(){return await(await rl()).getEnvironment()??await $c()}async function ul(e){let t=await zr(`**/*.{js,jsx,mjs,ts,tsx,mts,svelte}`,{cwd:ve(await Qc()),absolute:!0,ignore:`**/{node_modules,build,dist,out}/**`});for(let n of t)try{if((await ue(n,`utf8`)).includes(e))return!0}catch{}return!1}async function dl(e,t){await j(e)||await _(e,t)}async function fl(){return await tl()?`ts`:`js`}var pl=class{get localPreviewUrl(){return new URL(this.localPreviewConfig.resolverPath,this.localPreviewConfig.websiteURL).href}get localSimulatorUrl(){return new URL(`slice-simulator`,this.localPreviewConfig.websiteURL).href}async initProject({setup:e}){for(let e of await this.getSliceLibraries())await this.createSliceIndexFile(e);e&&await this.setupProject();let t={repo:await $c(),getToken:Rs,host:await zs()};(await ao(t)).simulator_url||await oo(this.localSimulatorUrl,t),(await eo(t)).results.length===0&&await to(this.localPreviewConfig,t)}async getSliceLibraries(){return await el()??[await this.getDefaultSliceLibrary()]}async getSlices(){return hl(await this.getSliceLibraries(),`*/model.json`)}async getSlice(e){let t=(await this.getSlices()).find(t=>t.model.id===e);if(t)return t;let n=xc((await this.getCustomTypes()).map(e=>e.model)).find(t=>t.id===e);if(n){let{customTypeId:t,sliceZoneId:r}=n;throw new Q(`"${e}" is a legacy slice in "${t}". Upgrade it first: \`prismic slice upgrade-legacy ${e} --from ${t}${r===`body`?``:` --slice-zone ${r}`}\`.`)}throw new ol(e)}async createSlice(e){let[t]=await this.getSliceLibraries(),n=A(new URL(ht(e.name),A(t)));await cl(`slice`,e.id,n,await this.getSlices()),await _(new URL(`model.json`,n),P(gc(e))),await this.createSliceIndexFile(t),await this.createSliceComponent(e,n)}async updateSlice(e){let t=await this.getSlice(e.id);await _(t.modelPath,P(gc(e))),await this.createSliceIndexFile(t.library)}async deleteSlice(e){let t=await this.getSlice(e);await pe(t.directory,{recursive:!0}),await this.createSliceIndexFile(t.library)}async getCustomTypeLibraries(){return[new URL(`customtypes/`,await Qc())]}async getCustomTypes(){return hl(await this.getCustomTypeLibraries(),`*/index.json`)}async getCustomType(e){let t=(await this.getCustomTypes()).find(t=>t.model.id===e);if(!t)throw new sl(e);return t}async createCustomType(e){let[t]=await this.getCustomTypeLibraries(),n=A(new URL(e.id,A(t)));if(await cl(`type`,e.id,n,await this.getCustomTypes()),await _(new URL(`index.json`,n),P(hc(e))),e.format!==`page`)return[];await Bc(e);let r=await Qc();return(await this.writePageFiles(e)).map(({path:t})=>`Skipped ${m(r,t)} (already exists). Run \`prismic gen page ${e.id}\` to get the code.`)}async writePageFiles(e){let{routes:t=[]}=await Nc(),n=(Uc(t,e.id)?.path??Wc(e)).split(`/`).filter(Boolean).map(e=>e.startsWith(`:`)?`[${e.slice(1)}]`:e).join(`/`),r=[];for(let t of await this.getPageFiles(e,n))await j(t.path)?r.push(t):await _(t.path,t.contents);return r}async updateCustomType(e){let t=await this.getCustomType(e.id);await _(t.modelPath,P(hc(e))),await Vc(e)}async deleteCustomType(e){let t=await this.getCustomType(e);await pe(t.directory,{recursive:!0}),await Hc(e)}async getModels(){let[e,t]=await Promise.all([this.getCustomTypes(),this.getSlices()]);return{customTypes:e.map(e=>e.model),slices:t.map(e=>e.model)}}async writeModels(e){for(let t of e.slices.update)await this.updateSlice(t);for(let t of e.slices.delete)await this.deleteSlice(t.id);for(let t of e.slices.insert)await this.createSlice(t);for(let t of e.customTypes.update)await this.updateCustomType(t);for(let t of e.customTypes.delete)await this.deleteCustomType(t.id);let t=[];for(let n of e.customTypes.insert)t.push(...await this.createCustomType(n));return t}async generateTypes(){let e=new URL(`prismicio-types.d.ts`,await Qc()),t=Qt({customTypeModels:(await this.getCustomTypes()).map(({model:e})=>({...e,label:e.label??null})),sharedSliceModels:(await this.getSlices()).map(e=>e.model),clientIntegration:{includeContentNamespace:!0,includeCreateClientInterface:!0},cache:!0,typesProvider:`@prismicio/client`});return await _(e,t),e}async getEnvironment(){let e=await ml();if(await j(e))return(await te(e))[this.environmentEnvVarName]||void 0}async setEnvironment(e){await B(await ml(),this.environmentEnvVarName,e)}async unsetEnvironment(){await D(await ml(),this.environmentEnvVarName)}};async function ml(){return new URL(`.env.local`,await Qc())}async function hl(e,t){let n=[];for(let r of e){let e=await zr(t,{absolute:!0,cwd:r}),i=await Promise.all(e.map(async e=>{let t=ye(e),n=await w(t);return{library:r,directory:new URL(`.`,t),modelPath:t,model:n}}));n.push(...i)}return n.sort((e,t)=>e.model.id.toLowerCase().localeCompare(t.model.id.toLowerCase()))}export{us as $,ua as $t,Dc as A,Co as At,uc as B,jo as Bt,Nc as C,Ma as Ct,Cc as D,so as Dt,Sc as E,Ho as Et,gc as F,ao as Ft,zs as G,Wa as Gt,pc as H,oo as Ht,mc as I,Da as It,Us as J,Q as Jt,Rs as K,Xa as Kt,xc as L,Oa as Lt,wc as M,eo as Mt,sc as N,ja as Nt,Tc as O,io as Ot,hc as P,Ao as Pt,fs as Q,xa as Qt,fc as R,mo as Rt,$c as S,ko as St,Fc as T,Uo as Tt,ac as U,Fa as Ut,dc as V,Mo as Vt,rc as W,go as Wt,ms as X,ga as Xt,Gs as Y,ha as Yt,ps as Z,ba as Zt,tl as _,ht as _n,Eo as _t,il as a,Ui as an,Fo as at,Uc as b,Ua as bt,ll as c,Wi as cn,to as ct,dl as d,Y as dn,To as dt,da as en,Os as et,Jc as f,Yr as fn,co as ft,Wc as g,gt as gn,Za as gt,zc as h,mt as hn,Oo as ht,al as i,qi as in,ds as it,Ec as j,Pa as jt,Oc as k,Ya as kt,rl as l,X as ln,Io as lt,Lc as m,Ur as mn,ho as mt,sl as n,ca as nn,Ss as nt,ol as o,Z as on,Ka as ot,Pc as p,Vr as pn,Lo as pt,Ks as q,Ca as qt,nl as r,sa as rn,xs as rt,ul as s,zi as sn,fo as st,pl as t,fa as tn,ws as tt,fl as u,oi as un,wo as ut,Mc as v,_t as vn,no as vt,qc as w,Vo as wt,Qc as x,_o as xt,Yc as y,lo as yt,lc as z,Do as zt};
197
+ `)}async function ec(e,t){let n=new AbortController,r=setInterval(async()=>{let r=await Z().catch(()=>void 0);e.cancelled||r&&r.login?.session.pendingLogin?.deviceCode!==t.deviceCode&&n.abort()},js),i=Number.isFinite(e.deadline)?AbortSignal.timeout(Math.max(0,e.deadline-Date.now())):void 0;try{return await ri(t,{signal:i?AbortSignal.any([i,n.signal]):n.signal,onUpdate:n=>tc(t,{...n,host:e.host})})}catch(e){if(e instanceof X)throw await tc(t,void 0),e;if(n.signal.aborted)return{status:`logged-out`};if(i?.aborted)return{status:`wait-limit`};throw e}finally{clearInterval(r)}}async function tc(e,t){await Wi(async n=>{let r=(await Z()).login;r?.session.pendingLogin?.deviceCode===e.deviceCode&&await Hi(n,{...r,session:{...r.session,pendingLogin:t}})}).catch(()=>{})}async function nc(e,t,n){return Wi(async r=>{let i=await Z().catch(()=>void 0);if(i&&i.login?.session.pendingLogin?.deviceCode!==t.deviceCode){await oi(n.refreshToken,t).catch(()=>{});return}let a=i?.login?{store:i.login.store,storeReason:i.login.storeReason}:await Vi(r),o={host:e.host,...e.auth0,...n};await Hi(r,{...a,session:o}),e.saved={...a,token:n.accessToken};let s=i?.login?.session;return s?.refreshToken&&await oi(s.refreshToken,s).catch(()=>{}),e.saved})}async function rc(){let e;try{e=await ue(Ns,`utf-8`)}catch{return}try{let t=JSON.parse(e);if(!t||t.latestKnownVersion===void 0&&t.lastUpdateCheckAt===void 0)return}catch{return}try{await pe(Ns,{force:!0})}catch{}}function ic(e,t,n){let{getKey:r,equals:i=(e,t)=>JSON.stringify(e)===JSON.stringify(t)}=n,a={insert:[],update:[],delete:[]};for(let n of e){let e=t.find(e=>r(e)===r(n));e?i(n,e)||a.update.push(n):a.insert.push(n)}for(let n of t)e.some(e=>r(e)===r(n))||a.delete.push(n);return a}function ac(e){return e.insert.length+e.update.length+e.delete.length>0}const oc=[`Slices`,`UID`,`Choice`];function sc(e,t,n){if(t in e)throw new Sc(t);e[t]=n}function cc(e,t){let n=e[t];if(!n)throw new Cc(t);return n}function lc(e,t,n){let r=new Map(n.map(e=>[e.id,e])),i=r.get(t);if(!i)throw new Tc(`Custom type "${t}" does not exist.`);let a=(e,t,n,i)=>{let o=/* @__PURE__ */ new Map;for(let t of e){let[e,...n]=t.split(`.`),r=o.get(e)??[];r.push(n.join(`.`)),o.set(e,r)}return Array.from(o,([e,o])=>{let s=t[e];if(!s)throw new Tc(`Field "${e}" does not exist on type "${n}".`);let c=o.filter(Boolean);if(c.length===0){if(oc.includes(s.type)||e===`uid`)throw new Tc(`Field "${e}" cannot be fetched from a content relationship.`);if(s.type===`Group`)throw new Tc(`Field "${e}" is a group. Select specific subfields.`);return e}if(c.length!==o.length)throw new Tc(`Field "${e}" cannot be selected both directly and through its subfields.`);if(s.type===`Group`)return{id:e,fields:a(c,s.config?.fields??{},n,i)};if(s.type===`Link`&&s.config?.select===`document`){if(!i)throw new Tc(`Content relationships cannot be nested more than once.`);let t=s.config?.customtypes;if(!t||t.length!==1)throw new Tc(`Field "${e}" must target exactly one custom type to select its fields.`);let n=typeof t[0]==`string`?t[0]:t[0].id,o=r.get(n);if(!o)throw new Tc(`Custom type "${n}" does not exist.`);let l=Object.assign({},...Object.values(o.json));return{id:e,customtypes:[{id:n,fields:a(c,l,n,!1)}]}}throw new Tc(`Field "${e}" is not a group or content relationship field.`)})};return a(e,Object.assign({},...Object.values(i.json)),i.id,!0)}function uc(e,t,n){let r;if(n){if(r=t.json[n],!r)throw new Ec(n,t.id)}else{let[n]=e.split(`.`);if(r=Object.values(t.json).find(e=>n in e),!r)throw new Cc(n)}return bc(e,r)}function dc(e,t,n,r=!1){let i=t.variations.find(e=>e.id===n);if(!i)throw new Dc(n,t.id);if(r){if(!i.items||Object.keys(i.items).length===0)throw new Oc(n,t.id);return bc(e,i.items)}return i.primary??={},bc(e,i.primary)}async function fc(e){let[t,n]=await Promise.all([La(e),Ra(e)]);return{customTypes:t,slices:n}}async function pc({customTypes:e,slices:t},n){let r=(e,t)=>({type:e,id:t.id,payload:t}),i=[...e.insert.map(e=>r(`CUSTOM_TYPE_INSERT`,e)),...e.update.map(e=>r(`CUSTOM_TYPE_UPDATE`,e)),...e.delete.map(({id:e})=>r(`CUSTOM_TYPE_DELETE`,{id:e})),...t.insert.map(e=>r(`SLICE_INSERT`,e)),...t.update.map(e=>r(`SLICE_UPDATE`,e)),...t.delete.map(({id:e})=>r(`SLICE_DELETE`,{id:e}))];i.length>0&&await za(i,n)}function mc(e,t,n={}){let{treatNonCanonicalAsChanged:r=!1}=n;return{customTypes:ic(e.customTypes,t.customTypes,{getKey:e=>e.id,equals:(e,t)=>JSON.stringify(hc(e))===JSON.stringify(r?t:hc(t))}),slices:ic(e.slices,t.slices,{getKey:e=>e.id,equals:(e,t)=>JSON.stringify(gc(e))===JSON.stringify(r?t:gc(t))})}}function hc(e){return{...yc(e),json:Object.fromEntries(Object.entries(e.json).map(([e,t])=>[e,_c(t)]))}}function gc(e){return{...yc(e),variations:e.variations.map(e=>{let t=yc(e);return e.primary&&(t.primary=_c(e.primary)),e.items&&(t.items=_c(e.items)),t})}}function _c(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=yc(t);return t.type===`Group`&&t.config?.fields&&n.type===`Group`&&n.config?.fields&&(n.config.fields=_c(t.config.fields)),t.type===`Slices`&&t.config?.choices&&n.type===`Slices`&&n.config?.choices&&(n.config.choices=vc(t.config.choices)),[e,n]}))}function vc(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=yc(t);return t.type===`Slice`&&n.type===`Slice`&&(t[`non-repeat`]&&(n[`non-repeat`]=_c(t[`non-repeat`])),t.repeat&&(n.repeat=_c(t.repeat))),[e,n]}))}function yc(e){return Array.isArray(e)?e.map(yc):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,yc(t)]))}function bc(e,t){let[n,...r]=e.split(`.`);if(r.length===0)return{fields:t,fieldId:n};let i=cc(t,n);if(i.type!==`Group`)throw new wc(n);return i.config??={},i.config.fields??={},bc(r.join(`.`),i.config.fields)}function xc(e){return e.flatMap(e=>Object.values(e.json).flatMap(t=>Object.entries(t).flatMap(([t,n])=>n.type===`Slices`?Object.entries(n.config?.choices??{}).flatMap(([r,i])=>i.type===`SharedSlice`?[]:[{id:r,customTypeId:e.id,sliceZoneId:t,sliceZone:n,model:i}]):[])))}var Sc=class extends Error{name=`FieldExistsError`;constructor(e){super(`Field "${e}" already exists.`)}},Cc=class extends Error{name=`FieldNotFoundError`;constructor(e){super(`Field "${e}" does not exist.`)}},wc=class extends Error{name=`UnsupportedNestedFieldError`;constructor(e){super(`Field "${e}" does not support nested fields.`)}},Tc=class extends Error{name=`FieldSelectionError`},Ec=class extends Error{name=`TabNotFoundError`;constructor(e,t){super(`Tab "${e}" does not exist on type "${t}".`)}},Dc=class extends Error{name=`SliceVariationNotFoundError`;constructor(e,t){super(`Variation "${e}" does not exist on slice "${t}".`)}},Oc=class extends Error{name=`SliceItemsNotFoundError`;constructor(e,t){super(`Variation "${e}" of slice "${t}" has no legacy items zone. To add repeatable fields, add a repeatable group to the slice.`)}};const kc=`prismic.config.json`,Ac=l({type:C(),path:C(),uid:S(C()),lang:S(C()),resolvers:S(x(C(),C()))}),jc=l({repositoryName:C(),documentAPIEndpoint:S(R()),libraries:S(V(C())),routes:S(V(Ac))});async function Mc(e){let t=await Rc();return await ge(t,P(e)),t}async function Nc(){let e=await Ic();try{return await w(e,{schema:jc})}catch{throw new Pc}}var Pc=class extends Error{name=`InvalidPrismicConfigError`;message=`${kc} is invalid. Run \`prismic init\` to re-create a config.`};async function Fc(e){let t=await Ic(),n={...await Nc(),...e};return await ge(t,P(n)),n}async function Ic(){let e=await ne(kc,{stop:`package.json`});if(!e)throw new Lc;return e}var Lc=class extends Error{name=`MissingPrismicConfigError`;message=`Could not find a ${kc} file. Run \`prismic init\` to create a config.`};async function Rc(){try{let e=await ie();return new URL(kc,e)}catch(e){throw e instanceof L?new zc({cause:e}):e}}var zc=class extends Error{name=`UnknownProjectRootError`;constructor(e){super(`Could not find your project root.`,e)}};async function Bc(e){let{routes:t=[]}=await Nc();if(t.some(t=>t.type===e.id))return;let n=Wc(e),r={type:e.id,path:n};await Fc({routes:[...t,r].sort((e,t)=>e.type.localeCompare(t.type))})}async function Vc(e){e.format===`page`?await Bc(e):await Hc(e.id)}async function Hc(e){let{routes:t=[]}=await Nc(),n=t.filter(t=>t.type!==e);t.length!==n.length&&await Fc({routes:n})}function Uc(e,t){return e.find(e=>e.type===t&&!e.uid&&!/[?*+]/.test(e.path))}function Wc(e){let{id:t,repeatable:n}=e,r=t.replaceAll(`_`,`-`).toLowerCase();return n?t===`page`?`/:uid`:`/${r}/:uid`:t===`homepage`?`/`:`/${r}`}const Gc=`slicemachine.config.json`,Kc=l({repositoryName:C(),libraries:S(V(C()))});async function qc(){let e=await Xc();try{return await w(e,{schema:Kc})}catch{throw new Jc}}var Jc=class extends Error{name=`InvalidLegacySliceMachineConfigError`;message=`${Gc} is invalid.`};async function Yc(){let e=await Xc();await pe(e)}async function Xc(){let e=await ne(Gc,{stop:`package.json`});if(!e)throw new Zc;return e}var Zc=class extends Error{name=`MissingLegacySliceMachineConfigError`;message=`Could not find a ${Gc} file.`};async function Qc(){let e;try{e=await Ic()}catch(t){if(t instanceof Lc)e=await Rc();else throw t}let t=new URL(`.`,e);return A(ye(await de(ve(t))))}async function $c(){try{return(await Nc()).repositoryName}catch(e){if(e instanceof Lc)try{return(await qc()).repositoryName}catch{}throw e}}async function el(){let e=(await Nc()).libraries;if(!e||e.length<1)return;let t=await Qc();return e.map(e=>A(new URL(e.replace(/^\//,``),t)))}async function tl(){let e=await Qc();return j(new URL(`tsconfig.json`,e))}const nl=[`next`,`nuxt`,`sveltekit`];async function rl(){let{dependencies:e,devDependencies:t,peerDependencies:n}=await re(),r={...e,...t,...n};if(`next`in r){let{NextJsAdapter:e}=await import(`./nextjs-BHpKe_-i.mjs`);return new e}if(`nuxt`in r){let{NuxtAdapter:e}=await import(`./nuxt-CwKupGuZ.mjs`);return new e}if(`@sveltejs/kit`in r){if(await T(`@sveltejs/kit`)<3){let{SvelteKit2Adapter:e}=await import(`./sveltekit2-Cpv1t7Wz.mjs`);return new e}let{SvelteKitAdapter:e}=await import(`./sveltekit-C3PWuKwC.mjs`);return new e}throw new il}var il=class extends Error{name=`NoSupportedFrameworkError`;message=`No supported framework found. Run this command in a Next.js, Nuxt, or SvelteKit project.`},al=class extends Error{name=`ModelExistsError`},ol=class extends Error{name=`SliceNotFoundError`;constructor(e){super(`Slice "${e}" does not exist. Run \`prismic slice list\` to see available IDs.`)}},sl=class extends Error{name=`CustomTypeNotFoundError`;constructor(e){super(`Type "${e}" does not exist. Run \`prismic type list\` to see available IDs.`)}};async function cl(e,t,n,r){let i=r.find(e=>e.model.id===t||e.directory.href===n.href);if(!i&&!await j(n))return;let a=m(await Qc(),i?.directory??n),o=i?` (id: ${i.model.id})`:``;throw new al(`A ${e} already exists at ${a}${_e}${o}.`)}async function ll(){return await(await rl()).getEnvironment()??await $c()}async function ul(e){let t=await zr(`**/*.{js,jsx,mjs,ts,tsx,mts,svelte}`,{cwd:ve(await Qc()),absolute:!0,ignore:`**/{node_modules,build,dist,out}/**`});for(let n of t)try{if((await ue(n,`utf8`)).includes(e))return!0}catch{}return!1}async function dl(e,t){await j(e)||await _(e,t)}async function fl(){return await tl()?`ts`:`js`}var pl=class{get localPreviewUrl(){return new URL(this.localPreviewConfig.resolverPath,this.localPreviewConfig.websiteURL).href}get localSimulatorUrl(){return new URL(`slice-simulator`,this.localPreviewConfig.websiteURL).href}async initProject({setup:e}){for(let e of await this.getSliceLibraries())await this.createSliceIndexFile(e);e&&await this.setupProject();let t={repo:await $c(),getToken:Rs,host:await zs()};(await ao(t)).simulator_url||await oo(this.localSimulatorUrl,t),(await eo(t)).results.length===0&&await to(this.localPreviewConfig,t)}async getSliceLibraries(){return await el()??[await this.getDefaultSliceLibrary()]}async getSlices(){return hl(await this.getSliceLibraries(),`*/model.json`)}async getSlice(e){let t=(await this.getSlices()).find(t=>t.model.id===e);if(t)return t;let n=xc((await this.getCustomTypes()).map(e=>e.model)).find(t=>t.id===e);if(n){let{customTypeId:t,sliceZoneId:r}=n;throw new Q(`"${e}" is a legacy slice in "${t}". Upgrade it first: \`prismic slice upgrade-legacy ${e} --from ${t}${r===`body`?``:` --slice-zone ${r}`}\`.`)}throw new ol(e)}async createSlice(e){let[t]=await this.getSliceLibraries(),n=A(new URL(ht(e.name),A(t)));await cl(`slice`,e.id,n,await this.getSlices()),await _(new URL(`model.json`,n),P(gc(e))),await this.createSliceIndexFile(t),await this.createSliceComponent(e,n)}async updateSlice(e){let t=await this.getSlice(e.id);await _(t.modelPath,P(gc(e))),await this.createSliceIndexFile(t.library)}async deleteSlice(e){let t=await this.getSlice(e);await pe(t.directory,{recursive:!0}),await this.createSliceIndexFile(t.library)}async getCustomTypeLibraries(){return[new URL(`customtypes/`,await Qc())]}async getCustomTypes(){return hl(await this.getCustomTypeLibraries(),`*/index.json`)}async getCustomType(e){let t=(await this.getCustomTypes()).find(t=>t.model.id===e);if(!t)throw new sl(e);return t}async createCustomType(e){let[t]=await this.getCustomTypeLibraries(),n=A(new URL(e.id,A(t)));if(await cl(`type`,e.id,n,await this.getCustomTypes()),await _(new URL(`index.json`,n),P(hc(e))),e.format!==`page`)return[];await Bc(e);let r=await Qc();return(await this.writePageFiles(e)).map(({path:t})=>`Skipped ${m(r,t)} (already exists). Run \`prismic gen page ${e.id}\` to get the code.`)}async writePageFiles(e){let{routes:t=[]}=await Nc(),n=(Uc(t,e.id)?.path??Wc(e)).split(`/`).filter(Boolean).map(e=>e.startsWith(`:`)?`[${e.slice(1)}]`:e).join(`/`),r=[];for(let t of await this.getPageFiles(e,n))await j(t.path)?r.push(t):await _(t.path,t.contents);return r}async updateCustomType(e){let t=await this.getCustomType(e.id);await _(t.modelPath,P(hc(e))),await Vc(e)}async deleteCustomType(e){let t=await this.getCustomType(e);await pe(t.directory,{recursive:!0}),await Hc(e)}async getModels(){let[e,t]=await Promise.all([this.getCustomTypes(),this.getSlices()]);return{customTypes:e.map(e=>e.model),slices:t.map(e=>e.model)}}async writeModels(e){for(let t of e.slices.update)await this.updateSlice(t);for(let t of e.slices.delete)await this.deleteSlice(t.id);for(let t of e.slices.insert)await this.createSlice(t);for(let t of e.customTypes.update)await this.updateCustomType(t);for(let t of e.customTypes.delete)await this.deleteCustomType(t.id);let t=[];for(let n of e.customTypes.insert)t.push(...await this.createCustomType(n));return t}async generateTypes(){let e=new URL(`prismicio-types.d.ts`,await Qc()),t=Qt({customTypeModels:(await this.getCustomTypes()).map(({model:e})=>({...e,label:e.label??null})),sharedSliceModels:(await this.getSlices()).map(e=>e.model),clientIntegration:{includeContentNamespace:!0,includeCreateClientInterface:!0},cache:!0,typesProvider:`@prismicio/client`});return await _(e,t),e}async getEnvironment(){let e=await ml();if(await j(e))return(await te(e))[this.environmentEnvVarName]||void 0}async setEnvironment(e){await B(await ml(),this.environmentEnvVarName,e)}async unsetEnvironment(){await D(await ml(),this.environmentEnvVarName)}};async function ml(){return new URL(`.env.local`,await Qc())}async function hl(e,t){let n=[];for(let r of e){let e=await zr(t,{absolute:!0,cwd:r}),i=await Promise.all(e.map(async e=>{let t=ye(e),n=await w(t);return{library:r,directory:new URL(`.`,t),modelPath:t,model:n}}));n.push(...i)}return n.sort((e,t)=>e.model.id.toLowerCase().localeCompare(t.model.id.toLowerCase()))}export{us as $,ua as $t,Dc as A,Co as At,uc as B,jo as Bt,Nc as C,Ma as Ct,Cc as D,so as Dt,Sc as E,Ho as Et,gc as F,ao as Ft,zs as G,Wa as Gt,pc as H,oo as Ht,mc as I,Da as It,Us as J,Q as Jt,Rs as K,Xa as Kt,xc as L,Oa as Lt,wc as M,eo as Mt,sc as N,ja as Nt,Tc as O,io as Ot,hc as P,Ao as Pt,fs as Q,xa as Qt,fc as R,mo as Rt,$c as S,ko as St,Fc as T,Uo as Tt,ac as U,Fa as Ut,dc as V,Mo as Vt,rc as W,go as Wt,ms as X,ga as Xt,Gs as Y,ha as Yt,ps as Z,ba as Zt,tl as _,ht as _n,Eo as _t,il as a,Ui as an,Fo as at,Uc as b,Ua as bt,ll as c,Wi as cn,to as ct,dl as d,Y as dn,To as dt,da as en,Os as et,Jc as f,Yr as fn,co as ft,Wc as g,gt as gn,Za as gt,zc as h,mt as hn,Oo as ht,al as i,qi as in,ds as it,Ec as j,Pa as jt,Oc as k,Ya as kt,rl as l,X as ln,Io as lt,Lc as m,Ur as mn,ho as mt,sl as n,ca as nn,Ss as nt,ol as o,Z as on,Ka as ot,Pc as p,Vr as pn,Lo as pt,Ks as q,Ca as qt,nl as r,sa as rn,xs as rt,ul as s,zi as sn,fo as st,pl as t,fa as tn,ws as tt,fl as u,oi as un,wo as ut,Mc as v,_t as vn,no as vt,qc as w,Vo as wt,Qc as x,_o as xt,Yc as y,lo as yt,lc as z,Do as zt};