prismic 1.23.0-pr.409.dafc762 → 1.23.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/dist/{adapters-BoIyqzRy.mjs → adapters-Bt9QKcJb.mjs} +2 -2
- package/dist/{auth-z_-l2G1U.mjs → auth-NkX7Docj.mjs} +1 -1
- package/dist/index.mjs +51 -51
- package/dist/{nextjs-DlOgfeBJ.mjs → nextjs-TJI3bKFA.mjs} +1 -1
- package/dist/{nuxt-BumZJU18.mjs → nuxt-DfWyc1bJ.mjs} +1 -1
- package/dist/package-Dyw1b366.mjs +1 -0
- package/dist/{segment-CCXO4sAE.mjs → segment-yGieXuDf.mjs} +1 -1
- package/dist/subprocesses/refreshToken.mjs +1 -1
- package/dist/subprocesses/sendSegmentEvents.mjs +1 -1
- package/dist/subprocesses/updateVersionState.mjs +1 -1
- package/dist/{sveltekit-DqTm7M3A.mjs → sveltekit-CC1sBn9O.mjs} +1 -1
- package/dist/{update-notifier-D0ZPYeGo.mjs → update-notifier-ChP_LYxw.mjs} +1 -1
- package/package.json +1 -1
- package/dist/package-wrGWFDHc.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{C as e,F as t,I as n,M as r,N as i,P as a,_ as o,b as s,c,d as l,f as u,h as d,k as f,l as p,m,s as h,u as g,v as _,w as v,z as y}from"./request-DJTl_0US.mjs";import{m as b,r as x}from"./auth-
|
|
1
|
+
import{C as e,F as t,I as n,M as r,N as i,P as a,_ as o,b as s,c,d as l,f as u,h as d,k as f,l as p,m,s as h,u as g,v as _,w as v,z as y}from"./request-DJTl_0US.mjs";import{m as b,r as x}from"./auth-NkX7Docj.mjs";import{c as S,r as C,t as w}from"./packageJson-Bxht6H4y.mjs";import{createRequire as ee}from"node:module";import{parseArgs as T}from"node:util";import{readFile as E,realpath as D,rm as O,writeFile as te}from"node:fs/promises";import{sep as ne}from"node:path";import{fileURLToPath as k,pathToFileURL as A}from"node:url";import*as re from"node:crypto";import{createHash as ie}from"node:crypto";import*as j from"fs";import{readdir as M,readdirSync as N,realpath as P,realpathSync as ae,stat as F,statSync as I}from"fs";import{basename as L,dirname as R,isAbsolute as z,normalize as B,posix as V,relative as oe,resolve as se,sep as H}from"path";import{fileURLToPath as ce}from"url";import{createRequire as U}from"module";var le=Object.create,ue=Object.defineProperty,de=Object.getOwnPropertyDescriptor,fe=Object.getOwnPropertyNames,pe=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty,he=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},W=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),ge=(e,t)=>{let n={};for(var r in e)ue(n,r,{get:e[r],enumerable:!0});return t||ue(n,Symbol.toStringTag,{value:`Module`}),n},_e=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=fe(t),a=0,o=i.length,s;a<o;a++)s=i[a],!me.call(e,s)&&s!==n&&ue(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=de(t,s))||r.enumerable});return e},ve=(e,t,n)=>(n=e==null?{}:le(pe(e)),_e(t||!e||!e.__esModule||!me.call(e,`default`)?ue(n,`default`,{value:e,enumerable:!0}):n,e)),ye=e=>me.call(e,`module.exports`)?e[`module.exports`]:_e(ue({},`__esModule`,{value:!0}),e);const be=/([\p{Ll}\d])(\p{Lu})/gu,xe=/(\p{Lu})([\p{Lu}][\p{Ll}])/gu,Se=/(\d)\p{Ll}|(\p{L})\d/u,Ce=/[^\p{L}\d]+/giu,we=`$1\0$2`;function Te(e){let t=e.trim();t=t.replace(be,we).replace(xe,we),t=t.replace(Ce,`\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 Ee(e){let t=Te(e);for(let e=0;e<t.length;e++){let n=t[e],r=Se.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 De(e,t){let[n,r,i]=Ie(e,t);return n+r.map(Me(t?.locale)).join(t?.delimiter??` `)+i}function Oe(e,t){let[n,r,i]=Ie(e,t),a=Me(t?.locale),o=Ne(t?.locale),s=t?.mergeAmbiguousCharacters?Pe(a,o):Fe(a,o);return n+r.map((e,t)=>t===0?a(e):s(e,t)).join(t?.delimiter??``)+i}function ke(e,t){let[n,r,i]=Ie(e,t),a=Me(t?.locale),o=Ne(t?.locale),s=t?.mergeAmbiguousCharacters?Pe(a,o):Fe(a,o);return n+r.map(s).join(t?.delimiter??``)+i}function Ae(e,t){let[n,r,i]=Ie(e,t),a=Me(t?.locale),o=Ne(t?.locale);return n+r.map(Pe(a,o)).join(t?.delimiter??` `)+i}function je(e,t){return De(e,{delimiter:`_`,...t})}function Me(e){return e===!1?e=>e.toLowerCase():t=>t.toLocaleLowerCase(e)}function Ne(e){return e===!1?e=>e.toUpperCase():t=>t.toLocaleUpperCase(e)}function Pe(e,t){return n=>`${t(n[0])}${e(n.slice(1))}`}function Fe(e,t){return(n,r)=>{let i=n[0];return(r>0&&i>=`0`&&i<=`9`?`_`+i:t(i))+e(n.slice(1))}}function Ie(e,t={}){let n=t.split??(t.separateNumbers?Ee:Te),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 Le(e,t){return(!e||e.endsWith(`
|
|
2
2
|
`))&&!t?.force?e:e+`
|
|
3
3
|
`}function G(e,t){return Le(t)+e}function Re(e,t){return(!e||e.endsWith(`
|
|
4
4
|
|
|
@@ -188,4 +188,4 @@ const ni=/^[A-Z]:\/$/i,ri=$r?e=>ni.test(e):e=>e===`/`;function ii(e,t,n){if(e===
|
|
|
188
188
|
what the user asked for as --user-intent. Analytics only — no effect on behavior.
|
|
189
189
|
`}:e.sections;console.info(Hi(e.description,n,e.name,r))}}function Vi(e){let t=Li?{...e,...Ri}:e,n=[];for(let[e,r]of Object.entries(t)){if(r.deprecated||r.hidden)continue;let t=r.short?`-${r.short}, `:` `,i=r.type===`string`?` string`:``,a=r.description+(r.required?` (required)`:``);n.push([` ${t}--${e}${i}`,a])}return n.push([` -h, --help`,`Show help for command`]),n}function Hi(e,t,n,r={}){let i=[Pi(e)];for(let[e,n]of Object.entries(t))i.push(``,e,n);for(let[e,t]of Object.entries(r))i.push(``,e,...Pi(t).split(`
|
|
190
190
|
`).map(e=>e?` ${e}`:``));return i.push(``,`LEARN MORE`,` Use \`${n} <command> --help\` for more information about a command.`),i.join(`
|
|
191
|
-
`)}function Ui(e,t){let n=t.filter(t=>t in e),r=t.map(e=>`--${String(e)}`).join(` or `);if(n.length>1)throw new Q(`Only one of ${r} can be specified.`);if(n.length===0)throw new Q(`Specify one of ${r}.`);return{key:n[0],value:e[n[0]]}}function Wi(e,t){let n=t.filter(t=>t in e),r=t.map(e=>`--${String(e)}`).join(` or `);if(n.length>1)throw new Q(`Only one of ${r} can be specified.`)}var Q=class extends Error{name=`CommandError`};const Gi=i({id:n(),label:n(),url:n()}),Ki=i({results:v(Gi)});async function qi(e){let{repo:t,host:n}=e;return(await aa(new URL(`core/repository/preview_configs`,oa(t,n)),e,{schema:Ki,unknownErrorMessage:`Failed to load previews`})).results}async function Ji(e,t){let{repo:n,host:r}=t;await aa(new URL(`previews/new`,oa(n,r)),t,{method:`POST`,json:{name:e.name,websiteURL:e.websiteURL,resolverPath:e.resolverPath},unknownErrorMessage:`Failed to add preview`})}async function Yi(e,t){let{repo:n,host:r}=t;await aa(new URL(`previews/delete/${encodeURIComponent(e)}`,oa(n,r)),t,{method:`POST`,json:{},notFoundMessage:`Preview not found: ${e}`,unknownErrorMessage:`Failed to remove preview`})}const Xi=i({kind:e([`prod`,`stage`,`dev`]),name:n(),domain:n(),users:v(i({id:n()}))});async function Zi(e){let{repo:t,host:n}=e;return(await aa(new URL(`core/environments`,oa(t,n)),e,{schema:i({results:v(Xi)})})).results}const Qi=i({simulator_url:a(n())});async function $i(e){let{repo:t,host:n}=e;return(await aa(new URL(`core/repository`,oa(t,n)),e,{schema:Qi,unknownErrorMessage:`Failed to load simulator URL`})).simulator_url}async function ea(e,t){let{repo:n,host:r}=t;await aa(new URL(`core/repository`,oa(n,r)),t,{method:`PATCH`,json:{simulator_url:e},unknownErrorMessage:`Failed to set simulator URL`})}const ta=i({total:r()});async function na(e,t){let{repo:n,host:r}=t;return(await aa(new URL(`core/documents/search`,oa(n,r)),t,{method:`POST`,json:{customTypes:[e],limit:0},schema:ta})).total}async function ra(e,t){let{repo:r,host:i}=t;return(await aa(new URL(`core/releases`,oa(r,i)),t,{method:`POST`,json:e,schema:f({id:n()}),unknownErrorMessage:`Failed to create a release`})).id}async function ia(e,t){let{repo:n,host:r}=t;await aa(new URL(`core/releases/${encodeURIComponent(e)}`,oa(n,r)),t,{method:`DELETE`,notFoundMessage:`Release not found: ${e}`,unknownErrorMessage:`Failed to delete the release`})}function aa(e,t,n={}){return h(e,{credentials:{"prismic-auth":t.token},notFoundMessage:`Repository not found: ${t.repo}`,...n})}function oa(e,t){return new URL(`https://${e}.${t}/`)}function sa(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 ca(e){return e.insert.length+e.update.length+e.delete.length>0}function la(e){return _a(new URL(`customtypes`,ya(e.host)),e)}function ua(e){return _a(new URL(`slices`,ya(e.host)),e)}async function da(e,t){await _a(new URL(`bulk-update`,ya(t.host)),t,{method:`POST`,json:{changes:e},unknownErrorMessage:`Failed to update models`})}const fa=i({values:i({url:n(),fields:t(n(),n())}),imgixEndpoint:n()}),pa={"image/png":`.png`,"image/jpeg":`.jpg`,"image/gif":`.gif`,"image/webp":`.webp`};async function ma(e,t){await va(new URL(`delete`,ba(t.host)),t,{method:`POST`,json:{sliceId:e}})}async function ha(e,t){let{sliceId:n,variationId:r,repo:i,host:a}=t,o=e.type;if(!(o in pa))throw new ga(o);let s=await va(new URL(`presigned-url`,ba(a)),t,{schema:fa}),c=pa[o],l=`${i}/shared-slices/${n}/${r}/${ie(`sha1`).update(new Uint8Array(await e.arrayBuffer())).digest(`hex`)}${c}`,u=new FormData;for(let[e,t]of Object.entries(s.values.fields))u.append(e,t);u.set(`key`,l),u.set(`Content-Type`,o),u.set(`file`,e),await h(s.values.url,{method:`POST`,body:u});let d=new URL(l,_(s.imgixEndpoint));return d.searchParams.set(`auto`,`compress,format`),d}var ga=class extends Error{name=`UnsupportedFileTypeError`;constructor(e){let t=Object.keys(pa);super(`Unsupported file type: ${e||`unknown`}. Supported: ${t.join(`, `)}`)}};function _a(e,t,n={}){return t.releaseId&&e.searchParams.set(`release`,t.releaseId),h(e,{headers:{repository:t.repo,Authorization:`Bearer ${t.token}`},notFoundMessage:`Repository not found: ${t.repo}`,...n})}function va(e,t,n={}){let r=new URL(e);return r.searchParams.set(`repository`,t.repo),h(r,{headers:{repository:t.repo,Authorization:`Bearer ${t.token}`},...n})}function ya(e){return new URL(`https://customtypes.${e}/`)}function ba(e){return new URL(`https://api.internal.${e}/screenshot/`)}const xa=[`Slices`,`UID`,`Choice`];function Sa(e,t,n){if(t in e)throw new La(t);e[t]=n}function Ca(e,t){let n=e[t];if(!n)throw new Ra(t);return n}function wa(e,t,n){let r=new Map(n.map(e=>[e.id,e])),i=r.get(t);if(!i)throw new $(`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 $(`Field "${e}" does not exist on type "${n}".`);let c=o.filter(Boolean);if(c.length===0){if(xa.includes(s.type)||e===`uid`)throw new $(`Field "${e}" cannot be fetched from a content relationship.`);if(s.type===`Group`)throw new $(`Field "${e}" is a group. Select specific subfields.`);return e}if(c.length!==o.length)throw new $(`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 $(`Content relationships cannot be nested more than once.`);let t=s.config?.customtypes;if(!t||t.length!==1)throw new $(`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 $(`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 $(`Field "${e}" is not a group or content relationship field.`)})};return a(e,Object.assign({},...Object.values(i.json)),i.id,!0)}function Ta(e,t,n){let r;if(n){if(r=t.json[n],!r)throw new Ba(n,t.id)}else{let[n]=e.split(`.`);if(r=Object.values(t.json).find(e=>n in e),!r)throw new Ra(n)}return Fa(e,r)}function Ea(e,t,n){let r=t.variations.find(e=>e.id===n);if(!r)throw new Va(n,t.id);return r.primary??={},Fa(e,r.primary)}async function Da(e){let[t,n]=await Promise.all([la(e),ua(e)]);return{customTypes:t,slices:n}}async function Oa({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 da(i,n)}function ka(e,t,n={}){let{treatNonCanonicalAsChanged:r=!1}=n;return{customTypes:sa(e.customTypes,t.customTypes,{getKey:e=>e.id,equals:(e,t)=>JSON.stringify(Aa(e))===JSON.stringify(r?t:Aa(t))}),slices:sa(e.slices,t.slices,{getKey:e=>e.id,equals:(e,t)=>JSON.stringify(ja(e))===JSON.stringify(r?t:ja(t))})}}function Aa(e){return{...Pa(e),json:Object.fromEntries(Object.entries(e.json).map(([e,t])=>[e,Ma(t)]))}}function ja(e){return{...Pa(e),variations:e.variations.map(e=>{let t=Pa(e);return e.primary&&(t.primary=Ma(e.primary)),e.items&&(t.items=Ma(e.items)),t})}}function Ma(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=Pa(t);return t.type===`Group`&&t.config?.fields&&n.type===`Group`&&n.config?.fields&&(n.config.fields=Ma(t.config.fields)),t.type===`Slices`&&t.config?.choices&&n.type===`Slices`&&n.config?.choices&&(n.config.choices=Na(t.config.choices)),[e,n]}))}function Na(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=Pa(t);return t.type===`Slice`&&n.type===`Slice`&&(t[`non-repeat`]&&(n[`non-repeat`]=Ma(t[`non-repeat`])),t.repeat&&(n.repeat=Ma(t.repeat))),[e,n]}))}function Pa(e){return Array.isArray(e)?e.map(Pa):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,Pa(t)]))}function Fa(e,t){let[n,...r]=e.split(`.`);if(r.length===0)return{fields:t,fieldId:n};let i=Ca(t,n);if(i.type!==`Group`)throw new za(n);return i.config??={},i.config.fields??={},Fa(r.join(`.`),i.config.fields)}function Ia(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 La=class extends Error{name=`FieldExistsError`;constructor(e){super(`Field "${e}" already exists.`)}},Ra=class extends Error{name=`FieldNotFoundError`;constructor(e){super(`Field "${e}" does not exist.`)}},za=class extends Error{name=`UnsupportedNestedFieldError`;constructor(e){super(`Field "${e}" does not support nested fields.`)}},$=class extends Error{name=`FieldSelectionError`},Ba=class extends Error{name=`TabNotFoundError`;constructor(e,t){super(`Tab "${e}" does not exist on type "${t}".`)}},Va=class extends Error{name=`SliceVariationNotFoundError`;constructor(e,t){super(`Variation "${e}" does not exist on slice "${t}".`)}};const Ha=`prismic.config.json`,Ua=i({type:n(),path:n(),uid:a(n()),lang:a(n()),resolvers:a(t(n(),n()))}),Wa=i({repositoryName:n(),documentAPIEndpoint:a(y()),libraries:a(v(n())),routes:a(v(Ua))});async function Ga(e){let t=await Za();return await te(t,c(e)),t}async function Ka(){let e=await Ya();try{return await u(e,{schema:Wa})}catch{throw new qa}}var qa=class extends Error{name=`InvalidPrismicConfigError`;message=`${Ha} is invalid. Run \`prismic init\` to re-create a config.`};async function Ja(e){let t=await Ya(),n={...await Ka(),...e};return await te(t,c(n)),n}async function Ya(){let e=await g(Ha,{stop:`package.json`});if(!e)throw new Xa;return e}var Xa=class extends Error{name=`MissingPrismicConfigError`;message=`Could not find a ${Ha} file. Run \`prismic init\` to create a config.`};async function Za(){try{let e=await C();return new URL(Ha,e)}catch(e){throw e instanceof w?new Qa({cause:e}):e}}var Qa=class extends Error{name=`UnknownProjectRootError`;constructor(e){super(`Could not find your project root.`,e)}};async function $a(e){let{routes:t=[]}=await Ka();if(t.some(t=>t.type===e.id))return;let n=ro(e),r={type:e.id,path:n};await Ja({routes:[...t,r].sort((e,t)=>e.type.localeCompare(t.type))})}async function eo(e){e.format===`page`?await $a(e):await to(e.id)}async function to(e){let{routes:t=[]}=await Ka(),n=t.filter(t=>t.type!==e);t.length!==n.length&&await Ja({routes:n})}function no(e,t){return e.find(e=>e.type===t&&!e.uid&&!/[?*+]/.test(e.path))}function ro(e){let{id:t,repeatable:n}=e,r=t.replaceAll(`_`,`-`).toLowerCase();return n?t===`page`?`/:uid`:`/${r}/:uid`:t===`homepage`?`/`:`/${r}`}const io=`slicemachine.config.json`,ao=i({repositoryName:n(),libraries:a(v(n()))});async function oo(){let e=await lo();try{return await u(e,{schema:ao})}catch{throw new so}}var so=class extends Error{name=`InvalidLegacySliceMachineConfigError`;message=`${io} is invalid.`};async function co(){let e=await lo();await O(e)}async function lo(){let e=await g(io,{stop:`package.json`});if(!e)throw new uo;return e}var uo=class extends Error{name=`MissingLegacySliceMachineConfigError`;message=`Could not find a ${io} file.`};async function fo(){let e;try{e=await Ya()}catch(t){if(t instanceof Xa)e=await Za();else throw t}let t=new URL(`.`,e);return _(A(await D(k(t))))}async function po(){try{return(await Ka()).repositoryName}catch(e){if(e instanceof Xa)try{return(await oo()).repositoryName}catch{}throw e}}async function mo(){let e=(await Ka()).libraries;if(!e||e.length<1)return;let t=await fo();return e.map(e=>_(new URL(e.replace(/^\//,``),t)))}async function ho(){let e=await fo();return p(new URL(`tsconfig.json`,e))}const go=[`next`,`nuxt`,`sveltekit`];async function _o(){let{dependencies:e,devDependencies:t,peerDependencies:n}=await S(),r={...e,...t,...n};if(`next`in r){let{NextJsAdapter:e}=await import(`./nextjs-DlOgfeBJ.mjs`);return new e}if(`nuxt`in r){let{NuxtAdapter:e}=await import(`./nuxt-BumZJU18.mjs`);return new e}if(`@sveltejs/kit`in r){let{SvelteKitAdapter:e}=await import(`./sveltekit-DqTm7M3A.mjs`);return new e}throw new vo}var vo=class extends Error{name=`NoSupportedFrameworkError`;message=`No supported framework found. Run this command in a Next.js, Nuxt, or SvelteKit project.`},yo=class extends Error{name=`ModelExistsError`},bo=class extends Error{name=`SliceNotFoundError`;constructor(e){super(`Slice "${e}" does not exist. Run \`prismic slice list\` to see available IDs.`)}},xo=class extends Error{name=`CustomTypeNotFoundError`;constructor(e){super(`Type "${e}" does not exist. Run \`prismic type list\` to see available IDs.`)}};async function So(e,t,n,r){let i=r.find(e=>e.model.id===t||e.directory.href===n.href);if(!i&&!await p(n))return;let a=s(await fo(),i?.directory??n),o=i?` (id: ${i.model.id})`:``;throw new yo(`A ${e} already exists at ${a}${ne}${o}.`)}async function Co(){return await(await _o()).getEnvironment()??await po()}async function wo(e){let t=await wi(`**/*.{js,jsx,mjs,ts,tsx,mts,svelte}`,{cwd:k(await fo()),absolute:!0,ignore:`**/{node_modules,build,dist,out}/**`});for(let n of t)try{if((await E(n,`utf8`)).includes(e))return!0}catch{}return!1}async function To(e,t){await p(e)||await o(e,t)}async function Eo(){return await ho()?`ts`:`js`}async function Do(e){let t=ee(await C());try{let{version:n}=t(`${e}/package.json`),r=Number.parseInt(n.split(`.`)[0]);return Number.isNaN(r)?1/0:r}catch{return 1/0}}var Oo=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 po(),...await x()};await $i(t)||await ea(this.localSimulatorUrl,t),(await qi(t)).length===0&&await Ji(this.localPreviewConfig,t)}async getSliceLibraries(){return await mo()??[await this.getDefaultSliceLibrary()]}async getSlices(){return Ao(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=Ia((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 bo(e)}async createSlice(e){let[t]=await this.getSliceLibraries(),n=_(new URL(ke(e.name),_(t)));await So(`slice`,e.id,n,await this.getSlices()),await o(new URL(`model.json`,n),c(ja(e))),await this.createSliceIndexFile(t),await this.createSliceComponent(e,n)}async updateSlice(e){let t=await this.getSlice(e.id);await o(t.modelPath,c(ja(e))),await this.createSliceIndexFile(t.library)}async deleteSlice(e){let t=await this.getSlice(e);await O(t.directory,{recursive:!0}),await this.createSliceIndexFile(t.library)}async getCustomTypeLibraries(){return[new URL(`customtypes/`,await fo())]}async getCustomTypes(){return Ao(await this.getCustomTypeLibraries(),`*/index.json`)}async getCustomType(e){let t=(await this.getCustomTypes()).find(t=>t.model.id===e);if(!t)throw new xo(e);return t}async createCustomType(e){let[t]=await this.getCustomTypeLibraries(),n=_(new URL(e.id,_(t)));if(await So(`type`,e.id,n,await this.getCustomTypes()),await o(new URL(`index.json`,n),c(Aa(e))),e.format!==`page`)return[];await $a(e);let r=await fo();return(await this.writePageFiles(e)).map(({path:t})=>`Skipped ${s(r,t)} (already exists). Run \`prismic gen page ${e.id}\` to get the code.`)}async writePageFiles(e){let{routes:t=[]}=await Ka(),n=(no(t,e.id)?.path??ro(e)).split(`/`).filter(Boolean).map(e=>e.startsWith(`:`)?`[${e.slice(1)}]`:e).join(`/`),r=[];for(let t of await this.getPageFiles(e,n))await p(t.path)?r.push(t):await o(t.path,t.contents);return r}async updateCustomType(e){let t=await this.getCustomType(e.id);await o(t.modelPath,c(Aa(e))),await eo(e)}async deleteCustomType(e){let t=await this.getCustomType(e);await O(t.directory,{recursive:!0}),await to(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 fo()),t=Rn({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 o(e,t),e}async getEnvironment(){let e=await ko();if(await p(e))return(await l(e))[this.environmentEnvVarName]||void 0}async setEnvironment(e){await m(await ko(),this.environmentEnvVarName,e)}async unsetEnvironment(){await d(await ko(),this.environmentEnvVarName)}};async function ko(){return new URL(`.env.local`,await fo())}async function Ao(e,t){let n=[];for(let r of e){let e=await wi(t,{absolute:!0,cwd:r}),i=await Promise.all(e.map(async e=>{let t=A(e),n=await u(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{$i as $,Va as A,Ta as B,po as C,La as D,Ja as E,ja as F,ha as G,Oa as H,ka as I,ra as J,ca as K,Ia as L,za as M,Sa as N,Ra as O,Aa as P,qi as Q,Da as R,fo as S,oo as T,ga as U,Ea as V,ma as W,na as X,ia as Y,Zi as Z,ro as _,vo as a,Ui as at,co as b,Co as c,Fi as ct,Eo as d,Ae as dt,Yi as et,To as f,ke as ft,Qa as g,Xa as h,yo as i,Bi as it,Ba as j,$ as k,_o as l,Ii as lt,qa as m,xo as n,Q as nt,bo as o,Wi as ot,so as p,je as pt,Ji as q,go as r,zi as rt,wo as s,Pi as st,Oo as t,ea as tt,Do as u,Oe as ut,ho as v,Ka as w,no as x,Ga as y,wa as z};
|
|
191
|
+
`)}function Ui(e,t){let n=t.filter(t=>t in e),r=t.map(e=>`--${String(e)}`).join(` or `);if(n.length>1)throw new Q(`Only one of ${r} can be specified.`);if(n.length===0)throw new Q(`Specify one of ${r}.`);return{key:n[0],value:e[n[0]]}}function Wi(e,t){let n=t.filter(t=>t in e),r=t.map(e=>`--${String(e)}`).join(` or `);if(n.length>1)throw new Q(`Only one of ${r} can be specified.`)}var Q=class extends Error{name=`CommandError`};const Gi=i({id:n(),label:n(),url:n()}),Ki=i({results:v(Gi)});async function qi(e){let{repo:t,host:n}=e;return(await aa(new URL(`core/repository/preview_configs`,oa(t,n)),e,{schema:Ki,unknownErrorMessage:`Failed to load previews`})).results}async function Ji(e,t){let{repo:n,host:r}=t;await aa(new URL(`previews/new`,oa(n,r)),t,{method:`POST`,json:{name:e.name,websiteURL:e.websiteURL,resolverPath:e.resolverPath},unknownErrorMessage:`Failed to add preview`})}async function Yi(e,t){let{repo:n,host:r}=t;await aa(new URL(`previews/delete/${encodeURIComponent(e)}`,oa(n,r)),t,{method:`POST`,json:{},notFoundMessage:`Preview not found: ${e}`,unknownErrorMessage:`Failed to remove preview`})}const Xi=i({kind:e([`prod`,`stage`,`dev`]),name:n(),domain:n(),users:v(i({id:n()}))});async function Zi(e){let{repo:t,host:n}=e;return(await aa(new URL(`core/environments`,oa(t,n)),e,{schema:i({results:v(Xi)})})).results}const Qi=i({simulator_url:a(n())});async function $i(e){let{repo:t,host:n}=e;return(await aa(new URL(`core/repository`,oa(t,n)),e,{schema:Qi,unknownErrorMessage:`Failed to load simulator URL`})).simulator_url}async function ea(e,t){let{repo:n,host:r}=t;await aa(new URL(`core/repository`,oa(n,r)),t,{method:`PATCH`,json:{simulator_url:e},unknownErrorMessage:`Failed to set simulator URL`})}const ta=i({total:r()});async function na(e,t){let{repo:n,host:r}=t;return(await aa(new URL(`core/documents/search`,oa(n,r)),t,{method:`POST`,json:{customTypes:[e],limit:0},schema:ta})).total}async function ra(e,t){let{repo:r,host:i}=t;return(await aa(new URL(`core/releases`,oa(r,i)),t,{method:`POST`,json:e,schema:f({id:n()}),unknownErrorMessage:`Failed to create a release`})).id}async function ia(e,t){let{repo:n,host:r}=t;await aa(new URL(`core/releases/${encodeURIComponent(e)}`,oa(n,r)),t,{method:`DELETE`,notFoundMessage:`Release not found: ${e}`,unknownErrorMessage:`Failed to delete the release`})}function aa(e,t,n={}){return h(e,{credentials:{"prismic-auth":t.token},notFoundMessage:`Repository not found: ${t.repo}`,...n})}function oa(e,t){return new URL(`https://${e}.${t}/`)}function sa(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 ca(e){return e.insert.length+e.update.length+e.delete.length>0}function la(e){return _a(new URL(`customtypes`,ya(e.host)),e)}function ua(e){return _a(new URL(`slices`,ya(e.host)),e)}async function da(e,t){await _a(new URL(`bulk-update`,ya(t.host)),t,{method:`POST`,json:{changes:e},unknownErrorMessage:`Failed to update models`})}const fa=i({values:i({url:n(),fields:t(n(),n())}),imgixEndpoint:n()}),pa={"image/png":`.png`,"image/jpeg":`.jpg`,"image/gif":`.gif`,"image/webp":`.webp`};async function ma(e,t){await va(new URL(`delete`,ba(t.host)),t,{method:`POST`,json:{sliceId:e}})}async function ha(e,t){let{sliceId:n,variationId:r,repo:i,host:a}=t,o=e.type;if(!(o in pa))throw new ga(o);let s=await va(new URL(`presigned-url`,ba(a)),t,{schema:fa}),c=pa[o],l=`${i}/shared-slices/${n}/${r}/${ie(`sha1`).update(new Uint8Array(await e.arrayBuffer())).digest(`hex`)}${c}`,u=new FormData;for(let[e,t]of Object.entries(s.values.fields))u.append(e,t);u.set(`key`,l),u.set(`Content-Type`,o),u.set(`file`,e),await h(s.values.url,{method:`POST`,body:u});let d=new URL(l,_(s.imgixEndpoint));return d.searchParams.set(`auto`,`compress,format`),d}var ga=class extends Error{name=`UnsupportedFileTypeError`;constructor(e){let t=Object.keys(pa);super(`Unsupported file type: ${e||`unknown`}. Supported: ${t.join(`, `)}`)}};function _a(e,t,n={}){return t.releaseId&&e.searchParams.set(`release`,t.releaseId),h(e,{headers:{repository:t.repo,Authorization:`Bearer ${t.token}`},notFoundMessage:`Repository not found: ${t.repo}`,...n})}function va(e,t,n={}){let r=new URL(e);return r.searchParams.set(`repository`,t.repo),h(r,{headers:{repository:t.repo,Authorization:`Bearer ${t.token}`},...n})}function ya(e){return new URL(`https://customtypes.${e}/`)}function ba(e){return new URL(`https://api.internal.${e}/screenshot/`)}const xa=[`Slices`,`UID`,`Choice`];function Sa(e,t,n){if(t in e)throw new La(t);e[t]=n}function Ca(e,t){let n=e[t];if(!n)throw new Ra(t);return n}function wa(e,t,n){let r=new Map(n.map(e=>[e.id,e])),i=r.get(t);if(!i)throw new $(`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 $(`Field "${e}" does not exist on type "${n}".`);let c=o.filter(Boolean);if(c.length===0){if(xa.includes(s.type)||e===`uid`)throw new $(`Field "${e}" cannot be fetched from a content relationship.`);if(s.type===`Group`)throw new $(`Field "${e}" is a group. Select specific subfields.`);return e}if(c.length!==o.length)throw new $(`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 $(`Content relationships cannot be nested more than once.`);let t=s.config?.customtypes;if(!t||t.length!==1)throw new $(`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 $(`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 $(`Field "${e}" is not a group or content relationship field.`)})};return a(e,Object.assign({},...Object.values(i.json)),i.id,!0)}function Ta(e,t,n){let r;if(n){if(r=t.json[n],!r)throw new Ba(n,t.id)}else{let[n]=e.split(`.`);if(r=Object.values(t.json).find(e=>n in e),!r)throw new Ra(n)}return Fa(e,r)}function Ea(e,t,n){let r=t.variations.find(e=>e.id===n);if(!r)throw new Va(n,t.id);return r.primary??={},Fa(e,r.primary)}async function Da(e){let[t,n]=await Promise.all([la(e),ua(e)]);return{customTypes:t,slices:n}}async function Oa({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 da(i,n)}function ka(e,t,n={}){let{treatNonCanonicalAsChanged:r=!1}=n;return{customTypes:sa(e.customTypes,t.customTypes,{getKey:e=>e.id,equals:(e,t)=>JSON.stringify(Aa(e))===JSON.stringify(r?t:Aa(t))}),slices:sa(e.slices,t.slices,{getKey:e=>e.id,equals:(e,t)=>JSON.stringify(ja(e))===JSON.stringify(r?t:ja(t))})}}function Aa(e){return{...Pa(e),json:Object.fromEntries(Object.entries(e.json).map(([e,t])=>[e,Ma(t)]))}}function ja(e){return{...Pa(e),variations:e.variations.map(e=>{let t=Pa(e);return e.primary&&(t.primary=Ma(e.primary)),e.items&&(t.items=Ma(e.items)),t})}}function Ma(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=Pa(t);return t.type===`Group`&&t.config?.fields&&n.type===`Group`&&n.config?.fields&&(n.config.fields=Ma(t.config.fields)),t.type===`Slices`&&t.config?.choices&&n.type===`Slices`&&n.config?.choices&&(n.config.choices=Na(t.config.choices)),[e,n]}))}function Na(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=Pa(t);return t.type===`Slice`&&n.type===`Slice`&&(t[`non-repeat`]&&(n[`non-repeat`]=Ma(t[`non-repeat`])),t.repeat&&(n.repeat=Ma(t.repeat))),[e,n]}))}function Pa(e){return Array.isArray(e)?e.map(Pa):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,Pa(t)]))}function Fa(e,t){let[n,...r]=e.split(`.`);if(r.length===0)return{fields:t,fieldId:n};let i=Ca(t,n);if(i.type!==`Group`)throw new za(n);return i.config??={},i.config.fields??={},Fa(r.join(`.`),i.config.fields)}function Ia(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 La=class extends Error{name=`FieldExistsError`;constructor(e){super(`Field "${e}" already exists.`)}},Ra=class extends Error{name=`FieldNotFoundError`;constructor(e){super(`Field "${e}" does not exist.`)}},za=class extends Error{name=`UnsupportedNestedFieldError`;constructor(e){super(`Field "${e}" does not support nested fields.`)}},$=class extends Error{name=`FieldSelectionError`},Ba=class extends Error{name=`TabNotFoundError`;constructor(e,t){super(`Tab "${e}" does not exist on type "${t}".`)}},Va=class extends Error{name=`SliceVariationNotFoundError`;constructor(e,t){super(`Variation "${e}" does not exist on slice "${t}".`)}};const Ha=`prismic.config.json`,Ua=i({type:n(),path:n(),uid:a(n()),lang:a(n()),resolvers:a(t(n(),n()))}),Wa=i({repositoryName:n(),documentAPIEndpoint:a(y()),libraries:a(v(n())),routes:a(v(Ua))});async function Ga(e){let t=await Za();return await te(t,c(e)),t}async function Ka(){let e=await Ya();try{return await u(e,{schema:Wa})}catch{throw new qa}}var qa=class extends Error{name=`InvalidPrismicConfigError`;message=`${Ha} is invalid. Run \`prismic init\` to re-create a config.`};async function Ja(e){let t=await Ya(),n={...await Ka(),...e};return await te(t,c(n)),n}async function Ya(){let e=await g(Ha,{stop:`package.json`});if(!e)throw new Xa;return e}var Xa=class extends Error{name=`MissingPrismicConfigError`;message=`Could not find a ${Ha} file. Run \`prismic init\` to create a config.`};async function Za(){try{let e=await C();return new URL(Ha,e)}catch(e){throw e instanceof w?new Qa({cause:e}):e}}var Qa=class extends Error{name=`UnknownProjectRootError`;constructor(e){super(`Could not find your project root.`,e)}};async function $a(e){let{routes:t=[]}=await Ka();if(t.some(t=>t.type===e.id))return;let n=ro(e),r={type:e.id,path:n};await Ja({routes:[...t,r].sort((e,t)=>e.type.localeCompare(t.type))})}async function eo(e){e.format===`page`?await $a(e):await to(e.id)}async function to(e){let{routes:t=[]}=await Ka(),n=t.filter(t=>t.type!==e);t.length!==n.length&&await Ja({routes:n})}function no(e,t){return e.find(e=>e.type===t&&!e.uid&&!/[?*+]/.test(e.path))}function ro(e){let{id:t,repeatable:n}=e,r=t.replaceAll(`_`,`-`).toLowerCase();return n?t===`page`?`/:uid`:`/${r}/:uid`:t===`homepage`?`/`:`/${r}`}const io=`slicemachine.config.json`,ao=i({repositoryName:n(),libraries:a(v(n()))});async function oo(){let e=await lo();try{return await u(e,{schema:ao})}catch{throw new so}}var so=class extends Error{name=`InvalidLegacySliceMachineConfigError`;message=`${io} is invalid.`};async function co(){let e=await lo();await O(e)}async function lo(){let e=await g(io,{stop:`package.json`});if(!e)throw new uo;return e}var uo=class extends Error{name=`MissingLegacySliceMachineConfigError`;message=`Could not find a ${io} file.`};async function fo(){let e;try{e=await Ya()}catch(t){if(t instanceof Xa)e=await Za();else throw t}let t=new URL(`.`,e);return _(A(await D(k(t))))}async function po(){try{return(await Ka()).repositoryName}catch(e){if(e instanceof Xa)try{return(await oo()).repositoryName}catch{}throw e}}async function mo(){let e=(await Ka()).libraries;if(!e||e.length<1)return;let t=await fo();return e.map(e=>_(new URL(e.replace(/^\//,``),t)))}async function ho(){let e=await fo();return p(new URL(`tsconfig.json`,e))}const go=[`next`,`nuxt`,`sveltekit`];async function _o(){let{dependencies:e,devDependencies:t,peerDependencies:n}=await S(),r={...e,...t,...n};if(`next`in r){let{NextJsAdapter:e}=await import(`./nextjs-TJI3bKFA.mjs`);return new e}if(`nuxt`in r){let{NuxtAdapter:e}=await import(`./nuxt-DfWyc1bJ.mjs`);return new e}if(`@sveltejs/kit`in r){let{SvelteKitAdapter:e}=await import(`./sveltekit-CC1sBn9O.mjs`);return new e}throw new vo}var vo=class extends Error{name=`NoSupportedFrameworkError`;message=`No supported framework found. Run this command in a Next.js, Nuxt, or SvelteKit project.`},yo=class extends Error{name=`ModelExistsError`},bo=class extends Error{name=`SliceNotFoundError`;constructor(e){super(`Slice "${e}" does not exist. Run \`prismic slice list\` to see available IDs.`)}},xo=class extends Error{name=`CustomTypeNotFoundError`;constructor(e){super(`Type "${e}" does not exist. Run \`prismic type list\` to see available IDs.`)}};async function So(e,t,n,r){let i=r.find(e=>e.model.id===t||e.directory.href===n.href);if(!i&&!await p(n))return;let a=s(await fo(),i?.directory??n),o=i?` (id: ${i.model.id})`:``;throw new yo(`A ${e} already exists at ${a}${ne}${o}.`)}async function Co(){return await(await _o()).getEnvironment()??await po()}async function wo(e){let t=await wi(`**/*.{js,jsx,mjs,ts,tsx,mts,svelte}`,{cwd:k(await fo()),absolute:!0,ignore:`**/{node_modules,build,dist,out}/**`});for(let n of t)try{if((await E(n,`utf8`)).includes(e))return!0}catch{}return!1}async function To(e,t){await p(e)||await o(e,t)}async function Eo(){return await ho()?`ts`:`js`}async function Do(e){let t=ee(await C());try{let{version:n}=t(`${e}/package.json`),r=Number.parseInt(n.split(`.`)[0]);return Number.isNaN(r)?1/0:r}catch{return 1/0}}var Oo=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 po(),...await x()};await $i(t)||await ea(this.localSimulatorUrl,t),(await qi(t)).length===0&&await Ji(this.localPreviewConfig,t)}async getSliceLibraries(){return await mo()??[await this.getDefaultSliceLibrary()]}async getSlices(){return Ao(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=Ia((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 bo(e)}async createSlice(e){let[t]=await this.getSliceLibraries(),n=_(new URL(ke(e.name),_(t)));await So(`slice`,e.id,n,await this.getSlices()),await o(new URL(`model.json`,n),c(ja(e))),await this.createSliceIndexFile(t),await this.createSliceComponent(e,n)}async updateSlice(e){let t=await this.getSlice(e.id);await o(t.modelPath,c(ja(e))),await this.createSliceIndexFile(t.library)}async deleteSlice(e){let t=await this.getSlice(e);await O(t.directory,{recursive:!0}),await this.createSliceIndexFile(t.library)}async getCustomTypeLibraries(){return[new URL(`customtypes/`,await fo())]}async getCustomTypes(){return Ao(await this.getCustomTypeLibraries(),`*/index.json`)}async getCustomType(e){let t=(await this.getCustomTypes()).find(t=>t.model.id===e);if(!t)throw new xo(e);return t}async createCustomType(e){let[t]=await this.getCustomTypeLibraries(),n=_(new URL(e.id,_(t)));if(await So(`type`,e.id,n,await this.getCustomTypes()),await o(new URL(`index.json`,n),c(Aa(e))),e.format!==`page`)return[];await $a(e);let r=await fo();return(await this.writePageFiles(e)).map(({path:t})=>`Skipped ${s(r,t)} (already exists). Run \`prismic gen page ${e.id}\` to get the code.`)}async writePageFiles(e){let{routes:t=[]}=await Ka(),n=(no(t,e.id)?.path??ro(e)).split(`/`).filter(Boolean).map(e=>e.startsWith(`:`)?`[${e.slice(1)}]`:e).join(`/`),r=[];for(let t of await this.getPageFiles(e,n))await p(t.path)?r.push(t):await o(t.path,t.contents);return r}async updateCustomType(e){let t=await this.getCustomType(e.id);await o(t.modelPath,c(Aa(e))),await eo(e)}async deleteCustomType(e){let t=await this.getCustomType(e);await O(t.directory,{recursive:!0}),await to(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 fo()),t=Rn({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 o(e,t),e}async getEnvironment(){let e=await ko();if(await p(e))return(await l(e))[this.environmentEnvVarName]||void 0}async setEnvironment(e){await m(await ko(),this.environmentEnvVarName,e)}async unsetEnvironment(){await d(await ko(),this.environmentEnvVarName)}};async function ko(){return new URL(`.env.local`,await fo())}async function Ao(e,t){let n=[];for(let r of e){let e=await wi(t,{absolute:!0,cwd:r}),i=await Promise.all(e.map(async e=>{let t=A(e),n=await u(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{$i as $,Va as A,Ta as B,po as C,La as D,Ja as E,ja as F,ha as G,Oa as H,ka as I,ra as J,ca as K,Ia as L,za as M,Sa as N,Ra as O,Aa as P,qi as Q,Da as R,fo as S,oo as T,ga as U,Ea as V,ma as W,na as X,ia as Y,Zi as Z,ro as _,vo as a,Ui as at,co as b,Co as c,Fi as ct,Eo as d,Ae as dt,Yi as et,To as f,ke as ft,Qa as g,Xa as h,yo as i,Bi as it,Ba as j,$ as k,_o as l,Ii as lt,qa as m,xo as n,Q as nt,bo as o,Wi as ot,so as p,je as pt,Ji as q,go as r,zi as rt,wo as s,Pi as st,Oo as t,ea as tt,Do as u,Oe as ut,ho as v,Ka as w,no as x,Ga as y,wa as z};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{B as e,D as t,H as n,I as r,L as i,N as a,O as o,P as s,R as c,S as ee,T as l,U as u,V as te,_ as d,c as f,f as p,k as m,l as h,s as g,v as _,x as ne}from"./request-DJTl_0US.mjs";import{i as re,r as v,t as y}from"./segment-
|
|
1
|
+
import{B as e,D as t,H as n,I as r,L as i,N as a,O as o,P as s,R as c,S as ee,T as l,U as u,V as te,_ as d,c as f,f as p,k as m,l as h,s as g,v as _,x as ne}from"./request-DJTl_0US.mjs";import{i as re,r as v,t as y}from"./segment-yGieXuDf.mjs";import{readFile as b,rm as x}from"node:fs/promises";import{fileURLToPath as S,pathToFileURL as C}from"node:url";import{spawn as w}from"node:child_process";import{createServer as T}from"node:http";import{homedir as E}from"node:os";import{existsSync as ie}from"node:fs";// @__NO_SIDE_EFFECTS__
|
|
2
2
|
function ae(t){return e(ne,t)}const oe=`prismic.io`,se=a({PROD:i(),PRISMIC_SENTRY_DSN:ee(t(),`https://e1886b1775bd397cd1afc60bfd2ebfc8@o146123.ingest.us.sentry.io/4510445143588864`),PRISMIC_SENTRY_ENVIRONMENT:s(r()),PRISMIC_SENTRY_ENABLED:s(i()),PRISMIC_TELEMETRY_ENABLED:s(i()),PRISMIC_HOST:s(r()),PRISMIC_TOKEN:s(r()),PRISMIC_DOCS_HOST:s(r()),PRISMIC_CONFIG_DIR:s(r()),PRISMIC_TYPE_BUILDER_ENABLED:s(i()),PRISMIC_SYNC_POLL_MS:s((/* @__PURE__ */ ae()).check(te(100)))}),D=u(se,{...process.env,PROD:`true`});function ce(e,t){if(t)return _(C(t));if(process.platform===`win32`){let t=process.env.APPDATA;if(t)return new URL(`${e}/`,_(C(t)))}if(process.platform!==`darwin`){let t=process.env.XDG_CONFIG_HOME;if(t)return new URL(`${e}/`,_(C(t)))}let n=_(C(E()));return new URL(`.config/${e}/`,n)}const O=ce(`prismic`,D.PRISMIC_CONFIG_DIR),k=new URL(`credentials.json`,O),le=new URL(`update-notifier.json`,O),A=new URL(`analytics.json`,O);async function j(e,t){let n=new URL(`refreshtoken`,P(t.host));return n.searchParams.set(`token`,e),g(n,{schema:r()})}const M=c([a({type:o(`USER`),email:r(),shortId:r()}),a({type:o(`Machine2Machine`),domain:r(),appName:r()})]);async function N(e,t){let n=new URL(`validate`,P(t.host));return e&&n.searchParams.set(`token`,e),g(n,{schema:M})}function P(e){return new URL(`https://auth.${e}/`)}function F(){if(process.env.AI_AGENT!==void 0)return process.env.AI_AGENT.toLowerCase()||void 0;if(process.env.CLAUDE_CODE_IS_COWORK===`1`||process.env.CLAUDE_CODE_IS_COWORK===`true`)return`claude-cowork`;if(process.env.CLAUDECODE===`1`||process.env.CLAUDE_CODE)return`claude-code`;if(process.env.CODEX_CI===`1`||process.env.CODEX_SANDBOX||process.env.CODEX_THREAD_ID)return`codex`;if(process.env.CURSOR_AGENT===`1`||process.env.CURSOR_EXTENSION_HOST_ROLE===`agent-exec`)return`cursor`;if(process.env.CLINE_ACTIVE===`true`)return`cline`;if(process.env.ANTIGRAVITY_AGENT)return`antigravity`;if(process.env.AUGMENT_AGENT===`1`)return`augment`;if(process.env.OPENCODE_CLIENT===`1`)return`opencode`;if(process.env.GEMINI_CLI===`1`)return`gemini-cli`;if(process.env.TRAE_AI_SHELL_ID)return`trae`;if(process.env.REPL_ID)return`replit`;if(process.env.COPILOT_MODEL||process.env.COPILOT_ALLOW_ALL||process.env.COPILOT_GITHUB_TOKEN)return`github-copilot`;let e=process.env.AGENT?.toLowerCase();if(e===`goose`||e===`amp`)return e;if(process.platform===`linux`&&ie(`/opt/.devin`))return`devin`;if(process.env.IS_SANDBOX===`yes`)return`unknown-sandbox`}const I=a({anonymousId:r(),userId:s(r())}),L=!D.PRISMIC_TOKEN;let R=!1,z,B,V,H,U;async function W(e){let{host:t,repo:n}=e;n&&(z=n),V=e.userIntent,H=e.taskId;let r=t===`prismic.io`?`cGjidifKefYb6EPaGaqpt8rQXkv5TD6P`:`Ng5oKJHCGpSWplZ9ymB7Pu7rm0sTDeiG`;B=F();let i=await q();U=i??{anonymousId:crypto.randomUUID()},i||await J(U),y({writeKey:r,anonymousId:U.anonymousId,userId:G()})}function ue(e){re({userId:e.shortId,intercomHash:e.intercomHash}),L&&!R&&U&&(U.userId=e.shortId,J(U))}function G(){return L?U?.userId:void 0}function de(){if(!U)return{};let e=G();return{"Prismic-Anonymous-Id":U.anonymousId,...e?{"Prismic-User-Id":e}:{}}}async function K(){R=!0;let e=await q();e?.userId&&await J({anonymousId:e.anonymousId})}async function q(){return p(A,{schema:I}).catch(()=>void 0)}async function J(e){await d(A,f(e)).catch(()=>{})}function fe(e,t={}){let{watch:n}=t;v(`Prismic CLI Start`,{properties:{commandType:e,fullCommand:process.argv.join(` `),repository:z,watch:n,agent:B,userIntent:V,taskId:H},groupId:z?{Repository:z}:void 0})}function pe(e,t={}){let{watch:n,error:r}=t,i=r?r instanceof Error?r.message:String(r):void 0;v(`Prismic CLI End`,{properties:{commandType:e,fullCommand:process.argv.join(` `),success:!process.exitCode,repository:z,watch:n,error:i?.slice(0,512),agent:B,userIntent:V,taskId:H},groupId:z?{Repository:z}:void 0})}const me=a({telemetry:l()});async function he(){try{return!(await Y(E())||await Y(process.cwd()))}catch{return!0}}async function Y(e){return(await p(new URL(`.prismicrc`,_(C(e))),{schema:me}).catch(()=>void 0))?.telemetry===!1}const ge=m({token:s(r().check(n(1))),host:s(r().check(n(1)))});async function X(){let e=await Z();return{token:D.PRISMIC_TOKEN||e?.token,host:D.PRISMIC_HOST||e?.host||`prismic.io`}}async function _e(){if(D.PRISMIC_TOKEN)return;let{token:e,host:t}=await X();if(!e)return;let n=await j(e,{host:t});return await Q({token:n,host:t}),n}async function ve(){if(!await h(k))return!0;try{return await x(k,{force:!0}),await K(),!0}catch{return!1}}async function Z(){return p(k,{schema:ge}).catch(()=>void 0)}async function Q(e){await d(k,f(e))}async function ye(e){let{host:t}=await X(),n=`https://${t}`;return new Promise((r,i)=>{let a=T((e,i)=>{if(e.method===`OPTIONS`){i.writeHead(204,{"Access-Control-Allow-Origin":n,"Access-Control-Allow-Methods":`POST, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type`}),i.end();return}if(e.method===`POST`){let s=(e,t)=>{i.writeHead(e,{"Access-Control-Allow-Origin":n,"Content-Type":`application/json`}),i.end(JSON.stringify(t))},c=``;e.on(`data`,e=>{c+=e.toString()}),e.on(`end`,async()=>{try{let{cookies:e,email:n}=JSON.parse(c),i=e.find(e=>e.startsWith(`prismic-auth=`))?.split(`;`)[0]?.replace(/^prismic-auth=/,``);if(!i){s(400,{error:`Invalid request`});return}await Q({token:i,host:t}),await K(),s(200,{success:!0}),clearTimeout(o),a.close(),r({email:n})}catch{s(400,{error:`Invalid request`})}});return}i.writeHead(404),i.end()}),o=setTimeout(()=>{a.close(),i(/* @__PURE__ */ Error(`Login timed out. Please try again.`))},18e4),s=async()=>{let n=a.address();if(!n||typeof n==`string`){clearTimeout(o),a.close(),i(/* @__PURE__ */ Error(`Failed to start login server`));return}let r=await xe(t,n.port);e.onReady(r)};a.on(`error`,e=>{e.code===`EADDRINUSE`&&a.listening===!1?a.listen(0,`0.0.0.0`,s):(clearTimeout(o),i(e))}),a.listen(5555,`0.0.0.0`,s)})}const $=new URL(`.prismic`,_(C(E())));async function be(){let e;try{e=await b($,`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 x($,{force:!0})}catch{}}async function xe(e,t){let n=new URL(`dashboard/cli/login`,`https://${e}/`);return n.searchParams.set(`source`,`prismic-cli`),n.searchParams.set(`port`,t.toString()),n}function Se(){try{let e=S(new URL(`./subprocesses/refreshToken.mjs`,import.meta.url));w(process.execPath,[e],{detached:!0,stdio:`ignore`}).unref()}catch{}}export{le as _,_e as a,G as c,pe as d,fe as f,O as g,N as h,ve as i,W as l,F as m,ye as n,Se as o,ue as p,X as r,de as s,be as t,he as u,oe as v,D as y};
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as f,M as p,N as m,O as h,P as g,Q as _,R as v,S as y,T as b,U as x,V as S,W as C,X as w,Y as ee,Z as te,_ as ne,a as re,at as ie,b as ae,c as T,dt as E,et as oe,ft as se,g as ce,h as le,i as ue,it as D,j as de,k as fe,l as O,lt as k,m as pe,n as me,nt as A,o as he,ot as ge,p as _e,pt as ve,q as ye,r as be,rt as j,st as xe,tt as Se,ut as Ce,w as we,x as Te,y as Ee,z as De}from"./adapters-
|
|
2
|
+
import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as f,M as p,N as m,O as h,P as g,Q as _,R as v,S as y,T as b,U as x,V as S,W as C,X as w,Y as ee,Z as te,_ as ne,a as re,at as ie,b as ae,c as T,dt as E,et as oe,ft as se,g as ce,h as le,i as ue,it as D,j as de,k as fe,l as O,lt as k,m as pe,n as me,nt as A,o as he,ot as ge,p as _e,pt as ve,q as ye,r as be,rt as j,st as xe,tt as Se,ut as Ce,w as we,x as Te,y as Ee,z as De}from"./adapters-Bt9QKcJb.mjs";import{n as Oe,t as ke}from"./package-Dyw1b366.mjs";import{A as Ae,E as je,F as Me,I as M,M as Ne,N,O as Pe,P,R as Fe,T as F,U as Ie,W as Le,_ as Re,a as I,b as L,c as R,f as ze,g as Be,i as Ve,j as He,k as Ue,n as z,o as We,p as Ge,r as Ke,s as B,t as qe,v as Je,w as V,y as H,z as Ye}from"./request-DJTl_0US.mjs";import{_ as Xe,c as Ze,d as Qe,f as $e,g as et,h as tt,i as nt,l as rt,m as it,n as at,o as ot,p as st,r as U,s as ct,t as lt,u as ut,y as W}from"./auth-NkX7Docj.mjs";import{a as dt,c as G,d as ft,i as pt,l as mt,s as ht,t as gt,u as _t}from"./packageJson-Bxht6H4y.mjs";import{t as vt}from"./update-notifier-ChP_LYxw.mjs";import{isDeepStrictEqual as yt,parseArgs as bt}from"node:util";import{realpath as xt,rm as St}from"node:fs/promises";import{fileURLToPath as Ct,pathToFileURL as wt}from"node:url";import{createHash as Tt,randomBytes as Et}from"node:crypto";import{exec as Dt}from"node:child_process";import{setTimeout as Ot}from"node:timers/promises";const kt=N({error:Pe(`invalid_auth_context`)});function At(e){return e instanceof I&&Le(kt,e.body).success}async function jt(e){if(e instanceof I||e instanceof z){let{token:t}=await U();return t?W.PRISMIC_TOKEN?At(e)?"This token cannot run administrative commands. Unset PRISMIC_TOKEN and run `prismic login`.":`PRISMIC_TOKEN is invalid or expired, or doesn't have access to this repository. Unset it to log in with a browser, or replace it with a valid token.`:e instanceof I?"Your session is invalid or expired. Run `prismic login` to sign in again.":`You do not have access to this repository. Check the repository name or log in with an account that has access.`:"Not logged in. Run `prismic login` first."}if(e instanceof qe||e instanceof We){let t=new URL(e.response.url);t.search=``;let n=e.message?`${e.message}\n\n`:``;return xe`
|
|
3
3
|
${n}Prismic responded with an unexpected error. Try again, and report it if it keeps happening.
|
|
4
4
|
|
|
5
5
|
Status: ${e.status} ${e.statusText}
|
|
@@ -210,13 +210,13 @@ Ending the session...`),await m()&&console.info(`Session ended.`)});async functi
|
|
|
210
210
|
Skips files that already exist.
|
|
211
211
|
`,options:{"no-install":{type:`boolean`,description:`Skip installing dependencies`}}},async({values:e})=>{let t=await O(),n=await G();await t.setupProject();for(let{name:e,from:t,to:r}of dt(n,await G()))console.info(`Updated ${e} from ${t} to ${r}. Check your code for breaking changes in the new version.`);if(!e[`no-install`])try{console.info(`Installing dependencies...`),await ht()}catch{console.warn(`Could not install dependencies. Run \`${await pt()}\` to finish.\nThe rest of the setup is done.`)}console.info(`Generated setup files.`);let r=await t.getSetupInstructions();r&&console.info(`\n${r}`)}),Sr=j({name:`prismic gen slice-index`,description:`Generate the slice index file of each slice library.`},async()=>{let e=await O(),t=await e.getSliceLibraries();for(let n of t)await e.createSliceIndexFile(n);console.info(t.length===1?`Generated the slice index file.`:`Generated ${t.length} slice index files.`)}),Cr=j({name:`prismic gen types`,description:`Generate TypeScript types for slices and content types.`},async()=>{let e=await(await O()).generateTypes(),t=await y(),n=L(t,e);console.info(`Generated types at ${n}`)}),wr=D({name:`prismic gen`,description:`Generate files from local Prismic models.`,commands:{page:{handler:br,description:`Generate the page files for a page type`},setup:{handler:xr,description:`Generate framework-specific Prismic setup`},"slice-index":{handler:Sr,description:`Generate the slice index file of each slice library`},types:{handler:Cr,description:`Generate TypeScript types from local models`}}});const Tr=N({id:M(),revision:M(),framework:M(),deploymentUrl:Ye()}),Er=N({name:P(M()),starter:He(Tr),framework:P(M()),quotas:P(N({sliceMachineEnabled:F()}))});function Dr(e){return Mr(Pr(e.host),e,{schema:Er})}async function Or(e,t){await Mr(new URL(`type-builder`,Pr(t.host)),t,{method:`PATCH`,json:{framework:e}})}const kr=N({completedSteps:V(M())});async function Ar(e){return Nr(new URL(`onboarding`,Pr(e.host)),e,{schema:kr})}async function jr(e,t){return Nr(new URL(`onboarding/${encodeURIComponent(e)}/toggle`,Pr(t.host)),t,{method:`PATCH`,schema:kr})}function Mr(e,t,n={}){let r=new URL(e);return r.searchParams.set(`repository`,t.repo),B(r,{headers:{Authorization:`Bearer ${t.token}`,repository:t.repo},notFoundMessage:`Repository not found: ${t.repo}`,...n})}function Nr(e,t,n={}){let r=new URL(e);return r.searchParams.set(`repository`,t.repo),B(r,{credentials:{"prismic-auth":t.token},...n})}function Pr(e){return new URL(`https://api.internal.${e}/repository/`)}const Fr=N({email:M(),shortId:M(),intercomHash:M()});async function Ir(e){let t=new URL(`user/profile`,`https://api.internal.${e.host}/`);return B(t,{headers:{Authorization:`Bearer ${e.token}`},schema:Fr,unknownErrorMessage:`Failed to load your profile`})}async function Lr(e,t){let{repo:n,token:r,host:i}=t,{completedSteps:a}=await Ar({repo:n,token:r,host:i}),o=e.filter(e=>!a.includes(e));for(let e of o)await jr(e,{repo:n,token:r,host:i})}let X;const Z={tags:{},contexts:{}};function Rr(e){X=e,Z.contexts.Process={command:process.argv.join(` `),cwd:process.cwd()}}function zr(e,t){Z.tags[e]=t}function Br(e,t){Z.contexts[e]=t}function Vr(e){Z.user=e}async function Hr(e){if(X)try{let t=new URL(X.dsn),n=e instanceof Error?e:Error(String(e)),r=crypto.randomUUID().replace(/-/g,``),i={event_id:r,timestamp:Date.now()/1e3,platform:`node`,level:`error`,release:X.appVersion,environment:X.environment||Ur(X.appVersion),tags:Z.tags,user:Z.user,contexts:{...Z.contexts,runtime:{name:`node`,version:process.versions.node}},exception:{values:[{type:n.name,value:n.message.slice(0,2500),stacktrace:Gr(n)}]},extra:{cause:n.cause,fullCommand:process.argv.join(` `)}},a=[JSON.stringify({event_id:r,sent_at:(/* @__PURE__ */ new Date()).toISOString()}),JSON.stringify({type:`event`}),JSON.stringify(i)].join(`
|
|
212
212
|
`);await fetch(Wr(t),{method:`POST`,headers:{"Content-Type":`application/x-sentry-envelope`,"X-Sentry-Auth":`Sentry sentry_version=7, sentry_client=${X.appName}/${X.appVersion}, sentry_key=${t.username}`},body:a,signal:AbortSignal.timeout(2e3)})}catch{}}function Ur(e){let t=e.match(/-(.+?)\./);return t?t[1]:`production`}function Wr(e){return`${e.protocol}//${e.host}/api${e.pathname}/envelope/`}function Gr(e){let t=[];for(let n of(e.stack??``).split(`
|
|
213
|
-
`).slice(1)){let e=n.match(/^\s*at (?:(.+?) \()?(.+?):(\d+):(\d+)\)?$/);e&&t.push({function:e[1]||`?`,filename:e[2],lineno:Number(e[3]),colno:Number(e[4]),in_app:!0})}return t.length>0?{frames:t.reverse()}:void 0}const Kr=N({id:M(),label:M(),customName:Ae(M()),isMaster:F()});async function qr(e){return(await Xr(new URL(`repository/locales`,Zr(e.host)),e,{schema:N({results:V(Kr)}),unknownErrorMessage:`Failed to load locales`})).results}async function Jr(e,t){return Xr(new URL(`repository/locales`,Zr(t.host)),t,{method:`POST`,json:{id:e.id,isMaster:e.isMaster??!1,...e.customName?{customName:e.customName}:{}},schema:Kr,unknownErrorMessage:`Failed to save locale`})}async function Yr(e,t){await Xr(new URL(`repository/locales/${encodeURIComponent(e)}`,Zr(t.host)),t,{method:`DELETE`,notFoundMessage:`Locale not found: ${e}`,unknownErrorMessage:`Failed to remove locale`})}function Xr(e,t,n){let r=new URL(e);return r.searchParams.set(`repository`,t.repo),B(r,{headers:{Authorization:`Bearer ${t.token}`},notFoundMessage:`Repository not found: ${t.repo}`,...n})}function Zr(e){return new URL(`https://api.internal.${e}/locale/`)}
|
|
213
|
+
`).slice(1)){let e=n.match(/^\s*at (?:(.+?) \()?(.+?):(\d+):(\d+)\)?$/);e&&t.push({function:e[1]||`?`,filename:e[2],lineno:Number(e[3]),colno:Number(e[4]),in_app:!0})}return t.length>0?{frames:t.reverse()}:void 0}const Kr=N({id:M(),label:M(),customName:Ae(M()),isMaster:F()});async function qr(e){return(await Xr(new URL(`repository/locales`,Zr(e.host)),e,{schema:N({results:V(Kr)}),unknownErrorMessage:`Failed to load locales`})).results}async function Jr(e,t){return Xr(new URL(`repository/locales`,Zr(t.host)),t,{method:`POST`,json:{id:e.id,isMaster:e.isMaster??!1,...e.customName?{customName:e.customName}:{}},schema:Kr,unknownErrorMessage:`Failed to save locale`})}async function Yr(e,t){await Xr(new URL(`repository/locales/${encodeURIComponent(e)}`,Zr(t.host)),t,{method:`DELETE`,notFoundMessage:`Locale not found: ${e}`,unknownErrorMessage:`Failed to remove locale`})}function Xr(e,t,n){let r=new URL(e);return r.searchParams.set(`repository`,t.repo),B(r,{headers:{Authorization:`Bearer ${t.token}`},notFoundMessage:`Repository not found: ${t.repo}`,...n})}function Zr(e){return new URL(`https://api.internal.${e}/locale/`)}const Qr=N({documentsPublished:F(),documentsUnpublished:F(),releasesCreated:F(),releasesUpdated:F(),tagsCreated:F(),tagsDeleted:F()}),$r=Object.keys(Qr.shape),ei=N({config:je(Qr,{_id:M(),url:M(),active:F(),name:Ae(M()),secret:Ae(M()),headers:Me(M(),M())})});function ti(e){let{repo:t,host:n}=e;return Q(new URL(`app/settings/webhooks`,$(t,n)),e,{schema:V(ei),unknownErrorMessage:`Failed to load webhooks`})}async function ni(e,t){let n=ai({...e,active:!0,headers:{}}),{repo:r,host:i}=t;await Q(new URL(`app/settings/webhooks/create`,$(r,i)),t,{method:`POST`,body:n,unknownErrorMessage:`Failed to create webhook`})}async function ri(e,t,n){let r=ai(t),{repo:i,host:a}=n;await Q(new URL(`app/settings/webhooks/${encodeURIComponent(e)}`,$(i,a)),n,{method:`POST`,body:r,notFoundMessage:`Webhook not found: ${e}`,unknownErrorMessage:`Failed to update webhook`})}async function ii(e,t){let{repo:n,host:r}=t;await Q(new URL(`app/settings/webhooks/${encodeURIComponent(e)}/delete`,$(n,r)),t,{method:`POST`,notFoundMessage:`Webhook not found: ${e}`,unknownErrorMessage:`Failed to delete webhook`})}function ai(e){let t=new FormData;return t.set(`url`,e.url),t.set(`name`,e.name??``),t.set(`secret`,e.secret??``),t.set(`headers`,JSON.stringify(e.headers??{})),t.set(`active`,e.active?`on`:`off`),t.set(`documentsPublished`,e.documentsPublished.toString()),t.set(`documentsUnpublished`,e.documentsUnpublished.toString()),t.set(`releasesCreated`,e.releasesCreated.toString()),t.set(`releasesUpdated`,e.releasesUpdated.toString()),t.set(`tagsCreated`,e.tagsCreated.toString()),t.set(`tagsDeleted`,e.tagsDeleted.toString()),t}const oi=N({id:M(),scope:M(),token:M(),created_at:N({$date:Ne()})}),si=N({id:M(),name:M(),wroom_auths:V(oi)}),ci=N({app_name:M(),token:M(),timestamp:Ne()}),li=N({max_tokens:Ne(),tokens:V(ci)});function ui(e){let{repo:t,host:n}=e;return Q(new URL(`settings/security/contentapi`,$(t,n)),e,{schema:V(si),unknownErrorMessage:`Failed to load OAuth apps`})}async function di(e,t){let{repo:n,host:r}=t;return Q(new URL(`settings/security/oauthapp`,$(n,r)),t,{method:`POST`,json:{app_name:e},schema:si,unknownErrorMessage:`Failed to create OAuth app`})}async function fi(e,t,n){let{repo:r,host:i}=n;return Q(new URL(`settings/security/authorizations`,$(r,i)),n,{method:`POST`,json:{app:e,scope:t},schema:oi,unknownErrorMessage:`Failed to create token`})}async function pi(e,t){let{repo:n,host:r}=t;await Q(new URL(`settings/security/authorizations/${encodeURIComponent(e)}`,$(n,r)),t,{method:`DELETE`,notFoundMessage:`Token not found: ${e}`,unknownErrorMessage:`Failed to delete token`})}function mi(e){let{repo:t,host:n}=e;return Q(new URL(`settings/security/customtypesapi`,$(t,n)),e,{schema:li,unknownErrorMessage:`Failed to load write tokens`})}async function hi(e,t){let{repo:n,host:r}=t;return Q(new URL(`settings/security/token`,$(n,r)),t,{method:`POST`,json:{app_name:e},schema:ci,unknownErrorMessage:`Failed to create write token`})}async function gi(e,t){let{repo:n,host:r}=t;await Q(new URL(`settings/security/token/${encodeURIComponent(e)}`,$(n,r)),t,{method:`DELETE`,notFoundMessage:`Token not found`,unknownErrorMessage:`Failed to delete write token`})}async function _i(e){let{domain:t,host:n}=e;return wi(new URL(`app/dashboard/repositories/${encodeURIComponent(t)}/exists`,Ti(n)),e,{schema:F()})}async function vi(e){let{domain:t,name:n,framework:r,agent:i,host:a}=e,o=new URL(`app/dashboard/repositories`,Ti(a));o.searchParams.set(`app`,`cli`),i&&o.searchParams.set(`agent`,i),await wi(o,e,{method:`POST`,json:{domain:t,name:n,framework:r,plan:`personal`},unknownErrorMessage:`Failed to create repository`})}const yi=N({repository:N({api_access:M()})});async function bi(e){let{repo:t,host:n}=e;return(await Q(new URL(`syncState`,$(t,n)),e,{schema:yi,unknownErrorMessage:`Failed to load repository access`})).repository.api_access}async function xi(e,t){let{repo:n,host:r}=t;await Q(new URL(`settings/security/apiaccess`,$(n,r)),t,{method:`POST`,json:{api_access:e},unknownErrorMessage:`Failed to set repository access`})}const Si=N({repository:N({name:M()})});async function Ci(e,t){let n=new FormData;n.set(`displayname`,e);let{repo:r,host:i}=t;return(await Q(new URL(`app/settings/repository`,$(r,i)),t,{method:`POST`,body:n,schema:Si,unknownErrorMessage:`Failed to set repository name`})).repository.name}function Q(e,t,n={}){return B(e,{credentials:{"prismic-auth":t.token},notFoundMessage:`Repository not found: ${t.repo}`,...n})}function wi(e,t,n={}){return B(e,{credentials:{"prismic-auth":t.token},...n})}function $(e,t){return new URL(`https://${e}.${t}/`)}function Ti(e){return new URL(`https://${e}/`)}const Ei={name:`prismic repo create`,description:`
|
|
214
214
|
Create a new Prismic repository.
|
|
215
215
|
|
|
216
216
|
The CLI generates a random domain, shown in the output. The domain cannot
|
|
217
217
|
be chosen or changed. --name sets only the display name, which
|
|
218
218
|
\`prismic repo set-name\` can change later.
|
|
219
|
-
`,options:{name:{type:`string`,short:`n`,description:`Display name for the repository`},lang:{type:`string`,short:`l`,description:`Master locale for the new repository (default: en-us)`},framework:{type:`string`,short:`f`,description:`Framework the repository is for: ${be.join(`, `)} (default: detected from the project)`}}};var
|
|
219
|
+
`,options:{name:{type:`string`,short:`n`,description:`Display name for the repository`},lang:{type:`string`,short:`l`,description:`Master locale for the new repository (default: en-us)`},framework:{type:`string`,short:`f`,description:`Framework the repository is for: ${be.join(`, `)} (default: detected from the project)`}}};var Di=j(Ei,async({values:e})=>{let t=await O().catch(()=>void 0),{name:n,lang:r,framework:i=t?.id}=e;if(!i)throw new A(`
|
|
220
220
|
No supported framework found. The CLI needs a Next.js, Nuxt, or SvelteKit project to work with a repository.
|
|
221
221
|
|
|
222
222
|
Do one of the following:
|
|
@@ -224,7 +224,7 @@ Ending the session...`),await m()&&console.info(`Session ended.`)});async functi
|
|
|
224
224
|
- Create the project first, then run \`prismic init\` to create and connect a repository.
|
|
225
225
|
- Pass --framework <${be.join(`|`)}> to create the repository now.
|
|
226
226
|
You still need a compatible project to use it. Connect one later with \`prismic init --repo <domain>\`.
|
|
227
|
-
`);if(!be.includes(i))throw new A(`Unsupported framework "${i}". Use one of: ${be.join(`, `)}.`);let{token:a,host:o}=await U(),s=await
|
|
227
|
+
`);if(!be.includes(i))throw new A(`Unsupported framework "${i}". Use one of: ${be.join(`, `)}.`);let{token:a,host:o}=await U(),s=await Oi({name:n,lang:r,framework:i,token:a,host:o});console.info(`Repository created: ${s}`),console.info(`URL: https://${s}.${o}/`)});async function Oi(e){let{name:t,lang:n=`en-us`,framework:r,token:i,host:a}=e,o=await ki({token:i,host:a});if(!o)throw new A(`Failed to create a repository. Please try again.`);let s=it();return await vi({domain:o,name:t??o,framework:r,agent:s,token:i,host:a}),await Jr({id:n,isMaster:!0},{repo:o,token:i,host:a}),await Lr([`createPrismicProject`],{repo:o,token:i,host:a}).catch(()=>{}),o}async function ki(e){let{token:t,host:n}=e,r;for(let e=0;e<5;e++){let e=crypto.randomUUID().replace(/-/g,``).slice(0,8);if(await _i({domain:e,token:t,host:n})){r=e;break}}return r}var Ai=j({name:`prismic init`,description:`
|
|
228
228
|
Initialize a new Prismic project by creating a repository and
|
|
229
229
|
prismic.config.json file. Detects the project framework, installs
|
|
230
230
|
dependencies, and pulls models from Prismic. The CLI generates a random
|
|
@@ -249,56 +249,56 @@ Ending the session...`),await m()&&console.info(`Session ended.`)});async functi
|
|
|
249
249
|
- Create the project first, then run \`prismic init\` again.
|
|
250
250
|
- To create the repository now, run \`prismic repo create --framework <${be.join(`|`)}>\`.
|
|
251
251
|
Connect the project later with \`prismic init --repo <domain>\`.
|
|
252
|
-
`):e}let _=W.PRISMIC_TYPE_BUILDER_ENABLED??h?.quotas?.sliceMachineEnabled;if(m&&h&&(!_||h.framework!==g.id))try{await Or(g.id,{repo:m,token:p,host:u}),_||console.info(`Turned on the Type Builder for repository "${m}".`)}catch(e){if(!(e instanceof z))throw e;if(!_)throw new A(`Repository "${m}" uses the Legacy Builder. Only a repository administrator can turn on the Type Builder. Ask an administrator to run \`prismic init\`.`);console.warn(`Could not set the repository's framework to ${g.id}. Ask a repository administrator to run \`prismic init\`.`)}m||(m=await
|
|
252
|
+
`):e}let _=W.PRISMIC_TYPE_BUILDER_ENABLED??h?.quotas?.sliceMachineEnabled;if(m&&h&&(!_||h.framework!==g.id))try{await Or(g.id,{repo:m,token:p,host:u}),_||console.info(`Turned on the Type Builder for repository "${m}".`)}catch(e){if(!(e instanceof z))throw e;if(!_)throw new A(`Repository "${m}" uses the Legacy Builder. Only a repository administrator can turn on the Type Builder. Ask an administrator to run \`prismic init\`.`);console.warn(`Could not set the repository's framework to ${g.id}. Ask a repository administrator to run \`prismic init\`.`)}m||(m=await Oi({name:e[`repo-name`],lang:n,framework:g.id,token:p,host:u}),console.info(`Created repository: ${m}`));try{let e=u===`prismic.io`?void 0:`https://${m}.cdn.${u}/api/v2/`;o?await a({repositoryName:m,documentAPIEndpoint:e}):await Ee({repositoryName:m,documentAPIEndpoint:e,libraries:c?.libraries,routes:[]})}catch(e){throw e instanceof ce?new A(`Could not find a package.json file. Run this command from a project directory.`):new A(`Failed to create prismic.config.json.`)}if(c){try{await ae()}catch{}let{dependencies:e,devDependencies:t,peerDependencies:n}=await G(),r=Object.keys({...e,...t,...n}).filter(e=>e===`slice-machine-ui`||e.startsWith(`@slicemachine/adapter-`));r.length>0&&await mt(r),console.info(`Migrated slicemachine.config.json to prismic.config.json`)}let y=await G();await g.initProject({setup:!i&&!o});for(let{name:e,from:t,to:n}of dt(y,await G()))console.info(`Updated ${e} from ${t} to ${n}. Check your code for breaking changes in the new version.`);if(!i)try{console.info(`Installing dependencies...`),await ht()}catch{console.warn(`Could not install dependencies. Run \`${await pt()}\` to finish.\nThe rest of the setup is done, so you don't need to run \`prismic init\` again.`)}let[x,S]=await Promise.all([v({repo:m,token:p,host:u}),g.getModels()]),C=l(x,S);if(s&&h?.starter){if(x.customTypes.length===0&&x.slices.length===0)throw new A(`Repository "${m}" has no starter models. Use a repository created from the starter in the Prismic dashboard.`);await Ni(h.starter)}let w=s&&[C.customTypes,C.slices].some(e=>e.update.length>0||e.delete.length>0);if(!w)for(let e of await g.writeModels(C))console.info(e);await g.generateTypes(),f(x.customTypes).length>0&&console.info("\nRun `prismic slice list --legacy` to find legacy slices to upgrade."),w&&console.warn(xe`
|
|
253
253
|
Local and remote models differ, so no model files were changed. The project is connected.
|
|
254
254
|
|
|
255
255
|
Choose the source of truth:
|
|
256
256
|
prismic pull --force Adopt remote models
|
|
257
257
|
prismic push --force Keep local models
|
|
258
|
-
`),s&&h?.starter?(await
|
|
258
|
+
`),s&&h?.starter?(await Mi(g,h.starter,{repo:m,token:p,host:u}),w||(console.info(`
|
|
259
259
|
---`),console.info(`
|
|
260
260
|
Your project is ready! Here's what you can do next:`),console.info("- Run `npm run dev` to start the development server"),console.info(`- Open https://${m}.${u}/builder to preview pages live`),console.info(`
|
|
261
261
|
Start building 🚀`))):(console.info(`
|
|
262
|
-
---`),console.info(`\nInitialized Prismic for repository "${m}".`),console.info("Run `prismic type create <name>` to create a content type."),console.info("Run `prismic pull` to pull models from Prismic."));let ee=await g.getSetupInstructions();ee&&console.info(`\n${ee}`)});async function
|
|
262
|
+
---`),console.info(`\nInitialized Prismic for repository "${m}".`),console.info("Run `prismic type create <name>` to create a content type."),console.info("Run `prismic pull` to pull models from Prismic."));let ee=await g.getSetupInstructions();ee&&console.info(`\n${ee}`)});async function ji(e){let t=await G(),n=e.id.split(`/`).at(-1);return!!(n&&t.name===n)}async function Mi(e,t,n){try{let t=await _(n);await Promise.all(t.filter(e=>e.label===`Starter Preview`).map(e=>oe(e.id,n))),t.some(t=>t.url===e.localPreviewUrl)||await ye(e.localPreviewConfig,n)}catch(t){await Hr(t),console.error(`Could not configure the local preview. Run \`prismic preview add ${e.localPreviewUrl} --name ${e.localPreviewConfig.name}\` manually. Continuing.`)}try{await Se(e.localSimulatorUrl,n)}catch(t){await Hr(t),console.error(`Could not configure the local slice simulator. Run \`prismic preview set-simulator ${e.localSimulatorUrl}\` manually. Continuing.`)}await Lr([`instantStart_continueBuildingLocally`],n).catch(()=>{}),await ji(t)&&await _t(n.repo)}async function Ni(e){if(!await ji(e))return;let t=await y();await Promise.all([St(new URL(`.deployment`,t),{recursive:!0,force:!0}),St(new URL(`documents`,t),{recursive:!0,force:!0})])}var Pi=j({name:`prismic locale add`,description:`
|
|
263
263
|
Add a locale to a Prismic repository.
|
|
264
264
|
|
|
265
265
|
By default, this command reads the repository from prismic.config.json at the
|
|
266
266
|
project root.
|
|
267
|
-
`,positionals:{code:{description:`Locale code (e.g. fr-fr, es-es)`,required:!0}},options:{master:{type:`boolean`,description:`Set as the master locale`},name:{type:`string`,short:`n`,description:`Custom display name (for custom locales)`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T(),master:a=!1,name:o}=t,{token:s,host:c}=await U();await Jr({id:n,isMaster:a,customName:o},{repo:i,token:s,host:c}),console.info(`Locale added: ${n}`)}),
|
|
267
|
+
`,positionals:{code:{description:`Locale code (e.g. fr-fr, es-es)`,required:!0}},options:{master:{type:`boolean`,description:`Set as the master locale`},name:{type:`string`,short:`n`,description:`Custom display name (for custom locales)`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T(),master:a=!1,name:o}=t,{token:s,host:c}=await U();await Jr({id:n,isMaster:a,customName:o},{repo:i,token:s,host:c}),console.info(`Locale added: ${n}`)}),Fi=j({name:`prismic locale list`,description:`
|
|
268
268
|
List all locales in a Prismic repository.
|
|
269
269
|
|
|
270
270
|
By default, this command reads the repository from prismic.config.json at the
|
|
271
271
|
project root.
|
|
272
|
-
`,options:{json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let{env:t,repo:n=t??await T(),json:r}=e,{token:i,host:a}=await U(),o=await qr({repo:n,token:i,host:a});if(r){console.info(R(o));return}if(o.length===0){console.info(`No locales found.`);return}let s=o.map(e=>{let t=e.isMaster?` (master)`:``;return[e.id,`${e.label}${t}`]});console.info(k(s,{headers:[`ID`,`LABEL`]}))}),
|
|
272
|
+
`,options:{json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let{env:t,repo:n=t??await T(),json:r}=e,{token:i,host:a}=await U(),o=await qr({repo:n,token:i,host:a});if(r){console.info(R(o));return}if(o.length===0){console.info(`No locales found.`);return}let s=o.map(e=>{let t=e.isMaster?` (master)`:``;return[e.id,`${e.label}${t}`]});console.info(k(s,{headers:[`ID`,`LABEL`]}))}),Ii=j({name:`prismic locale remove`,description:`
|
|
273
273
|
Remove a locale from a Prismic repository.
|
|
274
274
|
|
|
275
275
|
By default, this command reads the repository from prismic.config.json at the
|
|
276
276
|
project root.
|
|
277
|
-
`,positionals:{code:{description:`Locale code (e.g. en-us, fr-fr)`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U();await Yr(n,{repo:i,token:a,host:o}),console.info(`Locale removed: ${n}`)}),
|
|
277
|
+
`,positionals:{code:{description:`Locale code (e.g. en-us, fr-fr)`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U();await Yr(n,{repo:i,token:a,host:o}),console.info(`Locale removed: ${n}`)}),Li=j({name:`prismic locale set-master`,description:`
|
|
278
278
|
Set the master locale for a Prismic repository.
|
|
279
279
|
|
|
280
280
|
By default, this command reads the repository from prismic.config.json at the
|
|
281
281
|
project root.
|
|
282
|
-
`,positionals:{code:{description:`Locale code (e.g. en-us, fr-fr)`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=await qr({repo:i,token:a,host:o}),c=s.find(e=>e.id===n);if(!c)throw new A(`Locale "${n}" not found. Available locales: ${s.map(e=>e.id).join(`, `)}`);if(c.isMaster)throw new A(`Locale "${n}" is already the master.`);await Jr({id:c.id,isMaster:!0,customName:c.customName??void 0},{repo:i,token:a,host:o}),console.info(`Master locale set: ${n}`)}),
|
|
282
|
+
`,positionals:{code:{description:`Locale code (e.g. en-us, fr-fr)`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=await qr({repo:i,token:a,host:o}),c=s.find(e=>e.id===n);if(!c)throw new A(`Locale "${n}" not found. Available locales: ${s.map(e=>e.id).join(`, `)}`);if(c.isMaster)throw new A(`Locale "${n}" is already the master.`);await Jr({id:c.id,isMaster:!0,customName:c.customName??void 0},{repo:i,token:a,host:o}),console.info(`Master locale set: ${n}`)}),Ri=D({name:`prismic locale`,description:`
|
|
283
283
|
Manage locales in a Prismic repository.
|
|
284
284
|
|
|
285
285
|
Run \`prismic docs view locales\` for details.
|
|
286
|
-
`,commands:{add:{handler:
|
|
286
|
+
`,commands:{add:{handler:Pi,description:`Add a locale`},list:{handler:Fi,description:`List locales`},remove:{handler:Ii,description:`Remove a locale`},"set-master":{handler:Li,description:`Set the master locale`}}}),zi=j({name:`prismic login`,description:`Log in to Prismic via browser.`,options:{"no-browser":{type:`boolean`,description:`Skip opening the browser automatically`}}},async({values:e})=>{let{"no-browser":t}=e,{email:n}=await at({onReady:e=>{t?console.info(`Open this URL to log in: ${e}`):(console.info(`Opening browser to complete login...`),console.info(`If the browser doesn't open, visit: ${e}`),Mt(e))}});console.info(`Logged in to Prismic as ${n}`)}),Bi=j({name:`prismic logout`,description:`Log out of Prismic.`},async()=>{if(await nt())console.info(`Logged out of Prismic`);else throw new A(`Logout failed. You can log out manually by deleting the file.`)}),Vi=j({name:`prismic preview add`,description:`
|
|
287
287
|
Add a preview configuration to a Prismic repository.
|
|
288
288
|
|
|
289
289
|
By default, this command reads the repository from prismic.config.json at the
|
|
290
290
|
project root.
|
|
291
|
-
`,positionals:{url:{description:`Preview URL (e.g. https://example.com/api/preview)`,required:!0}},options:{name:{type:`string`,short:`n`,description:`Display name (defaults to hostname)`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T(),name:a}=t,o;try{o=new URL(n)}catch{throw new A(`Invalid URL: ${n}`)}let s=a||o.hostname,c=`${o.protocol}//${o.host}`,l=o.pathname===`/`?void 0:o.pathname,{token:u,host:d}=await U();await ye({name:s,websiteURL:c,resolverPath:l},{repo:i,token:u,host:d}),console.info(`Preview added: ${n}`),console.info("Run `prismic preview set-simulator <url>` to set the slice simulator URL.");try{let e=await(await O()).getSetupInstructions();e&&console.info(`\n${e}`)}catch(e){if(!(e instanceof re||e instanceof gt))throw e}}),
|
|
291
|
+
`,positionals:{url:{description:`Preview URL (e.g. https://example.com/api/preview)`,required:!0}},options:{name:{type:`string`,short:`n`,description:`Display name (defaults to hostname)`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T(),name:a}=t,o;try{o=new URL(n)}catch{throw new A(`Invalid URL: ${n}`)}let s=a||o.hostname,c=`${o.protocol}//${o.host}`,l=o.pathname===`/`?void 0:o.pathname,{token:u,host:d}=await U();await ye({name:s,websiteURL:c,resolverPath:l},{repo:i,token:u,host:d}),console.info(`Preview added: ${n}`),console.info("Run `prismic preview set-simulator <url>` to set the slice simulator URL.");try{let e=await(await O()).getSetupInstructions();e&&console.info(`\n${e}`)}catch(e){if(!(e instanceof re||e instanceof gt))throw e}}),Hi=j({name:`prismic preview list`,description:`
|
|
292
292
|
List all preview configurations in a Prismic repository.
|
|
293
293
|
|
|
294
294
|
By default, this command reads the repository from prismic.config.json at the
|
|
295
295
|
project root.
|
|
296
|
-
`,options:{json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:t})=>{let{env:n,repo:r=n??await T(),json:i}=t,{token:a,host:o}=await U(),[s,c]=await Promise.all([_({repo:r,token:a,host:o}),e({repo:r,token:a,host:o})]);if(i){console.info(R({previews:s,simulatorUrl:c??null}));return}if(s.length===0&&!c){console.info(`No preview configurations found.`);return}if(s.length>0){let e=s.map(e=>[e.url,e.label]);console.info(k(e,{headers:[`URL`,`NAME`]}))}c&&(s.length>0&&console.info(``),console.info(`Simulator: ${c}`))}),
|
|
296
|
+
`,options:{json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:t})=>{let{env:n,repo:r=n??await T(),json:i}=t,{token:a,host:o}=await U(),[s,c]=await Promise.all([_({repo:r,token:a,host:o}),e({repo:r,token:a,host:o})]);if(i){console.info(R({previews:s,simulatorUrl:c??null}));return}if(s.length===0&&!c){console.info(`No preview configurations found.`);return}if(s.length>0){let e=s.map(e=>[e.url,e.label]);console.info(k(e,{headers:[`URL`,`NAME`]}))}c&&(s.length>0&&console.info(``),console.info(`Simulator: ${c}`))}),Ui=j({name:`prismic preview remove`,description:`
|
|
297
297
|
Remove a preview configuration from a Prismic repository.
|
|
298
298
|
|
|
299
299
|
By default, this command reads the repository from prismic.config.json at the
|
|
300
300
|
project root.
|
|
301
|
-
`,positionals:{url:{description:`Preview URL to remove`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await _({repo:i,token:a,host:o})).find(e=>e.url===n);if(!s)throw new A(`Preview not found: ${n}`);await oe(s.id,{repo:i,token:a,host:o}),console.info(`Preview removed: ${n}`)}),
|
|
301
|
+
`,positionals:{url:{description:`Preview URL to remove`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await _({repo:i,token:a,host:o})).find(e=>e.url===n);if(!s)throw new A(`Preview not found: ${n}`);await oe(s.id,{repo:i,token:a,host:o}),console.info(`Preview removed: ${n}`)}),Wi=j({name:`prismic preview set-simulator`,description:`
|
|
302
302
|
Set the slice simulator URL for a Prismic repository.
|
|
303
303
|
|
|
304
304
|
If the URL pathname does not end with /slice-simulator, it is appended
|
|
@@ -306,7 +306,7 @@ Start building 🚀`))):(console.info(`
|
|
|
306
306
|
|
|
307
307
|
By default, this command reads the repository from prismic.config.json at the
|
|
308
308
|
project root.
|
|
309
|
-
`,positionals:{url:{description:`Simulator URL (e.g. https://example.com/slice-simulator)`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,a;try{a=new URL(n)}catch{throw new A(`Invalid URL: ${n}`)}a.pathname.endsWith(`/slice-simulator`)||(a.pathname=a.pathname.replace(/\/+$/,``)+`/slice-simulator`);let o=a.toString(),{token:s,host:c}=await U();await Se(o,{repo:i,token:s,host:c}),console.info(`Simulator URL set: ${o}`)}),
|
|
309
|
+
`,positionals:{url:{description:`Simulator URL (e.g. https://example.com/slice-simulator)`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,a;try{a=new URL(n)}catch{throw new A(`Invalid URL: ${n}`)}a.pathname.endsWith(`/slice-simulator`)||(a.pathname=a.pathname.replace(/\/+$/,``)+`/slice-simulator`);let o=a.toString(),{token:s,host:c}=await U();await Se(o,{repo:i,token:s,host:c}),console.info(`Simulator URL set: ${o}`)}),Gi=D({name:`prismic preview`,description:`
|
|
310
310
|
Manage previews in a Prismic repository.
|
|
311
311
|
|
|
312
312
|
Run \`prismic docs view previews\` for details.
|
|
@@ -314,15 +314,15 @@ Start building 🚀`))):(console.info(`
|
|
|
314
314
|
Set up previews after a deploy, using both settings:
|
|
315
315
|
prismic preview add https://example.com/api/preview
|
|
316
316
|
prismic preview set-simulator https://example.com
|
|
317
|
-
`},commands:{add:{handler:
|
|
318
|
-
`)){if(r.length<4)continue;let t=r.slice(3),i=t.indexOf(` -> `);i!==-1&&(t=t.slice(i+4)),n.push(new URL(t,e))}return n}catch{return[]}}var
|
|
317
|
+
`},commands:{add:{handler:Vi,description:`Add a preview URL`},list:{handler:Hi,description:`List preview URLs and the simulator URL`},remove:{handler:Ui,description:`Remove a preview URL`},"set-simulator":{handler:Wi,description:`Set the slice simulator URL`}}});async function Ki(e){try{let{stdout:t}=await ft(`git`,[`rev-parse`,`--show-toplevel`],{nodeOptions:{cwd:Ct(e)},throwOnError:!0}),n=t.trim();return n?Je(wt(await xt(n))):void 0}catch{return}}async function qi(e){try{let{stdout:t}=await ft(`git`,[`status`,`--porcelain`,`--untracked-files=all`],{nodeOptions:{cwd:Ct(e)},throwOnError:!0}),n=[];for(let r of t.split(`
|
|
318
|
+
`)){if(r.length<4)continue;let t=r.slice(3),i=t.indexOf(` -> `);i!==-1&&(t=t.slice(i+4)),n.push(new URL(t,e))}return n}catch{return[]}}var Ji=j({name:`prismic pull`,description:`
|
|
319
319
|
Pull content types and slices from Prismic to local files.
|
|
320
320
|
|
|
321
321
|
Remote models are the source of truth. Local files are created, updated,
|
|
322
322
|
or deleted to match.
|
|
323
323
|
|
|
324
324
|
Run \`prismic docs view cli#pull-models-from-prismic\` for details.
|
|
325
|
-
`,options:{force:{type:`boolean`,short:`f`,description:`Skip the git history check and overwrite local changes`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let t=await O(),{force:n=!1,env:i,repo:a=i??await t.getEnvironment()??await r()}=e,{token:o,host:s}=await U(),c=await y();console.info(`Pulling from repository: ${a}`);let[u,d,f]=await Promise.all([
|
|
325
|
+
`,options:{force:{type:`boolean`,short:`f`,description:`Skip the git history check and overwrite local changes`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let t=await O(),{force:n=!1,env:i,repo:a=i??await t.getEnvironment()??await r()}=e,{token:o,host:s}=await U(),c=await y();console.info(`Pulling from repository: ${a}`);let[u,d,f]=await Promise.all([Ki(c),t.getCustomTypeLibraries(),t.getSliceLibraries()]);if(!n&&u){let e=(await qi(u)).filter(e=>e.pathname.endsWith(`/model.json`)&&f.some(t=>H(t,e))||e.pathname.endsWith(`/index.json`)&&d.some(t=>H(t,e))).map(e=>L(c,e));if(e.length>0)throw new A(`
|
|
326
326
|
Local model files have uncommitted changes. Prismic keeps model history in
|
|
327
327
|
git. Commit model changes before you pull them, so this pull can't discard
|
|
328
328
|
your edits:
|
|
@@ -342,7 +342,7 @@ Start building 🚀`))):(console.info(`
|
|
|
342
342
|
This project isn't in a git repo, so changes can't be tracked. Choose one:
|
|
343
343
|
prismic pull --force Discard local files, adopt remote
|
|
344
344
|
prismic push --force Keep local files, overwrite remote
|
|
345
|
-
`)}let _=await t.writeModels(g);await t.generateTypes(),await Lr([`connectPrismic`],{repo:await r(),token:o,host:s}).catch(()=>{});let b=g.customTypes.insert.length+g.customTypes.update.length,x=g.slices.insert.length+g.slices.update.length,S=g.customTypes.delete.length+g.slices.delete.length;for(let e of _)console.info(e);if(b===0&&x===0&&S===0){console.info(`Already up to date.`);return}console.info(`Inserted ${g.customTypes.insert.length}, updated ${g.customTypes.update.length}, deleted ${g.customTypes.delete.length} types`),console.info(`Inserted ${g.slices.insert.length}, updated ${g.slices.update.length}, deleted ${g.slices.delete.length} slices`)}),
|
|
345
|
+
`)}let _=await t.writeModels(g);await t.generateTypes(),await Lr([`connectPrismic`],{repo:await r(),token:o,host:s}).catch(()=>{});let b=g.customTypes.insert.length+g.customTypes.update.length,x=g.slices.insert.length+g.slices.update.length,S=g.customTypes.delete.length+g.slices.delete.length;for(let e of _)console.info(e);if(b===0&&x===0&&S===0){console.info(`Already up to date.`);return}console.info(`Inserted ${g.customTypes.insert.length}, updated ${g.customTypes.update.length}, deleted ${g.customTypes.delete.length} types`),console.info(`Inserted ${g.slices.insert.length}, updated ${g.slices.update.length}, deleted ${g.slices.delete.length} slices`)}),Yi=j({name:`prismic push`,description:`
|
|
346
346
|
Push local content types and slices to Prismic.
|
|
347
347
|
|
|
348
348
|
Local models are the source of truth. Remote models are created,
|
|
@@ -353,7 +353,7 @@ Start building 🚀`))):(console.info(`
|
|
|
353
353
|
Deleting a remote model needs --force.
|
|
354
354
|
|
|
355
355
|
Run \`prismic docs view cli#push-models-to-prismic\` for details.
|
|
356
|
-
`,options:{force:{type:`boolean`,short:`f`,description:`Skip the git history and deletion checks`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let t=await O(),{force:n=!1,env:i,repo:a=i??await t.getEnvironment()??await r()}=e,{token:o,host:s}=await U(),u=await y();console.info(`Pushing to repository: ${a}`);let[d,f,p]=await Promise.all([
|
|
356
|
+
`,options:{force:{type:`boolean`,short:`f`,description:`Skip the git history and deletion checks`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let t=await O(),{force:n=!1,env:i,repo:a=i??await t.getEnvironment()??await r()}=e,{token:o,host:s}=await U(),u=await y();console.info(`Pushing to repository: ${a}`);let[d,f,p]=await Promise.all([Ki(u),t.getCustomTypeLibraries(),t.getSliceLibraries()]);if(!n&&d){let e=(await qi(d)).filter(e=>e.pathname.endsWith(`/model.json`)&&p.some(t=>H(t,e))||e.pathname.endsWith(`/index.json`)&&f.some(t=>H(t,e))).map(e=>L(u,e));if(e.length>0)throw new A(`
|
|
357
357
|
Local model files have uncommitted changes. Prismic keeps model history in
|
|
358
358
|
git. Commit model changes before you push them:
|
|
359
359
|
|
|
@@ -368,44 +368,44 @@ Start building 🚀`))):(console.info(`
|
|
|
368
368
|
Models that would be deleted:
|
|
369
369
|
${n.join(`
|
|
370
370
|
`)}
|
|
371
|
-
`)}try{await c(g,{repo:a,token:o,host:s})}catch(e){throw await
|
|
372
|
-
Please try again, or manually delete any associated pages at: `+t)}if(a!==0)return new A(`Could not delete type "${e}" because it has ${a} associated ${a===1?`page`:`pages`}. \nDelete any associated pages manually before pushing at: `+t)}return e}function
|
|
371
|
+
`)}try{await c(g,{repo:a,token:o,host:s})}catch(e){throw await Zi(e,g.customTypes.delete,{repo:a,token:o,host:s})}for(let{id:e}of g.slices.delete)await C(e,{repo:a,token:o,host:s}).catch(t=>{let n=t instanceof Error?t.message:String(t);console.warn(`Failed to delete screenshots for slice "${e}"${n?`: ${n}`:`.`}`)});let _=[];g.slices.insert.length>0&&_.push(`createSlice`),g.customTypes.insert.some(e=>e.format===`page`)&&_.push(`createPageType`),_.length>0&&await Lr(_,{repo:await r(),token:o,host:s}).catch(()=>{});let b=g.customTypes.insert.length+g.customTypes.update.length,x=g.slices.insert.length+g.slices.update.length,S=g.customTypes.delete.length+g.slices.delete.length;b===0&&x===0&&S===0?console.info(`Already up to date.`):(console.info(`Pushed ${b} type(s), ${x} slice(s).`),S>0&&console.info(`Deleted ${S} model(s).`))});const Xi=N({hasExistingDocuments:Pe(!0)});async function Zi(e,t,n){if(!(e instanceof z)||!Le(Xi,e.body).success)return e;let{repo:r,host:i}=n;for(let{id:e}of t){let t=Qi({repo:r,host:i,customTypeId:e}),a;try{a=await w(e,n)}catch{return new A(`Could not check whether type "${e}" has associated pages.
|
|
372
|
+
Please try again, or manually delete any associated pages at: `+t)}if(a!==0)return new A(`Could not delete type "${e}" because it has ${a} associated ${a===1?`page`:`pages`}. \nDelete any associated pages manually before pushing at: `+t)}return e}function Qi(e){let{repo:t,host:n,customTypeId:r}=e,i=new URL(`builder/working`,`https://${t}.${n}/`);return i.searchParams.set(`customTypes`,r),i.href}const $i=V(N({domain:M(),name:P(M()),role:P(Fe([M(),Me(M(),M())]))}));async function ea(e){let t=new URL(`repositories`,`https://user-service.${e.host}/`);return B(t,{credentials:{"prismic-auth":e.token},schema:$i,unknownErrorMessage:`Failed to load your repositories`})}var ta=j({name:`prismic repo list`,description:`List all Prismic repositories associated with your account.`,options:{json:{type:`boolean`,description:`Output as JSON`}}},async({values:e})=>{let{json:t}=e,{token:n,host:r}=await U(),i=await ea({token:n,host:r});if(t){console.info(R(i.map(e=>({domain:e.domain,name:e.name??null,role:e.role??null,url:`https://${e.domain}.${r}/`}))));return}if(i.length===0){console.info(`No repositories found.`);return}let a=i.map(e=>{let t=e.name||`(no name)`;return[e.domain,t,na(e.role)]});console.info(k(a,{headers:[`DOMAIN`,`NAME`,`ROLE`]}))});function na(e){return typeof e==`string`?e:e?Object.entries(e).map(([e,t])=>`${t} (${e})`).join(`, `):``}const ra=[`private`,`public`,`open`],ia={name:`prismic repo set-api-access`,description:`
|
|
373
373
|
Set the Content API access level of a Prismic repository.
|
|
374
374
|
|
|
375
375
|
By default, this command reads the repository from prismic.config.json at the
|
|
376
376
|
project root.
|
|
377
377
|
|
|
378
378
|
Run \`prismic docs view repository-settings#configuration\` for details.
|
|
379
|
-
`,positionals:{level:{description:`Access level (${
|
|
379
|
+
`,positionals:{level:{description:`Access level (${ra.join(`, `)})`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository domain`}}};var aa=j(ia,async({positionals:e,values:t})=>{let[n]=e,{repo:i=await r()}=t;if(!ra.includes(n))throw new A(`Invalid access level: ${n}. Must be one of: ${ra.join(`, `)}`);let{token:a,host:o}=await U();await xi(n,{repo:i,token:a,host:o}),console.info(`Repository access set to: ${n}`)}),oa=j({name:`prismic repo set-name`,description:`
|
|
380
380
|
Set the display name of a Prismic repository.
|
|
381
381
|
|
|
382
382
|
By default, this command reads the repository from prismic.config.json at the
|
|
383
383
|
project root.
|
|
384
|
-
`,positionals:{name:{description:`Display name for the repository`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository domain`}}},async({positionals:e,values:t})=>{let[n]=e,{repo:i=await r()}=t,{token:a,host:o}=await U(),s=await
|
|
384
|
+
`,positionals:{name:{description:`Display name for the repository`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository domain`}}},async({positionals:e,values:t})=>{let[n]=e,{repo:i=await r()}=t,{token:a,host:o}=await U(),s=await Ci(n,{repo:i,token:a,host:o});console.info(`Repository name set to: ${s}`)}),sa=j({name:`prismic repo view`,description:`
|
|
385
385
|
View details of a Prismic repository.
|
|
386
386
|
|
|
387
387
|
By default, this command reads the repository from prismic.config.json at the
|
|
388
388
|
project root.
|
|
389
|
-
`,options:{web:{type:`boolean`,short:`w`,description:`Open repository in browser`},json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository domain`}}},async({values:e})=>{let{repo:t=await r(),web:n,json:i}=e,{token:a,host:o}=await U(),s=`https://${t}.${o}/`;if(n){Mt(new URL(s)),console.info(`Opening ${s}`);return}let[c,l]=await Promise.all([Dr({repo:t,token:a,host:o}),
|
|
389
|
+
`,options:{web:{type:`boolean`,short:`w`,description:`Open repository in browser`},json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository domain`}}},async({values:e})=>{let{repo:t=await r(),web:n,json:i}=e,{token:a,host:o}=await U(),s=`https://${t}.${o}/`;if(n){Mt(new URL(s)),console.info(`Opening ${s}`);return}let[c,l]=await Promise.all([Dr({repo:t,token:a,host:o}),bi({repo:t,token:a,host:o}).catch(e=>{if(!At(e))throw e})]);if(i){console.info(R({domain:t,name:c.name??null,url:s,apiAccess:l??null}));return}let u=c.name||`(no name)`;console.info(`Name: ${u}`),console.info(`URL: ${s}`),console.info(`Content API: ${l??`(unavailable)`}`)}),ca=D({name:`prismic repo`,description:`
|
|
390
390
|
Manage Prismic repositories.
|
|
391
391
|
|
|
392
392
|
Run \`prismic docs view repository-settings\` for details.
|
|
393
|
-
`,commands:{create:{handler:
|
|
393
|
+
`,commands:{create:{handler:Di,description:`Create a new repository`},list:{handler:ta,description:`List repositories`},view:{handler:sa,description:`View repository details`},"set-name":{handler:oa,description:`Set repository display name`},"set-api-access":{handler:aa,description:`Set Content API access level`}}}),la=j({name:`prismic slice add-variation`,description:`
|
|
394
394
|
Add a variation to a slice.
|
|
395
395
|
|
|
396
396
|
Run \`prismic docs view slices#slice-variations\` for details.
|
|
397
|
-
`,positionals:{name:{description:`Name of the variation`,required:!0}},options:{to:{type:`string`,required:!0,description:`ID of the slice`},id:{type:`string`,description:`Custom ID for the variation`},screenshot:{type:`string`,short:`s`,description:`Screenshot image file path or URL`}}},async({positionals:e,values:t})=>{let[n]=e,{to:i,id:a=Ce(n),screenshot:o}=t,c=await O(),{model:l}=await c.getSlice(i);if(l.variations.some(e=>e.id===a))throw new A(`Variation "${a}" already exists in slice "${i}".`);let u=``;if(o){let e=await r(),{token:t,host:n}=await U(),i=/^https?:\/\//i.test(o)?new URL(o):wt(o),c=await Ge(i);u=(await s(c,{sliceId:l.id,variationId:a,repo:e,token:t,host:n})).toString()}l.variations.push({id:a,name:n,description:n,docURL:``,imageUrl:u,version:``,primary:{}}),await c.updateSlice(l),await c.generateTypes(),console.info(`Added variation "${n}" (id: "${a}") to slice "${i}"`)}),
|
|
397
|
+
`,positionals:{name:{description:`Name of the variation`,required:!0}},options:{to:{type:`string`,required:!0,description:`ID of the slice`},id:{type:`string`,description:`Custom ID for the variation`},screenshot:{type:`string`,short:`s`,description:`Screenshot image file path or URL`}}},async({positionals:e,values:t})=>{let[n]=e,{to:i,id:a=Ce(n),screenshot:o}=t,c=await O(),{model:l}=await c.getSlice(i);if(l.variations.some(e=>e.id===a))throw new A(`Variation "${a}" already exists in slice "${i}".`);let u=``;if(o){let e=await r(),{token:t,host:n}=await U(),i=/^https?:\/\//i.test(o)?new URL(o):wt(o),c=await Ge(i);u=(await s(c,{sliceId:l.id,variationId:a,repo:e,token:t,host:n})).toString()}l.variations.push({id:a,name:n,description:n,docURL:``,imageUrl:u,version:``,primary:{}}),await c.updateSlice(l),await c.generateTypes(),console.info(`Added variation "${n}" (id: "${a}") to slice "${i}"`)}),ua=j({name:`prismic slice connect`,description:`Connect a slice to a type's slice zone.`,sections:{EXAMPLES:`
|
|
398
398
|
Connect a slice to a type's default slice zone:
|
|
399
399
|
prismic slice connect hero --to blog_post
|
|
400
400
|
|
|
401
401
|
Connect to a named slice zone:
|
|
402
402
|
prismic slice connect hero --to blog_post --slice-zone page_slices
|
|
403
|
-
`},positionals:{id:{description:`ID of the slice`,required:!0}},options:{to:{type:`string`,required:!0,description:`ID of the content type`},"slice-zone":{type:`string`,description:`Slice zone field ID (default: "slices")`}}},async({positionals:e,values:t})=>{let[n]=e,{to:r,"slice-zone":i=`slices`}=t,a=await O(),{model:o}=await a.getSlice(n),{model:s}=await a.getCustomType(r),c=Object.assign({},...Object.values(s.json))[i];if(!c||c.type!==`Slices`)throw new A(`Slice zone "${i}" not found in "${r}".`);if(c.config??={},c.config.choices??={},o.id in c.config.choices)throw new A(`Slice "${o.id}" is already connected to "${r}" in slice zone "${i}".`);c.config.choices[o.id]={type:`SharedSlice`},await a.updateCustomType(s),await a.generateTypes(),console.info(`Connected slice "${n}" to "${r}"`)}),
|
|
403
|
+
`},positionals:{id:{description:`ID of the slice`,required:!0}},options:{to:{type:`string`,required:!0,description:`ID of the content type`},"slice-zone":{type:`string`,description:`Slice zone field ID (default: "slices")`}}},async({positionals:e,values:t})=>{let[n]=e,{to:r,"slice-zone":i=`slices`}=t,a=await O(),{model:o}=await a.getSlice(n),{model:s}=await a.getCustomType(r),c=Object.assign({},...Object.values(s.json))[i];if(!c||c.type!==`Slices`)throw new A(`Slice zone "${i}" not found in "${r}".`);if(c.config??={},c.config.choices??={},o.id in c.config.choices)throw new A(`Slice "${o.id}" is already connected to "${r}" in slice zone "${i}".`);c.config.choices[o.id]={type:`SharedSlice`},await a.updateCustomType(s),await a.generateTypes(),console.info(`Connected slice "${n}" to "${r}"`)}),da=j({name:`prismic slice create`,description:`Create a new slice.`,positionals:{name:{description:`Name of the slice`,required:!0}},options:{id:{type:`string`,description:`Custom ID for the slice`}}},async({positionals:e,values:t})=>{let[n]=e,{id:r=ve(n)}=t,i={id:r,name:n,type:`SharedSlice`,variations:[{id:`default`,name:`Default`,description:`Default`,docURL:``,imageUrl:``,version:``,primary:{}}]},a=await O();await a.createSlice(i),await a.generateTypes(),console.info(`Created slice "${n}" (id: "${r}")`),console.info(`Run \`prismic field add <type> --to-slice ${r}\` to add fields.`),console.info(`Run \`prismic slice connect ${r} --to <type>\` to connect the slice to a type.`)}),fa=j({name:`prismic slice disconnect`,description:`Disconnect a slice from a type's slice zone.`,positionals:{id:{description:`ID of the slice`,required:!0}},options:{from:{type:`string`,required:!0,description:`ID of the content type`},"slice-zone":{type:`string`,description:`Slice zone field ID (default: "slices")`}}},async({positionals:e,values:t})=>{let[n]=e,{from:r,"slice-zone":i=`slices`}=t,a=await O(),{model:o}=await a.getSlice(n),{model:s}=await a.getCustomType(r),c=Object.assign({},...Object.values(s.json))[i];if(!c||c.type!==`Slices`)throw new A(`Slice zone "${i}" not found in "${r}".`);if(!c.config?.choices||!(o.id in c.config.choices))throw new A(`Slice "${o.id}" is not connected to "${r}" in slice zone "${i}".`);delete c.config.choices[o.id],await a.updateCustomType(s),await a.generateTypes(),console.info(`Disconnected slice "${n}" from "${r}"`)}),pa=j({name:`prismic slice edit`,description:`Edit a slice.`,positionals:{id:{description:`ID of the slice`,required:!0}},options:{name:{type:`string`,short:`n`,description:`New name for the slice`}}},async({positionals:e,values:t})=>{let[n]=e,r=await O(),{model:i}=await r.getSlice(n);`name`in t&&(i.name=t.name),await r.updateSlice(i),await r.generateTypes(),console.info(`Slice updated: "${i.name}" (id: ${i.id})`)}),ma=j({name:`prismic slice edit-variation`,description:`Edit a variation of a slice.`,positionals:{id:{description:`ID of the variation`,required:!0}},options:{"from-slice":{type:`string`,required:!0,description:`ID of the slice`},name:{type:`string`,short:`n`,description:`New name for the variation`},screenshot:{type:`string`,short:`s`,description:`Screenshot image file path or URL`}}},async({positionals:e,values:t})=>{let[n]=e,{"from-slice":i,screenshot:a}=t,o=await O(),{model:c}=await o.getSlice(i),l=c.variations.find(e=>e.id===n);if(!l)throw new A(`Variation "${n}" not found in slice "${i}".`);if(`name`in t&&(l.name=t.name),a){let e=await r(),{token:t,host:n}=await U(),i=/^https?:\/\//i.test(a)?new URL(a):wt(a),o=await Ge(i);l.imageUrl=(await s(o,{sliceId:c.id,variationId:l.id,repo:e,token:t,host:n})).toString()}await o.updateSlice(c),await o.generateTypes(),console.info(`Variation updated: "${n}" in slice "${i}"`)}),ha=j({name:`prismic slice list`,description:`
|
|
404
404
|
List all slices.
|
|
405
405
|
|
|
406
406
|
Legacy slices from the Legacy Builder are marked with * and show the type
|
|
407
407
|
that defines them.
|
|
408
|
-
`,options:{legacy:{type:`boolean`,description:`List only legacy slices`},json:{type:`boolean`,description:`Output as JSON`}}},async({values:e})=>{let{legacy:t,json:n}=e,r=await O(),i=t?[]:(await r.getSlices()).map(e=>e.model),a=(await r.getCustomTypes()).map(e=>e.model),o=f(a);if(n&&t){let e=o.map(e=>({id:e.id,definedIn:e.customTypeId,sliceZone:e.sliceZoneId}));console.info(R(e));return}if(n){console.info(R(i));return}if(i.length===0&&o.length===0){console.info(t?`No legacy slices found.`:`No slices found.`);return}let s=[...i.map(e=>[e.name,e.id,``]),...o.map(({id:e,model:t,customTypeId:n,sliceZoneId:r})=>[`${(`fieldset`in t?t.fieldset:t.config?.label)||e} *`,e,r===`body`?n:`${n} (${r} slice zone)`])];console.info(k(s,{headers:[`NAME`,`ID`,`DEFINED IN`]})),o.length>0&&console.info("\n* Legacy slice. Run `prismic slice upgrade-legacy --help` to upgrade it.")}),
|
|
408
|
+
`,options:{legacy:{type:`boolean`,description:`List only legacy slices`},json:{type:`boolean`,description:`Output as JSON`}}},async({values:e})=>{let{legacy:t,json:n}=e,r=await O(),i=t?[]:(await r.getSlices()).map(e=>e.model),a=(await r.getCustomTypes()).map(e=>e.model),o=f(a);if(n&&t){let e=o.map(e=>({id:e.id,definedIn:e.customTypeId,sliceZone:e.sliceZoneId}));console.info(R(e));return}if(n){console.info(R(i));return}if(i.length===0&&o.length===0){console.info(t?`No legacy slices found.`:`No slices found.`);return}let s=[...i.map(e=>[e.name,e.id,``]),...o.map(({id:e,model:t,customTypeId:n,sliceZoneId:r})=>[`${(`fieldset`in t?t.fieldset:t.config?.label)||e} *`,e,r===`body`?n:`${n} (${r} slice zone)`])];console.info(k(s,{headers:[`NAME`,`ID`,`DEFINED IN`]})),o.length>0&&console.info("\n* Legacy slice. Run `prismic slice upgrade-legacy --help` to upgrade it.")}),ga=j({name:`prismic slice remove`,description:`Remove a slice.`,positionals:{id:{description:`ID of the slice`,required:!0}}},async({positionals:e})=>{let[t]=e,n=await O();await n.deleteSlice(t),await n.generateTypes(),console.info(`Slice removed: ${t}`)}),_a=j({name:`prismic slice remove-variation`,description:`Remove a variation from a slice.`,positionals:{id:{description:`ID of the variation`,required:!0}},options:{from:{type:`string`,required:!0,description:`ID of the slice`}}},async({positionals:e,values:t})=>{let[n]=e,{from:r}=t,i=await O(),{model:a}=await i.getSlice(r),o=a.variations.find(e=>e.id===n);if(!o)throw new A(`Variation "${n}" not found in slice "${r}".`);a.variations=a.variations.filter(e=>e.id!==o.id),await i.updateSlice(a),await i.generateTypes(),console.info(`Removed variation "${n}" from slice "${r}"`)}),va=j({name:`prismic slice upgrade-legacy`,description:`
|
|
409
409
|
Upgrade a legacy slice from the Legacy Builder.
|
|
410
410
|
|
|
411
411
|
The CLI and the Type Builder cannot edit legacy slices. Run
|
|
@@ -432,47 +432,47 @@ Please try again, or manually delete any associated pages at: `+t)}if(a!==0)retu
|
|
|
432
432
|
|
|
433
433
|
Merge a legacy slice into an existing variation with the same fields:
|
|
434
434
|
prismic slice upgrade-legacy hero --from landing_page --to hero --variation default
|
|
435
|
-
`},positionals:{id:{description:`ID of the legacy slice`,required:!0}},options:{from:{type:`string`,required:!0,description:`ID of the type that contains the legacy slice`},"slice-zone":{type:`string`,description:`Slice zone field ID (default: "body")`},to:{type:`string`,description:`ID of the slice to upgrade to, created if missing (default: the legacy slice ID)`},variation:{type:`string`,description:`Variation to create, or to merge into if it has the same fields (default: "default" for a new slice, the legacy slice ID otherwise)`}}},async({positionals:e,values:t})=>{let[n]=e,{from:r,"slice-zone":i=`body`,to:a,variation:o}=t,s=await O(),c=(await s.getCustomTypes()).map(e=>e.model),l=(await s.getSlices()).map(e=>e.model),u=f(c),d=c.find(e=>e.id===r);if(!d)throw new A(`Type "${r}" not found.`);let p=u.find(e=>e.customTypeId===r&&e.sliceZoneId===i&&e.id===n);if(!p)throw new A(`Legacy slice "${n}" not found in the "${i}" slice zone of "${r}". Use --slice-zone to choose the slice zone.`);let m=`${r}::${i}::${n}`,h=a??ve(n),g=p.sliceZone.config?.choices?.[h];if(h!==n&&g&&g.type!==`SharedSlice`)throw new A(`The "${i}" slice zone of "${r}" also has legacy slice "${h}". Upgrade it first.`);let _=l.find(e=>e.id===h),v=Ce(o??(_?n:`default`)),b=
|
|
436
|
-
`)}function
|
|
435
|
+
`},positionals:{id:{description:`ID of the legacy slice`,required:!0}},options:{from:{type:`string`,required:!0,description:`ID of the type that contains the legacy slice`},"slice-zone":{type:`string`,description:`Slice zone field ID (default: "body")`},to:{type:`string`,description:`ID of the slice to upgrade to, created if missing (default: the legacy slice ID)`},variation:{type:`string`,description:`Variation to create, or to merge into if it has the same fields (default: "default" for a new slice, the legacy slice ID otherwise)`}}},async({positionals:e,values:t})=>{let[n]=e,{from:r,"slice-zone":i=`body`,to:a,variation:o}=t,s=await O(),c=(await s.getCustomTypes()).map(e=>e.model),l=(await s.getSlices()).map(e=>e.model),u=f(c),d=c.find(e=>e.id===r);if(!d)throw new A(`Type "${r}" not found.`);let p=u.find(e=>e.customTypeId===r&&e.sliceZoneId===i&&e.id===n);if(!p)throw new A(`Legacy slice "${n}" not found in the "${i}" slice zone of "${r}". Use --slice-zone to choose the slice zone.`);let m=`${r}::${i}::${n}`,h=a??ve(n),g=p.sliceZone.config?.choices?.[h];if(h!==n&&g&&g.type!==`SharedSlice`)throw new A(`The "${i}" slice zone of "${r}" also has legacy slice "${h}". Upgrade it first.`);let _=l.find(e=>e.id===h),v=Ce(o??(_?n:`default`)),b=xa(p,v),x;if(_){if(!a)throw new A(ya(_,p,b));let e=_.variations.find(e=>e.id===v);if(e&&!Sa(e,b))throw new A(`Variation "${v}" of slice "${h}" has different fields than legacy slice "${n}". Use another ID with --variation.`);e?x=`Merged legacy slice "${n}" into variation "${v}" of slice "${h}"`:(_.variations.push(b),x=`Added legacy slice "${n}" to slice "${h}" as variation "${v}"`),_.legacyPaths={..._.legacyPaths,[m]:v},await s.updateSlice(_)}else{let{model:e}=p,t=`fieldset`in e?e.fieldset:void 0;_={id:h,type:`SharedSlice`,name:se(a??t??h),legacyPaths:{[m]:v},variations:[b]},x=`Upgraded legacy slice "${n}" to slice "${h}"`,await s.createSlice(_)}Ca(p,_.id),await s.updateCustomType(d),await s.generateTypes();let{directory:S}=await s.getSlice(_.id),C=L(await y(),S),w=u.length-1;console.info(x),console.info(`After \`prismic push\`: ${ba(p,h,v)}`),console.info(`Update the component in ${C}, then deploy it with \`prismic push\`. Documents use the new shape after the next publish.`),w>0&&console.info(`\n${w} legacy ${w===1?`slice remains`:`slices remain`}. Run \`prismic slice list --legacy\` to list them.`)});function ya(e,t,n){let{id:r,customTypeId:i,sliceZoneId:a}=t,o=`prismic slice upgrade-legacy ${r} --from ${i}${a===`body`?``:` --slice-zone ${a}`}`,s=e.variations.find(e=>Sa(e,n));return[`Slice "${e.id}" already exists. How do you want to upgrade legacy slice "${r}" of "${i}"? This changes how editors pick slices, so the project's owner should choose:`,` Add it to slice "${e.id}" as a new variation: ${o} --to ${e.id}`,...s?[` Merge it into variation "${s.id}", which has the same fields: ${o} --to ${e.id} --variation ${s.id}`]:[],` Upgrade it to a separate slice: ${o} --to <new-slice-id>`].join(`
|
|
436
|
+
`)}function ba(e,t,n){let{model:r,id:i}=e,a=[];return(t!==i||n!=="default")&&a.push(`\`slice_type\` becomes "${t}" and \`variation\` becomes "${n}".`),r.type===`Group`?a.push("`slice.value` moves to `slice.items`."):r.type!==`Slice`&&a.push(`\`slice.value\` moves to \`slice.primary.${i}\`.`),a.join(` `)||"`slice.primary` and `slice.items` keep their shape."}function xa(e,t){let{model:n}=e,r=t==="default"?`Default`:se(t),i={id:t,name:r,description:r,docURL:``,imageUrl:``,version:`initial`,primary:{},items:{}};switch(n.type){case`Slice`:i.primary=n[`non-repeat`]??{},i.items=n.repeat??{};break;case`Group`:i.items=n.config?.fields??{};break;default:i.primary={[e.id]:n}}return i}function Sa(e,t){return yt(e.primary??{},t.primary??{})&&yt(e.items??{},t.items??{})}function Ca({id:e,sliceZone:t},n){t.config.choices=Object.fromEntries(Object.entries(t.config.choices).filter(([t])=>t===e||t!==n).map(([t,r])=>t===e?[n,{type:`SharedSlice`}]:[t,r]))}var wa=j({name:`prismic slice view`,description:`View details of a slice.`,positionals:{id:{description:`ID of the slice`,required:!0}},options:{json:{type:`boolean`,description:`Output as JSON`}}},async({positionals:e,values:t})=>{let[n]=e,{json:r}=t,{model:i}=await(await O()).getSlice(n);if(r){console.info(R(i));return}console.info(`ID: ${i.id}`),console.info(`Name: ${i.name}`);for(let e of i.variations??[])console.info(``),console.info(`${e.id}:`),console.info(An(e.primary??{}))}),Ta=D({name:`prismic slice`,description:`
|
|
437
437
|
Manage slices.
|
|
438
438
|
|
|
439
439
|
Run \`prismic docs view slices\` for details.
|
|
440
|
-
`,commands:{create:{handler:
|
|
440
|
+
`,commands:{create:{handler:da,description:`Create a new slice`},edit:{handler:pa,description:`Edit a slice`},remove:{handler:ga,description:`Remove a slice`},list:{handler:ha,description:`List slices`},view:{handler:wa,description:`View a slice`},connect:{handler:ua,description:`Connect a slice to a type's slice zone`},disconnect:{handler:fa,description:`Disconnect a slice from a type's slice zone`},"upgrade-legacy":{handler:va,description:`Upgrade a legacy slice`},"add-variation":{handler:la,description:`Add a variation to a slice`},"edit-variation":{handler:ma,description:`Edit a variation of a slice`},"remove-variation":{handler:_a,description:`Remove a variation from a slice`}}}),Ea=j({name:`prismic status`,description:`
|
|
441
441
|
Show local vs remote model differences.
|
|
442
442
|
|
|
443
443
|
Reports what would be pushed to or pulled from Prismic, plus any local
|
|
444
444
|
model files with uncommitted git changes that must be committed before
|
|
445
445
|
pull and push.
|
|
446
|
-
`,options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let t=await O(),n=await r(),i=await t.getEnvironment(),{env:a,repo:o=a??i??n}=e,{token:s,host:c}=await U(),u=await y(),[p,m,h,g]=await Promise.all([
|
|
446
|
+
`,options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let t=await O(),n=await r(),i=await t.getEnvironment(),{env:a,repo:o=a??i??n}=e,{token:s,host:c}=await U(),u=await y(),[p,m,h,g]=await Promise.all([Ki(u),t.getCustomTypeLibraries(),t.getSliceLibraries(),t.getModels()]),_,b;if(s){let[e,t]=await Promise.all([tt(s,{host:c}),v({repo:o,token:s,host:c})]);_=e.type===`USER`?e.email:`${e.appName} (Write API token for ${e.domain})`,b=l(g,t)}let x=[];p&&(x=(await qi(p)).filter(e=>e.pathname.endsWith(`/model.json`)&&h.some(t=>H(t,e))||e.pathname.endsWith(`/index.json`)&&m.some(t=>H(t,e))).map(e=>L(u,e))),console.info(`Repository: ${n}`),o!==n&&console.info(`Environment: ${o}`),console.info(_?`Authenticated as: ${_}`:"Not logged in — log in with `prismic login` to compare with remote.");let S=f(g.customTypes).length;S>0&&console.info(`\n${S} legacy ${S===1?`slice needs`:`slices need`} upgrading. Run \`prismic slice list --legacy\`.`);let C=b!==void 0&&!d(b.customTypes)&&!d(b.slices);if(C&&x.length===0){console.info(``),console.info(`Already up to date.`);return}if(b){let e=[],t=[...b.customTypes.insert.map(e=>` ${e.id} (custom type)`),...b.slices.insert.map(e=>` ${e.id} (slice)`)];t.length>0&&e.push([`Local-only:`,...t]);let n=[...b.customTypes.delete.map(e=>` ${e.id} (custom type)`),...b.slices.delete.map(e=>` ${e.id} (slice)`)];n.length>0&&e.push([`Remote-only:`,...n]);let r=[...b.customTypes.update.map(e=>` ${e.id} (custom type)`),...b.slices.update.map(e=>` ${e.id} (slice)`)];r.length>0&&e.push([`Differ:`,...r]);for(let t of e){console.info(``);for(let e of t)console.info(e)}}let w=[];if(x.length>0&&(console.info(``),console.info(`Prismic keeps model history in git. Commit model changes before you push or pull them.`),w.push(`git add ${x.join(` `)}`),w.push(`git commit -m "Update Prismic models"`)),b&&!C){let e=b.customTypes.insert.length+b.slices.insert.length,t=b.customTypes.update.length+b.slices.update.length,n=b.customTypes.delete.length+b.slices.delete.length;w.push(`prismic push # creates ${e}, updates ${t}, deletes ${n}`),w.push(`prismic pull # creates ${n}, updates ${t}, deletes ${e}`)}if(w.length>0){console.info(``),console.info(`Next:`);for(let e of w)console.info(` ${e}`)}});const Da=W.PRISMIC_SYNC_POLL_MS??5e3;var Oa=j({name:`prismic sync`,description:`
|
|
447
447
|
Watch Prismic and continuously pull changes to local files.
|
|
448
448
|
|
|
449
449
|
For one-time pulls, use \`prismic pull\`.
|
|
450
450
|
`,options:{watch:{type:`boolean`,short:`w`,description:`Watch for changes and sync continuously`,required:!0},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let t=await O(),{env:n,repo:i=n??await t.getEnvironment()??await r()}=e,{token:a,host:o}=await U();$e(`sync`,{watch:!0}),process.on(`SIGINT`,()=>{console.info(`
|
|
451
|
-
Watch stopped. Goodbye!`),Qe(`sync`,{watch:!0}),process.exit(0)}),console.info(`Watching repository: ${i} (polling every ${
|
|
451
|
+
Watch stopped. Goodbye!`),Qe(`sync`,{watch:!0}),process.exit(0)}),console.info(`Watching repository: ${i} (polling every ${Da/1e3}s, Ctrl+C to stop)`);let s,c=0;for(;;){try{let e=await v({repo:i,token:a,host:o}),n=s&&l(e,s);if(!n||d(n.customTypes)||d(n.slices)){let i=!n,c=l(e,await t.getModels(),{treatNonCanonicalAsChanged:!0});for(let e of await t.writeModels(c))console.info(e);let u=[...d(c.slices)?[`slices`]:[],...d(c.customTypes)?[`custom types`]:[]];if((i||u.length>0)&&await t.generateTypes(),s=e,i)await Lr([`connectPrismic`],{repo:await r(),token:a,host:o}).catch(()=>{}),console.info(`Initial sync complete.`);else if(u.length>0){let e=(/* @__PURE__ */ new Date()).toLocaleTimeString();console.info(`[${e}] Changes detected in ${u.join(` and `)}`)}}c=0}catch(e){c++;let t=await jt(e)??`Unknown error`;if(console.error(`Error checking for changes: ${t}`),c>=5)throw new A(`Too many consecutive errors (5), stopping watch.`)}await Ot(Da)}});const ka=`0123456789abcdefghjkmnpqrstvwxyz`,Aa=RegExp(`^pt_[${ka}]{16}$`);function ja(){let e=`pt_`;for(let t of Et(16))e+=ka[t&31];return e}function Ma(e){return Aa.test(e)}var Na=j({name:`prismic task-id`,description:`
|
|
452
452
|
Print a task ID for --task-id.
|
|
453
453
|
|
|
454
454
|
One ID covers one user request: pass it on every command for that request,
|
|
455
455
|
and run this again when the user asks for something else.
|
|
456
|
-
`},async()=>{console.info(
|
|
456
|
+
`},async()=>{console.info(ja())});const Pa=`Prismic CLI`;var Fa=j({name:`prismic token create`,description:`
|
|
457
457
|
Create a new API token for a Prismic repository.
|
|
458
458
|
|
|
459
459
|
By default, this command reads the repository from prismic.config.json at the
|
|
460
460
|
project root.
|
|
461
|
-
`,options:{write:{type:`boolean`,description:`Create a write token`},"allow-releases":{type:`boolean`,description:`Allow access to releases (read tokens only)`},name:{type:`string`,short:`n`,description:`Name to identify the token (default: "${
|
|
461
|
+
`,options:{write:{type:`boolean`,description:`Create a write token`},"allow-releases":{type:`boolean`,description:`Allow access to releases (read tokens only)`},name:{type:`string`,short:`n`,description:`Name to identify the token (default: "${Pa}")`},json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let{env:t,repo:n=t??await T(),write:r,"allow-releases":i,name:a=Pa,json:o}=e;if(r&&i)throw new A(`--allow-releases is only valid for access tokens (not with --write)`);let{token:s,host:c}=await U(),l,u;if(r)l=(await hi(a,{repo:n,token:s,host:c})).token;else{u=i?`master+releases`:`master`;let e=(await ui({repo:n,token:s,host:c})).find(e=>e.name===a);e||=await di(a,{repo:n,token:s,host:c}),l=(await fi(e.id,u,{repo:n,token:s,host:c})).token}if(o){console.info(R({token:l,type:r?`write`:`access`,name:a,repository:n,...u?{scope:u}:{}}));return}console.info(`Token created: ${l}`)}),Ia=j({name:`prismic token delete`,description:`
|
|
462
462
|
Delete a token from a Prismic repository.
|
|
463
463
|
|
|
464
464
|
By default, this command reads the repository from prismic.config.json at the
|
|
465
465
|
project root.
|
|
466
|
-
`,positionals:{token:{description:`Token value`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),[s,c]=await Promise.all([
|
|
466
|
+
`,positionals:{token:{description:`Token value`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),[s,c]=await Promise.all([ui({repo:i,token:a,host:o}),mi({repo:i,token:a,host:o})]),l=s.flatMap(e=>e.wroom_auths).find(e=>e.token===n);if(l){await pi(l.id,{repo:i,token:a,host:o}),console.info(`Token deleted`);return}let u=c.tokens.find(e=>e.token===n);if(u){await gi(u.token,{repo:i,token:a,host:o}),console.info(`Token deleted`);return}throw new A(`Token not found: ${n}`)}),La=j({name:`prismic token list`,description:`
|
|
467
467
|
List all API tokens for a Prismic repository.
|
|
468
468
|
|
|
469
469
|
By default, this command reads the repository from prismic.config.json at the
|
|
470
470
|
project root.
|
|
471
|
-
`,options:{json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let{env:t,repo:n=t??await T(),json:r}=e,{token:i,host:a}=await U(),[o,s]=await Promise.all([
|
|
471
|
+
`,options:{json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let{env:t,repo:n=t??await T(),json:r}=e,{token:i,host:a}=await U(),[o,s]=await Promise.all([ui({repo:n,token:i,host:a}),mi({repo:n,token:i,host:a})]),c=o.flatMap(e=>e.wroom_auths.map(t=>({name:e.name,scope:t.scope,token:t.token,createdAt:new Date(t.created_at.$date).toISOString().split(`T`)[0]}))),l=s.tokens;if(r){console.info(R({accessTokens:c,writeTokens:l}));return}if(c.length>0){console.info(`ACCESS TOKENS`);let e=c.map(e=>[` ${e.name}`,e.scope,e.token,e.createdAt]);console.info(k(e))}else console.info(`ACCESS TOKENS (none)`);if(console.info(``),l.length>0){console.info(`WRITE TOKENS`);let e=l.map(e=>{let t=(/* @__PURE__ */ new Date(e.timestamp*1e3)).toISOString().split(`T`)[0];return[` ${e.app_name}`,e.token,t]});console.info(k(e))}else console.info(`WRITE TOKENS (none)`)}),Ra=D({name:`prismic token`,description:`
|
|
472
472
|
Manage API tokens for a Prismic repository.
|
|
473
473
|
|
|
474
474
|
Run \`prismic docs view repository-settings#configuration\` for details.
|
|
475
|
-
`,commands:{list:{handler:
|
|
475
|
+
`,commands:{list:{handler:La,description:`List all tokens`},create:{handler:Fa,description:`Create a new token`},delete:{handler:Ia,description:`Delete a token`}}}),za=j({name:`prismic type add-tab`,description:`Add a tab to a content type.`,positionals:{name:{description:`Name of the tab`,required:!0}},options:{to:{type:`string`,required:!0,description:`ID of the content type`},"with-slice-zone":{type:`boolean`,description:`Add a slice zone to the tab`}}},async({positionals:e,values:t})=>{let[n]=e,{to:r,"with-slice-zone":i}=t,a=await O(),{model:o}=await a.getCustomType(r);if(n in o.json)throw new A(`Tab "${n}" already exists in "${r}".`);o.json[n]=i?{slices:{type:`Slices`,fieldset:`Slice Zone`,config:{choices:{}}}}:{},await a.updateCustomType(o),await a.generateTypes(),console.info(`Added tab "${n}" to "${r}"`)}),Ba=j({name:`prismic type create`,description:`Create a new content type.`,positionals:{name:{description:`Name of the content type`,required:!0}},options:{format:{type:`string`,short:`f`,description:`Type format: "custom" (default) or "page"`},single:{type:`boolean`,short:`s`,description:`Allow only one document of this type`},id:{type:`string`,description:`Custom ID for the content type`}},sections:{FORMATS:`
|
|
476
476
|
custom A non-page type (e.g. settings, navigation, author, blog
|
|
477
477
|
category). This is the default.
|
|
478
478
|
page A page type with a URL (e.g. homepage, blog post, landing
|
|
@@ -487,11 +487,11 @@ Watch stopped. Goodbye!`),Qe(`sync`,{watch:!0}),process.exit(0)}),console.info(`
|
|
|
487
487
|
|
|
488
488
|
Create with a custom ID:
|
|
489
489
|
prismic type create "Landing Page" --format page --id landing
|
|
490
|
-
`}},async({positionals:e,values:t})=>{let[n]=e,{format:r=`custom`,single:i=!1,id:a=ve(n)}=t;if(r!==`custom`&&r!==`page`)throw new A(`Invalid format: "${r}". Use "custom" or "page".`);let o=await O();if((await o.getCustomTypes()).some(({model:e})=>e.id===a))throw new A(`Type "${a}" already exists. Run \`prismic type edit ${a}\` to change it.`);let s=r===`page`?{Main:{slices:{type:`Slices`,fieldset:`Slice Zone`,config:{choices:{}}}},"SEO & Metadata":{meta_title:{type:`Text`,config:{label:`Meta Title`,placeholder:`A title of the page used for social media and search engines`}},meta_description:{type:`Text`,config:{label:`Meta Description`,placeholder:`A brief summary of the page`}},meta_image:{type:`Image`,config:{label:`Meta Image`,constraint:{width:2400,height:1260},thumbnails:[]}}}}:{Main:{}};i||(s.Main={uid:{type:`UID`,config:{label:`UID`}},...s.Main});let c={id:a,label:n,repeatable:!i,status:!0,format:r,json:s},l=await o.createCustomType(c);await o.generateTypes(),console.info(`Created type "${n}" (id: "${a}", format: "${r}")`);for(let e of l)console.info(e);console.info(`Run \`prismic field add <type> --to-type ${a}\` to add fields.`),console.info(`Run \`prismic type view ${a}\` to view the type.`)}),
|
|
490
|
+
`}},async({positionals:e,values:t})=>{let[n]=e,{format:r=`custom`,single:i=!1,id:a=ve(n)}=t;if(r!==`custom`&&r!==`page`)throw new A(`Invalid format: "${r}". Use "custom" or "page".`);let o=await O();if((await o.getCustomTypes()).some(({model:e})=>e.id===a))throw new A(`Type "${a}" already exists. Run \`prismic type edit ${a}\` to change it.`);let s=r===`page`?{Main:{slices:{type:`Slices`,fieldset:`Slice Zone`,config:{choices:{}}}},"SEO & Metadata":{meta_title:{type:`Text`,config:{label:`Meta Title`,placeholder:`A title of the page used for social media and search engines`}},meta_description:{type:`Text`,config:{label:`Meta Description`,placeholder:`A brief summary of the page`}},meta_image:{type:`Image`,config:{label:`Meta Image`,constraint:{width:2400,height:1260},thumbnails:[]}}}}:{Main:{}};i||(s.Main={uid:{type:`UID`,config:{label:`UID`}},...s.Main});let c={id:a,label:n,repeatable:!i,status:!0,format:r,json:s},l=await o.createCustomType(c);await o.generateTypes(),console.info(`Created type "${n}" (id: "${a}", format: "${r}")`);for(let e of l)console.info(e);console.info(`Run \`prismic field add <type> --to-type ${a}\` to add fields.`),console.info(`Run \`prismic type view ${a}\` to view the type.`)}),Va=j({name:`prismic type edit`,description:`Edit a content type.`,positionals:{id:{description:`ID of the content type`,required:!0}},options:{name:{type:`string`,short:`n`,description:`New name for the type`},format:{type:`string`,short:`f`,description:`Type format: "custom" or "page"`}}},async({positionals:e,values:t})=>{let[n]=e;if(`format`in t&&t.format!==`custom`&&t.format!==`page`)throw new A(`Invalid format: "${t.format}". Use "custom" or "page".`);let r=await O(),{model:i}=await r.getCustomType(n);`name`in t&&(i.label=t.name),`format`in t&&(i.format=t.format),await r.updateCustomType(i),await r.generateTypes(),console.info(`Type updated: "${i.label}" (id: ${i.id})`)}),Ha=j({name:`prismic type edit-tab`,description:`Edit a tab of a content type.`,positionals:{name:{description:`Current name of the tab`,required:!0}},options:{"from-type":{type:`string`,required:!0,description:`ID of the content type`},name:{type:`string`,short:`n`,description:`New name for the tab`},"with-slice-zone":{type:`boolean`,description:`Add a slice zone to the tab`},"without-slice-zone":{type:`boolean`,description:`Remove the slice zone from the tab`}}},async({positionals:e,values:t})=>{let[n]=e,{"from-type":r}=t,i=await O(),{model:a}=await i.getCustomType(r);if(!(n in a.json))throw new A(`Tab "${n}" not found in "${r}".`);if(`with-slice-zone`in t&&`without-slice-zone`in t)throw new A(`Cannot use --with-slice-zone and --without-slice-zone together.`);if(`with-slice-zone`in t){let e=a.json[n];if(Object.values(e).some(e=>e.type===`Slices`))throw new A(`Tab "${n}" already has a slice zone.`);e.slices={type:`Slices`,fieldset:`Slice Zone`,config:{choices:{}}}}if(`without-slice-zone`in t){let e=a.json[n],t=Object.entries(e).find(([,e])=>e.type===`Slices`);if(!t)throw new A(`Tab "${n}" does not have a slice zone.`);let[r,i]=t,o=i.type===`Slices`?i.config?.choices??{}:{};if(Object.keys(o).length>0)throw new A(`Cannot remove slice zone from "${n}": disconnect all slices first.`);delete e[r]}if(`name`in t){if(t.name in a.json)throw new A(`Tab "${t.name}" already exists in "${r}".`);let e={};for(let[r,i]of Object.entries(a.json))e[r===n?t.name:r]=i;a.json=e}await i.updateCustomType(a),await i.generateTypes(),console.info(`Tab updated: "${n}" in "${r}"`)}),Ua=j({name:`prismic type list`,description:`List all content types.`,options:{json:{type:`boolean`,description:`Output as JSON`}}},async({values:e})=>{let{json:t}=e,n=await(await O()).getCustomTypes();if(t){console.info(R(n.map(e=>e.model)));return}if(n.length===0){console.info(`No types found.`);return}let r=n.map(({model:e})=>[e.label||`(no name)`,e.id,e.format??``]);console.info(k(r,{headers:[`NAME`,`ID`,`FORMAT`]}))}),Wa=j({name:`prismic type remove`,description:`Remove a content type.`,positionals:{id:{description:`ID of the content type`,required:!0}}},async({positionals:e})=>{let[t]=e,n=await O();await n.deleteCustomType(t),await n.generateTypes(),console.info(`Type removed: ${t}`)}),Ga=j({name:`prismic type remove-tab`,description:`Remove a tab from a content type.`,positionals:{name:{description:`Name of the tab`,required:!0}},options:{from:{type:`string`,required:!0,description:`ID of the content type`}}},async({positionals:e,values:t})=>{let[n]=e,{from:r}=t,i=await O(),{model:a}=await i.getCustomType(r);if(!(n in a.json))throw new A(`Tab "${n}" not found in "${r}".`);if(Object.keys(a.json).length<=1)throw new A(`Cannot remove the last tab from "${r}".`);delete a.json[n],await i.updateCustomType(a),await i.generateTypes(),console.info(`Removed tab "${n}" from "${r}"`)}),Ka=j({name:`prismic type view`,description:`View details of a content type.`,positionals:{id:{description:`ID of the content type`,required:!0}},options:{json:{type:`boolean`,description:`Output as JSON`}}},async({positionals:e,values:t})=>{let[n]=e,{json:r}=t,{model:i}=await(await O()).getCustomType(n);if(r){console.info(R(i));return}let a=(await we()).routes?.find(e=>e.type===i.id);console.info(`ID: ${i.id}`),console.info(`Name: ${i.label||`(no name)`}`),console.info(`Format: ${i.format??`custom`}`),console.info(`Repeatable: ${i.repeatable}`),console.info(`Route: ${a?.path??`none`}`);for(let[e,t]of Object.entries(i.json)){console.info(``),console.info(`${e}:`),console.info(An(t));for(let[e,n]of Object.entries(t)){if(n.type!==`Slices`)continue;let t=Object.entries(n.config?.choices??{}).map(([e,t])=>t.type===`SharedSlice`?e:`${e} *`);console.info(`\n ${e} slices: ${t.join(`, `)||`(none)`}`)}}f([i]).length>0&&console.info("\n* Legacy slice. Run `prismic slice upgrade-legacy --help` to upgrade it.")}),qa=D({name:`prismic type`,description:`
|
|
491
491
|
Manage content types.
|
|
492
492
|
|
|
493
493
|
Run \`prismic docs view content-modeling\` for details.
|
|
494
|
-
`,commands:{create:{handler:
|
|
494
|
+
`,commands:{create:{handler:Ba,description:`Create a new content type`},edit:{handler:Va,description:`Edit a content type`},remove:{handler:Wa,description:`Remove a content type`},list:{handler:Ua,description:`List content types`},view:{handler:Ka,description:`View a content type`},"add-tab":{handler:za,description:`Add a tab to a content type`},"edit-tab":{handler:Ha,description:`Edit a tab of a content type`},"remove-tab":{handler:Ga,description:`Remove a tab from a content type`}}}),Ja=j({name:`prismic webhook create`,description:`
|
|
495
495
|
Create a new webhook in a Prismic repository.
|
|
496
496
|
|
|
497
497
|
By default, this command reads the repository from prismic.config.json at the
|
|
@@ -514,27 +514,27 @@ Watch stopped. Goodbye!`),Qe(`sync`,{watch:!0}),process.exit(0)}),console.info(`
|
|
|
514
514
|
|
|
515
515
|
Create a named webhook with a secret:
|
|
516
516
|
prismic webhook create https://example.com/webhook --name "Deploy" --secret my-secret
|
|
517
|
-
`}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T(),name:a,secret:o,trigger:s=[]}=t;for(let e of s)if(
|
|
517
|
+
`}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T(),name:a,secret:o,trigger:s=[]}=t;for(let e of s)if(!$r.includes(e))throw new A(`Invalid trigger: ${e}\nValid triggers: ${$r.join(`, `)}`);let{token:c,host:l}=await U(),u=!(s.length>0);await ni({url:n,name:a??null,secret:o??null,documentsPublished:s.includes(`documentsPublished`)||u,documentsUnpublished:s.includes(`documentsUnpublished`)||u,releasesCreated:s.includes(`releasesCreated`)||u,releasesUpdated:s.includes(`releasesUpdated`)||u,tagsCreated:s.includes(`tagsCreated`)||u,tagsDeleted:s.includes(`tagsDeleted`)||u},{repo:i,token:c,host:l}),console.info(`Webhook created: ${n}`),console.info(`Run \`prismic webhook set-triggers ${n}\` to configure triggers.`)}),Ya=j({name:`prismic webhook disable`,description:`
|
|
518
518
|
Disable a webhook in a Prismic repository.
|
|
519
519
|
|
|
520
520
|
By default, this command reads the repository from prismic.config.json at the
|
|
521
521
|
project root.
|
|
522
|
-
`,positionals:{url:{description:`Webhook URL`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await
|
|
522
|
+
`,positionals:{url:{description:`Webhook URL`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await ti({repo:i,token:a,host:o})).find(e=>e.config.url===n);if(!s)throw new A(`Webhook not found: ${n}`);if(!s.config.active){console.info(`Webhook already disabled: ${n}`);return}let c=s.config._id,l=structuredClone(s.config);l.active=!1,await ri(c,l,{repo:i,token:a,host:o}),console.info(`Webhook disabled: ${n}`)}),Xa=j({name:`prismic webhook enable`,description:`
|
|
523
523
|
Enable a webhook in a Prismic repository.
|
|
524
524
|
|
|
525
525
|
By default, this command reads the repository from prismic.config.json at the
|
|
526
526
|
project root.
|
|
527
|
-
`,positionals:{url:{description:`Webhook URL`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await
|
|
527
|
+
`,positionals:{url:{description:`Webhook URL`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await ti({repo:i,token:a,host:o})).find(e=>e.config.url===n);if(!s)throw new A(`Webhook not found: ${n}`);if(s.config.active){console.info(`Webhook already enabled: ${n}`);return}let c=s.config._id,l=structuredClone(s.config);l.active=!0,await ri(c,l,{repo:i,token:a,host:o}),console.info(`Webhook enabled: ${n}`)}),Za=j({name:`prismic webhook list`,description:`
|
|
528
528
|
List all webhooks in a Prismic repository.
|
|
529
529
|
|
|
530
530
|
By default, this command reads the repository from prismic.config.json at the
|
|
531
531
|
project root.
|
|
532
|
-
`,options:{json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let{env:t,repo:n=t??await T(),json:r}=e,{token:i,host:a}=await U(),o=await
|
|
532
|
+
`,options:{json:{type:`boolean`,description:`Output as JSON`},repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({values:e})=>{let{env:t,repo:n=t??await T(),json:r}=e,{token:i,host:a}=await U(),o=await ti({repo:n,token:i,host:a});if(r){console.info(R(o.map(e=>e.config)));return}if(o.length===0){console.info(`No webhooks configured.`);return}let s=o.map(e=>{let t=e.config.active?`enabled`:`disabled`,n=e.config.name?` (${e.config.name})`:``;return[`${e.config.url}${n}`,`[${t}]`]});console.info(k(s,{headers:[`URL`,`STATUS`]}))}),Qa=j({name:`prismic webhook remove`,description:`
|
|
533
533
|
Delete a webhook from a Prismic repository.
|
|
534
534
|
|
|
535
535
|
By default, this command reads the repository from prismic.config.json at the
|
|
536
536
|
project root.
|
|
537
|
-
`,positionals:{url:{description:`Webhook URL`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await
|
|
537
|
+
`,positionals:{url:{description:`Webhook URL`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await ti({repo:i,token:a,host:o})).find(e=>e.config.url===n);if(!s)throw new A(`Webhook not found: ${n}`);let c=s.config._id;await ii(c,{repo:i,token:a,host:o}),console.info(`Webhook removed: ${n}`)}),$a=j({name:`prismic webhook set-triggers`,description:`
|
|
538
538
|
Update which events trigger a webhook.
|
|
539
539
|
|
|
540
540
|
By default, this command reads the repository from prismic.config.json at the
|
|
@@ -546,16 +546,16 @@ Watch stopped. Goodbye!`),Qe(`sync`,{watch:!0}),process.exit(0)}),console.info(`
|
|
|
546
546
|
releasesUpdated When a release is edited or deleted
|
|
547
547
|
tagsCreated When a tag is created
|
|
548
548
|
tagsDeleted When a tag is deleted
|
|
549
|
-
`}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T(),trigger:a=[]}=t;for(let e of a)if(
|
|
549
|
+
`}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T(),trigger:a=[]}=t;for(let e of a)if(!$r.includes(e))throw new A(`Invalid trigger: ${e}\nValid triggers: ${$r.join(`, `)}`);let{token:o,host:s}=await U(),c=(await ti({repo:i,token:o,host:s})).find(e=>e.config.url===n);if(!c)throw new A(`Webhook not found: ${n}`);let l=c.config._id;await ri(l,{...c.config,documentsPublished:a.includes(`documentsPublished`),documentsUnpublished:a.includes(`documentsUnpublished`),releasesCreated:a.includes(`releasesCreated`),releasesUpdated:a.includes(`releasesUpdated`),tagsCreated:a.includes(`tagsCreated`),tagsDeleted:a.includes(`tagsDeleted`)},{repo:i,token:o,host:s}),console.info(`Webhook triggers updated: ${a.join(`, `)}`)}),eo=j({name:`prismic webhook view`,description:`
|
|
550
550
|
View details of a webhook in a Prismic repository.
|
|
551
551
|
|
|
552
552
|
By default, this command reads the repository from prismic.config.json at the
|
|
553
553
|
project root.
|
|
554
|
-
`,positionals:{url:{description:`Webhook URL`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await
|
|
554
|
+
`,positionals:{url:{description:`Webhook URL`,required:!0}},options:{repo:{type:`string`,short:`r`,description:`Repository or environment domain`},env:{type:`string`,short:`e`,description:`Alias for --repo`,deprecated:"Use `prismic env` or --repo instead."}}},async({positionals:e,values:t})=>{let[n]=e,{env:r,repo:i=r??await T()}=t,{token:a,host:o}=await U(),s=(await ti({repo:i,token:a,host:o})).find(e=>e.config.url===n);if(!s)throw new A(`Webhook not found: ${n}`);let{config:c}=s;console.info(`URL: ${c.url}`),console.info(`Name: ${c.name||`(none)`}`),console.info(`Status: ${c.active?`enabled`:`disabled`}`),console.info(`Secret: ${c.secret?`(set)`:`(none)`}`);let l=[];for(let e of $r)c[e]&&l.push(e);if(console.info(`Triggers: ${l.length>0?l.join(`, `):`(none)`}`),Object.keys(c.headers).length>0){console.info(`Headers:`);for(let[e,t]of Object.entries(c.headers))console.info(` ${e}: ${t}`)}else console.info(`Headers: (none)`)}),to=D({name:`prismic webhook`,description:`
|
|
555
555
|
Manage webhooks in a Prismic repository.
|
|
556
556
|
|
|
557
557
|
Run \`prismic docs view webhooks\` for details.
|
|
558
|
-
`,commands:{list:{handler:
|
|
558
|
+
`,commands:{list:{handler:Za,description:`List all webhooks`},create:{handler:Ja,description:`Create a new webhook`},view:{handler:eo,description:`View webhook details`},remove:{handler:Qa,description:`Delete a webhook`},enable:{handler:Xa,description:`Enable a webhook`},disable:{handler:Ya,description:`Disable a webhook`},"set-triggers":{handler:$a,description:`Update webhook triggers`}}}),no=j({name:`prismic whoami`,description:`Show the currently logged in user.`},async()=>{let{token:e,host:t}=await U(),n=await tt(e,{host:t});if(n.type===`Machine2Machine`){console.info(`${n.appName} (Write API token for ${n.domain})`);return}console.info(n.email)}),ro=D({name:`prismic`,description:`Prismic CLI for managing repositories and configurations.`,sections:{DOCUMENTATION:"\n Run `prismic docs list` to browse available documentation topics.\n Run `prismic docs view <path>` to read a topic.\n ",MODELING:`
|
|
559
559
|
Pages are page types, built from slices and fields. Content that is
|
|
560
560
|
not a page is a custom type, such as an author or a navigation menu.
|
|
561
561
|
A page references a custom type with a content relationship field,
|
|
@@ -576,4 +576,4 @@ Watch stopped. Goodbye!`),Qe(`sync`,{watch:!0}),process.exit(0)}),console.info(`
|
|
|
576
576
|
A repository can hold multiple preview URLs but only one simulator URL,
|
|
577
577
|
which the Page Builder loads live slice previews from.
|
|
578
578
|
Run \`prismic docs view previews\` for details.
|
|
579
|
-
`},commands:{init:{handler:
|
|
579
|
+
`},commands:{init:{handler:Ai,description:`Initialize a Prismic project`},docs:{handler:gn,description:`Browse Prismic documentation`},gen:{handler:wr,description:`Generate files from local models`},pull:{handler:Ji,description:`Pull types and slices from Prismic`},push:{handler:Yi,description:`Push types and slices to Prismic`},sync:{handler:Oa,description:`Sync types and slices from Prismic`},dev:{handler:Pt,description:`Edit local models visually in the Type Builder`,hidden:!0},status:{handler:Ea,description:`Show local vs remote model differences`},env:{handler:Cn,description:`Manage the active environment`},locale:{handler:Ri,description:`Manage locales`},repo:{handler:ca,description:`Manage repositories`},type:{handler:qa,description:`Manage content types`},field:{handler:yr,description:`Manage fields`},slice:{handler:Ta,description:`Manage slices`},preview:{handler:Gi,description:`Manage preview and simulator URLs`},token:{handler:Ra,description:`Manage API tokens`},webhook:{handler:to,description:`Manage webhooks`},login:{handler:zi,description:`Log in to Prismic`},logout:{handler:Bi,description:`Log out of Prismic`},whoami:{handler:no,description:`Show the currently logged in user`},"task-id":{handler:Na,description:`Print a task ID for --task-id`,hidden:it()===void 0}}});const io=Ue({exp:P(Ne())});function ao(e){try{let[,t]=e.split(`.`);if(!t)return;let n=JSON.parse(Buffer.from(t,`base64url`).toString());return Ie(io,n)}catch{return}}const oo=[A,i,h,p,fe,de,t,x,re,ue,he,me,yn,pe,le,_e,gt,ce,Ke,I,z,qe,We],so=[qe,We];await co();async function co(){await vt({npmPackageName:ke,statePath:Xe}),lt().catch(()=>{});let{positionals:[e=``],values:{version:t,help:n,repo:i=await r().catch(()=>void 0),"analytics-intent":a,"analytics-task-id":o,"user-intent":s=a,"task-id":c=o}}=bt({options:{version:{type:`boolean`,short:`v`},help:{type:`boolean`,short:`h`},repo:{type:`string`,short:`r`},"user-intent":{type:`string`},"task-id":{type:`string`},"analytics-intent":{type:`string`},"analytics-task-id":{type:`string`}},allowPositionals:!0,strict:!1});if(t){console.info(Oe);return}let l=typeof i==`string`?i:void 0,u=typeof s==`string`?s:void 0,d=typeof c==`string`?c:void 0,f=!n&&e!==``&&e!==`task-id`&&it()!==void 0?uo(d,u):void 0;if(f){console.error(`error: ${f}\nrun \`prismic task-id\` once per user request, then pass --task-id <id> --user-intent "<what the user asked for>" on every command until the user asks for something else`),process.exitCode=1;return}if(!n){let{token:e,host:t}=await U(),n=W.PRISMIC_TELEMETRY_ENABLED??await ut(),r=W.PRISMIC_SENTRY_ENABLED??(n&&W.PROD);if(r&&await lo({host:t,repo:l,userIntent:u,taskId:d}),n&&await rt({host:t,repo:l,userIntent:u,taskId:d}),e){let i=ao(e)?.exp,a=Date.now()/1e3;if((!i||i-a<=3600)&&process.on(`exit`,()=>ot()),r||n){let n=Ze();n?Vr({id:n}):(!i||i>a)&&Ir({token:e,host:t}).then(e=>{st(e),Vr({id:e.shortId})}).catch(()=>{})}}}let p=!n&&e&&e!==`sync`;try{p&&$e(e),await ro(),p&&Qe(e)}catch(t){process.exitCode=1;let n=await jt(t).catch(()=>void 0);if(p&&Qe(e,{error:n??t}),oo.some(e=>t instanceof e))console.error(n),so.some(e=>t instanceof e)&&await Hr(t);else throw console.error(`The CLI reached a bug. Report this if it keeps happening: https://github.com/prismicio/cli/issues`),await Hr(t),t}}async function lo(e){let{host:t,repo:n,userIntent:r,taskId:i}=e;Rr({dsn:W.PRISMIC_SENTRY_DSN,appName:ke,appVersion:Oe,environment:W.PRISMIC_SENTRY_ENVIRONMENT}),zr(`host`,t),n&&(zr(`repository`,n),Br(`Repository Data`,{name:n})),i&&zr(`taskId`,i),r&&Br(`Agent Task`,{userIntent:r,taskId:i});try{zr(`framework`,(await O()).id)}catch{}}function uo(e,t){if(!e)return`missing --task-id`;if(!Ma(e))return"--task-id must come from `prismic task-id`";if(!t)return`missing --user-intent`}export{};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{S as e,ct as t,d as n,f as r,ft as i,s as a,st as o,t as s,u as c,v as l}from"./adapters-
|
|
1
|
+
import{S as e,ct as t,d as n,f as r,ft as i,s as a,st as o,t as s,u as c,v as l}from"./adapters-Bt9QKcJb.mjs";import{_ as u,l as d}from"./request-DJTl_0US.mjs";import{n as f,o as p}from"./packageJson-Bxht6H4y.mjs";import{relative as m}from"node:path";import{fileURLToPath as h}from"node:url";const g=o`
|
|
2
2
|
return (
|
|
3
3
|
<section
|
|
4
4
|
data-slice-type={slice.slice_type}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{E as e,S as t,ct as n,d as r,f as i,ft as a,st as o,t as s,v as c,w as l}from"./adapters-
|
|
1
|
+
import{E as e,S as t,ct as n,d as r,f as i,ft as a,st as o,t as s,v as c,w as l}from"./adapters-Bt9QKcJb.mjs";import{_ as u,l as d}from"./request-DJTl_0US.mjs";import{d as f,n as p,o as m}from"./packageJson-Bxht6H4y.mjs";import{t as h}from"./taggedTemplateLiteral-DygvE_Ih.mjs";import{readFile as g,rm as _}from"node:fs/promises";import{relative as v}from"node:path";import{fileURLToPath as y}from"node:url";var b,x,S,C,w;const T=o`
|
|
2
2
|
<template>
|
|
3
3
|
<section
|
|
4
4
|
:data-slice-type="slice.slice_type"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=`prismic`,t=`1.23.0`;export{t as n,e as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./package-
|
|
1
|
+
import{n as e,t}from"./package-Dyw1b366.mjs";import{fileURLToPath as n}from"node:url";import{spawn as r}from"node:child_process";const i=[],a=[];let o,s;function c(e){let{writeKey:t}=e;o=e.anonymousId,s=e.userId,process.on(`exit`,()=>d({writeKey:t}))}function l(n){s=n.userId,a.push({userId:n.userId,anonymousId:o,integrations:{Intercom:{user_hash:n.intercomHash}},context:{app:{name:t,version:e}},timestamp:(/* @__PURE__ */ new Date()).toISOString()})}function u(n,r={}){let{properties:a,groupId:c}=r;i.push({event:n,properties:{nodeVersion:process.versions.node,...a},context:{app:{name:t,version:e},groupId:c},userId:s,anonymousId:o,timestamp:(/* @__PURE__ */ new Date()).toISOString()})}function d(e){let{writeKey:t}=e;if(i.length!==0||a.length!==0){try{let e=Buffer.from(JSON.stringify({trackEvents:i.map(e=>({...e,userId:e.userId||s})),identifyEvents:a,writeKey:t})).toString(`base64`),o=n(new URL(`./subprocesses/sendSegmentEvents.mjs`,import.meta.url));r(process.execPath,[o,e],{detached:!0,stdio:`ignore`}).unref()}catch{}i.length=0,a.length=0}}async function f(e,t,n){let r={"Content-Type":`application/json`,Authorization:`Basic ${btoa(n+`:`)}`};await Promise.allSettled([...e.map(e=>fetch(`https://api.segment.io/v1/track`,{method:`POST`,headers:r,body:JSON.stringify(e)}).catch(()=>{})),...t.map(e=>fetch(`https://api.segment.io/v1/identify`,{method:`POST`,headers:r,body:JSON.stringify(e)}).catch(()=>{}))])}export{l as i,f as n,u as r,c as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"../auth-
|
|
1
|
+
import{a as e}from"../auth-NkX7Docj.mjs";try{await e()}catch{}export{};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../segment-
|
|
1
|
+
import{n as e}from"../segment-yGieXuDf.mjs";const{trackEvents:t,identifyEvents:n,writeKey:r}=JSON.parse(Buffer.from(process.argv[2],`base64`).toString());try{await e(t,n,r)}catch{}export{};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../update-notifier-
|
|
1
|
+
import{n as e}from"../update-notifier-ChP_LYxw.mjs";const[t,n]=process.argv.slice(2);try{await e(t,new URL(n))}catch{}export{};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{S as e,ct as t,d as n,f as r,ft as i,s as a,st as o,t as s,u as c,v as l}from"./adapters-
|
|
1
|
+
import{S as e,ct as t,d as n,f as r,ft as i,s as a,st as o,t as s,u as c,v as l}from"./adapters-Bt9QKcJb.mjs";import{_ as u,l as d}from"./request-DJTl_0US.mjs";import{n as f,o as p}from"./packageJson-Bxht6H4y.mjs";import{t as m}from"./taggedTemplateLiteral-DygvE_Ih.mjs";import{readFile as h,rm as g}from"node:fs/promises";import{relative as _}from"node:path";import{fileURLToPath as v}from"node:url";var y,b,x,S,C,w,T,E,D,O;function k({typescript:e}){return e?o`
|
|
2
2
|
import { createClient as baseCreateClient } from "@prismicio/client";
|
|
3
3
|
import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
4
4
|
import { env } from '$env/dynamic/public';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./package-
|
|
1
|
+
import{n as e}from"./package-Dyw1b366.mjs";import{I as t,M as n,P as r,_ as i,c as a,f as o,k as s}from"./request-DJTl_0US.mjs";import{o as c}from"./packageJson-Bxht6H4y.mjs";import{fileURLToPath as l}from"node:url";import{spawn as u}from"node:child_process";const d=s({latestKnownVersion:r(t()),lastUpdateCheckAt:r(n())});async function f(t){try{if(p())return;let n=await m(t.statePath),r=e;if(n?.latestKnownVersion&&h(n.latestKnownVersion,r)){let e=`Update available: ${r} → ${n.latestKnownVersion}. Run \`npx ${t.npmPackageName}@latest --version\` to update.`;process.on(`exit`,()=>{try{console.error(`\n${e}`)}catch{}})}(!n?.lastUpdateCheckAt||Date.now()-n.lastUpdateCheckAt>864e5)&&process.on(`exit`,()=>{_(t.npmPackageName,t.statePath)})}catch{}}function p(){return process.env.NO_UPDATE_NOTIFIER!==`0`&&!(process.env.NO_UPDATE_NOTIFIER!==`1`&&!process.env.CI&&process.stderr.isTTY)}async function m(e){return o(e,{schema:d}).catch(()=>void 0)}function h(e,t){if(e.includes(`-`)||t.includes(`-`))return!1;let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);if(n.length!==3||r.length!==3||n.some(e=>!Number.isFinite(e))||r.some(e=>!Number.isFinite(e)))return!1;for(let e=0;e<3;e++){if(n[e]>r[e])return!0;if(n[e]<r[e])return!1}return!1}async function g(e,t){let n=await c(e);await i(t,a({latestKnownVersion:n,lastUpdateCheckAt:Date.now()}))}function _(e,t){try{let n=l(new URL(`./subprocesses/updateVersionState.mjs`,import.meta.url));u(process.execPath,[n,e,t.href],{detached:!0,stdio:`ignore`}).unref()}catch{}}export{g as n,f as t};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=`prismic`,t=`1.23.0-pr.409.dafc762`;export{t as n,e as t};
|