khoros-aurora-sdk 25.2.1 → 25.2.2

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/build-hash.txt CHANGED
@@ -1 +1 @@
1
- b846e83
1
+ 9c3527f
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "khoros-aurora-sdk",
3
- "version": "25.2.1",
3
+ "version": "25.2.2",
4
4
  "author": "Khoros, LLC",
5
5
  "keywords": [
6
6
  "Khoros_Aurora_SDK",
@@ -94,6 +94,7 @@
94
94
  "lil-uri": "~0.2.2",
95
95
  "lint-staged": "~12.3.3",
96
96
  "mime-types": "^2.1.35",
97
+ "minimatch": "^9.0.5",
97
98
  "next": "~15.1.4",
98
99
  "pino": "^9.6.0",
99
100
  "pino-pretty": "^13.0.0",
@@ -1,3 +1,3 @@
1
- "use strict";var tt=Object.create;var Se=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var nt=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var st=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var it=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of rt(t))!ot.call(e,o)&&o!==n&&Se(e,o,{get:()=>t[o],enumerable:!(a=at(t,o))||a.enumerable});return e};var d=(e,t,n)=>(n=e!=null?tt(nt(e)):{},it(t||!e||!e.__esModule?Se(n,"default",{value:e,enumerable:!0}):n,e));var Oe=st((La,Le)=>{"use strict";var Pt=require("brotli"),f=require("node:fs"),Rt=require("node:zlib"),Tt=require("node:path"),se=require("node:util"),Ne={extension:"br",skipLarger:!0,mode:0,quality:11,lgwin:22},vt={dirs:[],threshold:0,minRatio:1,brotliSettings:Ne,onProcessed:null,onBrotliProcessed:null,onGzipProcessed:null},xt=se.promisify(f.writeFile),ie=se.promisify(f.stat),ft=se.promisify(f.readFile),De=function(e,t){let n=[];return f.readdir(e,(a,o)=>{if(a)return t(a);let r=o.length;if(!r)return t(null,n);o.forEach(s=>{s=Tt.resolve(e,s),f.stat(s,(i,p)=>{p&&p.isDirectory()?De(s,(S,u)=>{n=n.concat(u),--r||t(null,n)}):(n.push(s),--r||t(null,n))})})})},_e=e=>e/1e3,Ft=async(e,t,n)=>new Promise(async a=>{let o=Pt.compress(await ft(e),Ne);if(o===null)return a(Q(`${e}.br`,"result",t));let r=o.length/t,s=!1;try{await ie(`${e}.br`),s=!1}catch{s=!0}return r>n.minRatio&&s===!0?a(Q(`${e}.br`,"ratio",t,o.length)):(await xt(`${e}.br`,o),a(Be(`${e}.br`,t,o.length)))}),ht=(e,t,n)=>new Promise(a=>{let o=f.createReadStream(e),r=f.createWriteStream(`${e}.gz`),s=Rt.createGzip({level:9});o.pipe(s).on("error",i=>console.error(i)).pipe(r).on("finish",async()=>{let i=await ie(`${e}.gz`);if(i.size/t>n.minRatio){let S=Q(`${e}.gz`,"ratio",t,i.size);f.unlink(`${e}.gz`,()=>{}),a(S)}else{let S=Be(`${e}.gz`,t,i.size);a(S)}}).on("error",i=>console.error(i))}),_t=async(e,t)=>{if(e.endsWith(".js")||e.endsWith(".css")||e.endsWith(".html")||e.endsWith(".svg")||e.endsWith("jpg")){let n=await ie(e),{size:a}=n;if(a<t.threshold)return Q(e,"size",a),{filePath:e,skipped:!0,brotli:null,gzip:null};let o=await ht(e,a,t);t.onGzipProcessed&&t.onGzipProcessed(o);let r=await Ft(e,a,t);return t.onBrotliProcessed&&t.onBrotliProcessed(r),{filePath:e,skipped:!1,brotli:r,gzip:o}}return{filePath:e,skipped:!0,brotli:null,gzip:null}};function Be(e,t,n,a){let o=n/t,s=`${o*100}% == ${_e(t)}kB -> ${_e(n)}kB`;return console.log(`[done] ${e}: ${s}`),{filePath:e,initialSize:t,compressedSize:n,type:a,ratio:o}}var Q=(e,t,n,a)=>{let o=a/n,r=o*100;return{filePath:e,initialSize:n,compressedSize:a||null,ratio:o||null,ratioPercent:r||null}},Nt=async e=>{e={...vt,...e};let t=[];return e.dirs.forEach(n=>{De(n,(a,o)=>{if(!o)console.debug("No results found at",n);else{let r=o.map(async s=>{let i=await _t(s,e);return typeof e.onProcessed=="function"&&e.onProcessed(i),i});t.concat(r)}})}),t};Le.exports=function(e){return Nt(e)}});var Ze=require("fs-extra"),$e=require("rimraf");var de=d(require("pino")),pt=(0,de.default)({transport:{target:"pino-pretty",options:{sync:!0}},level:process.env.LOG_LEVEL??"info"});function l(e,t){return pt.child({name:e??"sdk"},t)}var G=require("fs-extra"),_=d(require("node:path")),Me=d(require("shelljs"));var ut=d(require("fs-extra")),$=d(require("node:path"));var ge=require("glob");var zt=l("filePathHelper");function A(e,t){return(0,ge.glob)(e?.replaceAll($.default.sep,$.default.posix.sep),t)}var B=l("graphql-types");async function lt(e,t,n){B.info("Building graphql types for plugin directory: %s",e);let a=t&&n?"**":t?"components":"endpoints",o=await A(_.default.join(e,"src",a,"**","package.json"));return(await Promise.all(o.map(async s=>{let i=_.default.dirname(s),p=await A(_.default.join(i,"**","*.graphql"));if(p.length>0){B.debug("Building types types for graphql files: %s",p);let S=_.default.join(i,"types","codegen.json");try{await(0,G.copy)(_.default.join(__dirname,"..","types","codegen.json"),S);let u="graphql-codegen --config ./types/codegen.json ";B.debug(u);let I=Me.default.exec(u,{fatal:!0,silent:!0,cwd:i});return I.code>0?B.error("Building graphql types failed for module at %s: %s",i,I.stderr):B.info("Building graphql types complete for module at %s",i),I.code}finally{await(0,G.rm)(S)}}}))).find(s=>s>0)??0}var Ie=lt;var be="build-time.txt",ee="@khoros/endpoints",te="1.0.0",yt=ee.slice(1).replaceAll("/","-"),$t=`${yt}-${te}.tgz`;var M=require("fs-extra"),g=d(require("node:path")),H=d(require("shelljs"));var me=require("node:fs/promises"),C=l("buildModules");function ae(e,t,n){return`babel ${e} --ignore 'types/*.ts' --copy-files --config-file ${t} --out-dir ${n} --extensions ".ts"`}async function ct(e,t,n){let a=null,o=Date.now(),r=g.default.join(e,"src"),s=g.default.join(r,"endpoints");if(await(0,M.pathExists)(s)){C.info("Building plugin modules at %s",g.default.resolve(__dirname,e));let i=g.default.join(e,"tsconfig.server.json"),p=g.default.join(e,"babelModules.config.json");if(await(0,M.pathExists)(p)&&await(0,M.pathExists)(i)){let S=g.default.isAbsolute(t)?t:g.default.join(e,t);C.debug(`Output directory is ${S}`);let u=g.default.join(S,"pkg");await(0,M.emptyDir)(u);let I=g.default.join(u,"endpoints"),m=[`tsc -p ${i} --noEmit`],R=g.default.join(r,"shared");if(await(0,M.pathExists)(R)){let v=await(0,me.readdir)(R);for(let x of v)C.info("Compiling shared package %s...",x),m.push(ae(g.default.join(R,x),p,g.default.join(u,"shared",x)))}if(n&&n.size>0)for(let v of n)C.info("Compiling endpoint %s...",v),m.push(ae(g.default.join(s,v),p,g.default.join(I,v)));else C.info("Compiling all modules..."),m.push(ae(s,p,I));let P=m.join(" && "),T=H.default.exec(P,{fatal:!0,cwd:e});if(T.code>0)return C.error("Error building modules: %s",T.stderr),{code:T.code};{let v=g.default.join(e,"package.json");if(await(0,M.pathExists)(v)){let x=await(0,M.readJSON)(v);x.workspaces=["endpoints/**/*","shared/**/*"],x.name=ee,x.version=te,await(0,M.writeJSON)(g.default.join(u,"package.json"),x);let le=g.default.join(e,"package-lock.json"),ye=g.default.join(e,"src","shared");await(0,M.pathExists)(ye)&&(C.info("Copying /src/shared directory into output bundle"),await(0,M.copy)(ye,g.default.join(u,"shared"),{overwrite:!0})),await(0,M.pathExists)(le)&&await(0,M.copy)(le,g.default.join(u,"package-lock.json"),{errorOnExist:!1}),C.debug(`Creating a tarball in ${u}`);let ce=H.default.exec(`npm pack ${u} --pack-destination ${u}`);if(ce.stdout){a=g.default.join(u,ce.stdout.trim()),C.info("Created a tarball at %s",a);let et=[`rm -rf ${u}/package.json`,`rm -rf ${u}/package-lock.json`,`rm -rf ${u}/endpoints`];H.default.exec(et.join(";"),{cwd:u})}}else C.warn("Missing package.json file in %s",r);await(0,M.writeFile)(g.default.join(u,be),`${Date.now()}`),C.info("Module build complete in %d ms",Date.now()-o)}}else C.warn("No tsconfig.server.json file found. Please run init first.")}else C.info("No plugin modules to build");return{code:0,path:a}}var Ce=ct;var N=d(require("fs-extra")),F=d(require("node:path")),re=d(require("shelljs"));var L=l("buildNext"),St=async e=>{let t=await A(F.default.join(e,"src","**","*.component.json"));return Promise.all(t.map(async n=>({path:n,descriptor:await N.default.readJson(n)})))},dt=async(e,t)=>{let n={};return await Promise.all(t.map(async a=>{let{descriptor:o,path:r}=a,s=`./${o.id}`,i=F.default.dirname(r),p=F.default.join(i,"Component.tsx");await(0,N.pathExists)(p)||(p=F.default.join(i,`${s}.tsx`)),await(0,N.pathExists)(p)?(L.debug(`React component found at path ${p} for descriptor at path ${r}`),Object.assign(n,{[s]:`./${F.default.relative(e,p)}`})):L.error("No React component found at path %s for descriptor at path %s",p,r)})),n};async function Ae(e,t){let n=await St(e),a=await dt(e,n);return L.info("Federation config is %O",a),await N.default.writeJSON(F.default.join(e,"federation.config.json"),{name:"auroraComponents"+(t?"Local":""),exposes:a,extraOptions:{debug:!1}}),n}async function gt(e){re.default.env.NEXT_PRIVATE_LOCAL_WEBPACK="true";let t=`next build ${e}`;try{let n=re.default.exec(t,{async:!1,fatal:!0,cwd:e});return n.code>0&&L.error("Error in NextJS build"),{code:n.code}}catch(n){return L.error("Error running next command: %s",t,n?.message),{code:1}}}var Ee=gt;var ne=d(require("node:path"));var Pe=l("changeSet");function Mt(){let e=process.env.CHANGE_SET;return e?.length>0?e.split(/[\s,]/):null}function It(e){let t=e??Mt();if(t?.length>0){Pe.info("Parsing changeset: %O",t);let n=!1;t.some(r=>r.includes(ne.default.join("src","components")))&&(n=!0);let a=!1;t.some(r=>r.includes(ne.default.join("src","endpoints")))&&(a=!0),t.some(r=>r=="package.json"||r.startsWith(".github"))&&(n=!0,a=!0);let o={buildComponents:n,buildEndpoints:a};return Pe.info("Changeset result: %O",o),o}return null}var Re=It;var ve=d(require("dotenv-flow")),xe=d(require("findup-sync")),oe=d(require("node:path")),fe=d(require("yargs")),Fe=require("yargs/helpers");var Sa=require("graphql-import-node"),Te=require("@urql/core");var Ma=l("GraphqlClient");var Ta=l("versionCheck");var O=l("cli");function Ct(){if(!global.sdkConfigLoaded){let e=(0,xe.default)(".env*");if(e){O.debug("Loading config from .env files: $s",e);let{error:t,parsed:n}=ve.default.config({path:oe.default.dirname(e)});t?(O.error(t,"Error reading config file"),process.exit(1)):O.info("Using config values: %O",n)}}global.sdkConfigLoaded=!0}function At(e){let t=e.indexOf("node_modules");return t===1?e:e.slice(0,t-1)}function Et(e,t,n,a,o){Ct(),(0,fe.default)((0,Fe.hideBin)(process.argv)).scriptName(e).options(a??{}).env("PLUGIN").usage("$0 [repoPath]").command("$0 [repoPath]",t,r=>{let s=At(process.cwd());return r.positional("repoPath",{describe:"The full path to plugin root directory.",default:s,type:"string"})},async r=>{await n(r)}).check(async r=>{let{repoPath:s}=r;if(!s)throw new Error("No plugin repository path found. Please either pass it as an argument to this process or specify it in your .env file as PLUGIN_REPO_PATH. ");if(!oe.default.isAbsolute(s))throw new Error("The plugin repository path must be a full (not relative) path.");return o?await o(r):!0}).help().showHelpOnFail(!1).fail((r,s)=>{s?O.error(s.message):O.error(r),process.exit(1)}).parse()}var he=Et;var Ue=d(Oe()),Ve=require("fs-extra"),K=d(require("node:path"));var W=l("compress");async function Dt(e,t){let n=K.default.isAbsolute(t)?t:K.default.join(e,t),a=K.default.join(n,"mf");if(await(0,Ve.pathExists)(a)){W.info("Compressing assets in %s",a);try{await(0,Ue.default)({dirs:[a]}),W.info("Compressing assets complete")}catch(o){W.error(o,"Error compressing assets")}}else W.info("No mf assets to compress")}var we=Dt;var U=d(require("node:path")),qe=d(require("shelljs"));var j=l("format");function Bt(e,t){j.info("Formatting plugin directory: %s",t);let n=e==="format:fix"?"--write":"--check",a=`prettier --config ${U.default.join(t,".prettierrc.js")} --ignore-path ${U.default.join(t,".prettierignore")} ${n} ${U.default.join(t,"res")} ${U.default.join(t,"src")} `;j.debug(a);let o=qe.default.exec(a,{cwd:t});return o.code>0?j.warn("Formatting errors found for plugin at %s",t):j.info("Formatting complete for plugin at %s",t),o.code}var ke=Bt;var c=require("fs-extra"),y=d(require("node:path"));var V=l("setup"),Lt={hooks:{"pre-commit":"npm run precommit","post-commit":"git update-index --again"}},Ot={"**/*.{js,jsx,ts,tsx,css,scss,pcss,json}":["prettier --write"],"**/*.{js,ts,tsx}":["eslint --fix --ignore-pattern '!.eslintrc.js' --ignore-pattern '!.prettierrc.js'"]},E=y.default.resolve(__dirname,y.default.join("..")),Ut=y.default.join(E,"templates");async function Ge(e){return(await(0,c.readFile)(e)).toString().split(`
2
- `).map(n=>n.trim())}async function Vt(e,t){let n=y.default.join(e,"package.json");if(await(0,c.pathExists)(n)){let a=await(0,c.readJson)(n,"utf8"),r=(await(0,c.readJson)(y.default.join(E,"package.json"))).name;if(t&&!a.devDependencies[r]&&!a.dependencies[r])V.warn("SDK not found as a dependency of package.json file at %s. Skipping init step.",n);else{V.info("Initializing plugin directory %s",e),await(0,c.remove)(y.default.join(e,"app")),await(0,c.ensureDir)(y.default.join(e,"pages")),await(0,c.ensureDir)(y.default.join(e,"src"));async function s(p,S=!0){let u=y.default.join(Ut,p),I=p.replaceAll(".tmpl",""),m=y.default.join(e,I);if(V.debug(`Copying ${u} to ${m}`),await(0,c.copy)(u,m,{overwrite:S}),!S&&I.startsWith(".")&&I.endsWith("ignore")&&await(0,c.pathExists)(m)){let R=await Ge(m),P=await Ge(u);for(let T of P)R.includes(T)||R.push(T);await(0,c.writeFile)(m,R.filter(T=>!!T).join(`
3
- `))}}let i={".env.local.tmpl":!1,".eslintignore.tmpl":!1,".eslintrc.tmpl.js":!1,".gitignore.tmpl":!1,".npmrc.tmpl":!0,".nvmrc.tmpl":!0,".prettierignore.tmpl":!1,".prettierrc.tmpl.js":!1,"tsconfig.server.tmpl.json":!0,"tsconfig.tmpl.json":!0,"babelModules.config.tmpl.json":!1};V.info(`Copying template files to the plugin at ${e}`),await Promise.all(Object.keys(i).map(async p=>{await s(p,i[p])})),a.workspaces=["src/**/*"],a.engines={node:">=18"},a.scripts||(a.scripts={}),a.scripts.start=`npm explore ${r} -- npm run start`,a.scripts["start:logger"]=`npm explore ${r} -- npm run start:logger`,a.scripts.dev=`npm explore ${r} -- npm run dev:plugin`,a.scripts.build=`npm explore ${r} -- npm run build:plugin`,a.scripts["build:graphql"]=`npm explore ${r} -- npm run build:graphql`,a.scripts.lint=`npm explore ${r} -- npm run lint:plugin`,a.scripts["lint:fix"]=`npm explore ${r} -- npm run lint:plugin:fix`,a.scripts.format=`npm explore ${r} -- npm run format:plugin`,a.scripts["format:fix"]=`npm explore ${r} -- npm run format:plugin:fix`,a.scripts.init=`npm explore ${r} -- npm run init:plugin`,a.scripts.validate=`npm explore ${r} -- npm run validate:plugin`,a.scripts.gen=`npm explore ${r} -- npm run gen`,a.scripts.precommit="lint-staged",a.husky=Lt,a["lint-staged"]=Ot,await(0,c.writeJson)(n,a,{spaces:" "}),await(0,c.copy)(y.default.join(E,"README.md"),y.default.join(e,"SDK.md"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"next.config.js"),y.default.join(e,"next.config.js"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"next.overrides.js"),y.default.join(e,"next.overrides.js"),{overwrite:!1}),await(0,c.copy)(y.default.join(E,"postcss.config.js"),y.default.join(e,"postcss.config.js"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"types","mf","index.d.ts"),y.default.join(e,"types","mf","aurora.d.ts"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"types","pkg","index.d.ts"),y.default.join(e,"types","pkg","aurora.d.ts"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"types","graphql.d.ts"),y.default.join(e,"types","graphql.d.ts"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"templates","pcss.d.ts.tmpl"),y.default.join(e,"types","pcss.d.ts"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"types","graphql-schema-types.ts"),y.default.join(e,"types","graphql-schema-types.ts"),{overwrite:!0})}}else V.warn("No package.json file found at %s. Skipping init step.",n)}var He=Vt;var pe=d(require("node:path")),Qe=d(require("shelljs"));var We=require("fs-extra"),z=l("lintPlugin");async function wt(e,t){let n=pe.default.join(t,"src");if(await(0,We.pathExists)(n)){z.info("Linting plugin directory: %s",t);let a=e==="lint:fix"?"--fix --max-warnings=0":"",o=`eslint --ext .js --ext .jsx --ext .tsx --ext .ts --cache --config ${pe.default.join(t,".eslintrc.js")} --no-error-on-unmatched-pattern --ignore-pattern '**/types/*' ${a} ${n}`;z.debug(o);let r=Qe.default.exec(o,{fatal:!0,cwd:t});return r.code>0?z.error("Linting failed for plugin at %s",t):z.info("Linting complete for plugin at %s",t),r.code}return 0}var Ke=wt;var w=(r=>(r.Freemarker="FREEMARKER",r.Handlebars="HANDLEBARS",r.Html="HTML",r.Javascript="JAVASCRIPT",r.React="REACT",r))(w||{});var Y=(i=>(i.Delete="DELETE",i.Get="GET",i.Head="HEAD",i.Options="OPTIONS",i.Patch="PATCH",i.Post="POST",i.Put="PUT",i))(Y||{});var q=(r=>(r.Content="CONTENT",r.Custom="CUSTOM",r.People="PEOPLE",r.Places="PLACES",r.Texthtml="TEXTHTML",r))(q||{});var k=require("fs-extra"),b=d(require("node:path"));var J=(r=>(r.Json="JSON",r.Multipart="MULTIPART",r.MultipartFiles="MULTIPART_FILES",r.None="NONE",r.UrlEncoded="URL_ENCODED",r))(J||{});var je=d(require("fs-extra"));var za=l("fileUtils");function qt(e){return Promise.all(e.map(async t=>({path:t,descriptor:await je.default.readJson(t)})))}async function X(e){let t=await A(e);return qt(t)}var ue=require("fs-extra"),Ye=require("glob"),D=d(require("node:path"));var ze={ReactComponent:["@coveo/atomic-react","@coveo/atomic","@coveo/headless-react","@coveo/headless","clone-deep","dateformat","js-base64","lil-uri","moment-timezone","path-to-regexp","react","react-beautiful-dnd","react-bootstrap","react-hook-form","react-uid","react-dropzone","tabbable","tiny-lru","universal-cookie"],Endpoint:["brotli","clone-deep","cookie","dateformat","js-base64","jsonwebtoken","lil-uri","path-to-regexp","tiny-lru","universal-cookie"]};var Ht={async validatePackageDependencies(e,t,n=""){let{path:a}=e,o=D.default.dirname(a),r=D.default.join(o,"package.json"),s=[],i={allowedDependencies:[],disallowedDependencies:[]};if(t==="Endpoint"||t==="ReactComponent"){s=ze[t];let p=await(0,Ye.glob)("**/package.json",{cwd:D.default.join(n,"src"),ignore:[D.default.join(n,"src","endpoints","**","node_modules","**"),D.default.join(n,"src","components","**","node_modules","**")],absolute:!0}),S=await Promise.all(p.map(async u=>(await(0,ue.readJSON)(u)).name));await(0,ue.readJSON)(r).then(u=>(u.dependencies&&(i.allowedDependencies=[...s,...S],i.disallowedDependencies=Object.keys(u.dependencies).filter(I=>!i.allowedDependencies.includes(I))),null))}return i}},Je=Ht;var h=l("validationUtils"),Qt={validateCustomComponentDescriptor(e,t=[]){return e.id||t.push("Component id is missing or empty for descriptor: "+JSON.stringify(e)),e.markupLanguage?Object.values(w).includes(e.markupLanguage)||t.push("Component markupLanguage value is invalid for descriptor: "+JSON.stringify(e)+". Valid markupLanguage values are: "+JSON.stringify(Object.values(w))):t.push("Component markupLanguage field is missing for descriptor: "+JSON.stringify(e)+". Valid markupLanguage values are: "+JSON.stringify(Object.values(w))),e.grouping?Object.values(q).includes(e.grouping)||t.push("Component grouping value is invalid for descriptor: "+JSON.stringify(e)+". Valid grouping values are: "+JSON.stringify(Object.values(q))):t.push("Component grouping field is missing for descriptor: "+JSON.stringify(e)+". Valid grouping values are: "+JSON.stringify(Object.values(q))),!e.components||e.components.length===0?t.push('Missing "components" field for descriptor: '+JSON.stringify(e)):e.components.some(n=>`custom.widget.${e.id}`===n.id)||t.push(`Invalid "components" field for descriptor. Components field id should be "custom.widget.${e.id}": Descriptor is ${JSON.stringify(e)}`),t},validateReactComponentDescriptor(e,t=[]){return this.validateCustomComponentDescriptor(e,t),e.markupLanguage!="REACT"&&t.push('Component descriptor markup language must be "REACT" for descriptor: '+JSON.stringify(e)),t},validateEndpointDescriptor(e,t=[]){return e.id||t.push("Endpoint id field is missing or empty for descriptor: "+JSON.stringify(e)),e.bodyType&&!Object.values(J).includes(e.bodyType)&&t.push("Endpoint body type field is invalid for descriptor: "+JSON.stringify(e)+". Valid body types are: "+JSON.stringify(Object.values(J))),e.httpMethods&&e.httpMethods.some(n=>!Object.values(Y).includes(n))&&t.push("Endpoint httpMethods field is invalid for descriptor: "+JSON.stringify(e)+". Valid httpMethods are: "+JSON.stringify(Object.values(Y))),t},validateModule(e,t=[]){let{descriptor:n,path:a}=e,o=/\.(\w+)\.json/,r=b.default.basename(a).replace(o,""),s=o.exec(a);if(s.length<2)t.push("No descriptor type found");else{let[,i]=s,p=b.default.dirname(a),S=b.default.basename(p);S===i&&t.push(`A descriptor needs to go into its own directory under ${i}s at ${a}.`),r!=S?t.push(`Descriptor filename prefix (${r}) must match descriptor directory name (${S}) at ${a}`):n.id!=S&&t.push(`Descriptor id (${n.id}) must match descriptor directory name (${S}) at ${a}`)}return t},async validatePackageDescriptor(e,t,n="",a=!1,o=[]){let{path:r}=e,s=b.default.dirname(r),i=b.default.join(s,"package.json");if(!await(0,k.pathExists)(i))o.push(`No package descriptor (package.json) found in ${s}`);else{let p=await Je.validatePackageDependencies(e,t,n);if(p.disallowedDependencies.length>0){let S=`Disallowed dependencies found in ${s}/package.json: ${p.disallowedDependencies.join(", ")}. Only the following dependencies are allowed: ${p.allowedDependencies.sort().join(", ")}`;a?h.warn(S):o.push(S)}}return o},async validateReactComponent(e,t,n=!1,a=[]){let{descriptor:o,path:r}=e;this.validateReactComponentDescriptor(o,a),this.validateModule(e,a),await this.validatePackageDescriptor(e,"ReactComponent",t,n,a);let s=b.default.dirname(r),i=b.default.join(s,"Component.tsx"),p=`${o.id}.tsx`;return await(0,k.pathExists)(i)||(i=b.default.join(s,p)),await(0,k.pathExists)(i)||a.push(`No valid React component (${p}) found in ${s}`),a},async validateEndpoint(e,t,n=!1,a=[]){let{descriptor:o,path:r}=e;this.validateEndpointDescriptor(o,a),this.validateModule(e,a),await this.validatePackageDescriptor(e,"Endpoint",t,n,a);let s=b.default.dirname(r),i=b.default.join(s,"index.ts");return await(0,k.pathExists)(i)||a.push(`No valid endpoint (index.ts) found in ${s}`),a},async validatePlugin(e,t=!1,n=!1,a=!1){h.info("Validating plugin files at %s...",e);let o=[];if(t){h.info("Validating component descriptors...");let r=await A(b.default.join(e,"res","components","*"));for await(let s of r){let i=await X(b.default.join(s,"*.component.json"));if(i.length===0)h.warn(`No component descriptor (<ComponentName>.component.json) found in ${s}`);else for(let p of i)this.validateCustomComponentDescriptor(p.descriptor,o),this.validateModule(p,o)}}if(n){h.info("Validating React components...");let r=await A(b.default.join(e,"src","components","*"));for await(let s of r){let i=await X(b.default.join(s,"*.component.json"));if(i.length===0)o.push(`No component descriptor (<ComponentName>.component.json) found in ${s}`);else for await(let p of i)await this.validateReactComponent(p,e,!1,o)}}if(a){h.info("Validating endpoints...");let r=await A(b.default.join(e,"src","endpoints","*"));for await(let s of r){let i=await X(b.default.join(s,"*.endpoint.json"));if(i.length===0)o.push(`No endpoint descriptor (<EndpointName>.endpoint.json) found in ${s}`);else for await(let p of i)await this.validateEndpoint(p,e,!1,o)}}return h.info(`Plugin files are validated. ${o.length===0?"No":o.length} error(s) found.`),o}},Xe=Qt;var Z=l("build");he("build:modules","Build the plugin modules",async({repoPath:e,outputDirectory:t,init:n,lint:a,format:o,changeSet:r,mf:s,pkg:i})=>{let p=Date.now();if(await(0,Ze.pathExists)(t))try{Z.info("Cleaning output directory at %s",t),await(0,$e.rimraf)(t)}catch(P){Z.error(P,"Error cleaning output directory at %s",t)}n===!0&&await He(e,!0);let S=Re(r),u=S?.buildComponents??s===!0,I=S?.buildEndpoints??i===!0,m=await Xe.validatePlugin(e,!(s===!1||i===!1),u,I);if(m.length>0){for(let P of m)Z.error("Validation Error: %s",P);throw new Error("Terminating build due to validation errors")}if(a===!0&&await Ke("lint",e)>0)throw new Error("Terminating build due to lint failure");if(o===!0&&ke("format",e),await Ie(e,u,u||I)>0)throw new Error("Terminating build due to failure in building graphql types");if(u)if(await Ae(e,!1),(await Ee(e)).code==0)await we(e,t);else throw new Error("Terminating build due to component build failure");if(I&&(await Ce(e,t)).code>0)throw new Error("Terminating build due to module build failure");Z.info("Plugin build complete in "+(Date.now()-p)+"ms")},{b:{alias:"branchName",demandOption:!1,default:"main",describe:'The branch to build. If not specified, "main" is assumed. This does not control the checked out files but adds an additional branch segment to the S3 file key',type:"string"},c:{alias:"changeSet",demandOption:!1,describe:"A set of changed files. If not specified, all components and middlewares in the plugin will be built. If specified, only components and middlewares with changed files will be built.",type:"array"},o:{alias:"outputDirectory",demandOption:!1,default:"dist",describe:'The output directory. If not specified, "dist" is assumed. This is where the build artifacts will be placed.',type:"string"},i:{alias:"init",demandOption:!1,default:!1,describe:"Whether to init the plugin as part of the build process",type:"boolean"},l:{alias:"lint",demandOption:!1,default:!0,describe:"Whether to run lint as part of the build process.",type:"boolean"},f:{alias:"format",demandOption:!1,default:!1,describe:"Whether to run format as part of the build process.",type:"boolean"},m:{alias:"mf",demandOption:!1,default:!0,describe:"Whether to build the module federation (mf) artifacts.",type:"boolean"},p:{alias:"pkg",demandOption:!1,default:!0,describe:"Whether to build the module (pkg) artifacts.",type:"boolean"}});
1
+ "use strict";var at=Object.create;var Se=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var ot=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var it=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var pt=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of nt(t))!st.call(e,o)&&o!==n&&Se(e,o,{get:()=>t[o],enumerable:!(a=rt(t,o))||a.enumerable});return e};var d=(e,t,n)=>(n=e!=null?at(ot(e)):{},pt(t||!e||!e.__esModule?Se(n,"default",{value:e,enumerable:!0}):n,e));var Oe=it((Oa,Le)=>{"use strict";var Rt=require("brotli"),f=require("node:fs"),Tt=require("node:zlib"),vt=require("node:path"),se=require("node:util"),Ne={extension:"br",skipLarger:!0,mode:0,quality:11,lgwin:22},xt={dirs:[],threshold:0,minRatio:1,brotliSettings:Ne,onProcessed:null,onBrotliProcessed:null,onGzipProcessed:null},ft=se.promisify(f.writeFile),ie=se.promisify(f.stat),Ft=se.promisify(f.readFile),De=function(e,t){let n=[];return f.readdir(e,(a,o)=>{if(a)return t(a);let r=o.length;if(!r)return t(null,n);o.forEach(s=>{s=vt.resolve(e,s),f.stat(s,(i,p)=>{p&&p.isDirectory()?De(s,(S,u)=>{n=n.concat(u),--r||t(null,n)}):(n.push(s),--r||t(null,n))})})})},_e=e=>e/1e3,ht=async(e,t,n)=>new Promise(async a=>{let o=Rt.compress(await Ft(e),Ne);if(o===null)return a(Q(`${e}.br`,"result",t));let r=o.length/t,s=!1;try{await ie(`${e}.br`),s=!1}catch{s=!0}return r>n.minRatio&&s===!0?a(Q(`${e}.br`,"ratio",t,o.length)):(await ft(`${e}.br`,o),a(Be(`${e}.br`,t,o.length)))}),_t=(e,t,n)=>new Promise(a=>{let o=f.createReadStream(e),r=f.createWriteStream(`${e}.gz`),s=Tt.createGzip({level:9});o.pipe(s).on("error",i=>console.error(i)).pipe(r).on("finish",async()=>{let i=await ie(`${e}.gz`);if(i.size/t>n.minRatio){let S=Q(`${e}.gz`,"ratio",t,i.size);f.unlink(`${e}.gz`,()=>{}),a(S)}else{let S=Be(`${e}.gz`,t,i.size);a(S)}}).on("error",i=>console.error(i))}),Nt=async(e,t)=>{if(e.endsWith(".js")||e.endsWith(".css")||e.endsWith(".html")||e.endsWith(".svg")||e.endsWith("jpg")){let n=await ie(e),{size:a}=n;if(a<t.threshold)return Q(e,"size",a),{filePath:e,skipped:!0,brotli:null,gzip:null};let o=await _t(e,a,t);t.onGzipProcessed&&t.onGzipProcessed(o);let r=await ht(e,a,t);return t.onBrotliProcessed&&t.onBrotliProcessed(r),{filePath:e,skipped:!1,brotli:r,gzip:o}}return{filePath:e,skipped:!0,brotli:null,gzip:null}};function Be(e,t,n,a){let o=n/t,s=`${o*100}% == ${_e(t)}kB -> ${_e(n)}kB`;return console.log(`[done] ${e}: ${s}`),{filePath:e,initialSize:t,compressedSize:n,type:a,ratio:o}}var Q=(e,t,n,a)=>{let o=a/n,r=o*100;return{filePath:e,initialSize:n,compressedSize:a||null,ratio:o||null,ratioPercent:r||null}},Dt=async e=>{e={...xt,...e};let t=[];return e.dirs.forEach(n=>{De(n,(a,o)=>{if(!o)console.debug("No results found at",n);else{let r=o.map(async s=>{let i=await Nt(s,e);return typeof e.onProcessed=="function"&&e.onProcessed(i),i});t.concat(r)}})}),t};Le.exports=function(e){return Dt(e)}});var $e=require("fs-extra"),et=require("rimraf");var de=d(require("pino")),ut=(0,de.default)({transport:{target:"pino-pretty",options:{sync:!0}},level:process.env.LOG_LEVEL??"info"});function l(e,t){return ut.child({name:e??"sdk"},t)}var G=require("fs-extra"),_=d(require("node:path")),Me=d(require("shelljs"));var lt=d(require("fs-extra")),$=d(require("node:path"));var ge=require("glob");var Yt=l("filePathHelper");function A(e,t){return(0,ge.glob)(e?.replaceAll($.default.sep,$.default.posix.sep),t)}var B=l("graphql-types");async function yt(e,t,n){B.info("Building graphql types for plugin directory: %s",e);let a=t&&n?"**":t?"components":"endpoints",o=await A(_.default.join(e,"src",a,"**","package.json"));return(await Promise.all(o.map(async s=>{let i=_.default.dirname(s),p=await A(_.default.join(i,"**","*.graphql"));if(p.length>0){B.debug("Building types types for graphql files: %s",p);let S=_.default.join(i,"types","codegen.json");try{await(0,G.copy)(_.default.join(__dirname,"..","types","codegen.json"),S);let u="graphql-codegen --config ./types/codegen.json ";B.debug(u);let I=Me.default.exec(u,{fatal:!0,silent:!0,cwd:i});return I.code>0?B.error("Building graphql types failed for module at %s: %s",i,I.stderr):B.info("Building graphql types complete for module at %s",i),I.code}finally{await(0,G.rm)(S)}}}))).find(s=>s>0)??0}var Ie=yt;var be="build-time.txt",ee="@khoros/endpoints",te="1.0.0",ct=ee.slice(1).replaceAll("/","-"),ea=`${ct}-${te}.tgz`;var M=require("fs-extra"),g=d(require("node:path")),H=d(require("shelljs"));var me=require("node:fs/promises"),C=l("buildModules");function ae(e,t,n){return`babel ${e} --ignore 'types/*.ts' --copy-files --config-file ${t} --out-dir ${n} --extensions ".ts"`}async function St(e,t,n){let a=null,o=Date.now(),r=g.default.join(e,"src"),s=g.default.join(r,"endpoints");if(await(0,M.pathExists)(s)){C.info("Building plugin modules at %s",g.default.resolve(__dirname,e));let i=g.default.join(e,"tsconfig.server.json"),p=g.default.join(e,"babelModules.config.json");if(await(0,M.pathExists)(p)&&await(0,M.pathExists)(i)){let S=g.default.isAbsolute(t)?t:g.default.join(e,t);C.debug(`Output directory is ${S}`);let u=g.default.join(S,"pkg");await(0,M.emptyDir)(u);let I=g.default.join(u,"endpoints"),m=[`tsc -p ${i} --noEmit`],R=g.default.join(r,"shared");if(await(0,M.pathExists)(R)){let v=await(0,me.readdir)(R);for(let x of v)C.info("Compiling shared package %s...",x),m.push(ae(g.default.join(R,x),p,g.default.join(u,"shared",x)))}if(n&&n.size>0)for(let v of n)C.info("Compiling endpoint %s...",v),m.push(ae(g.default.join(s,v),p,g.default.join(I,v)));else C.info("Compiling all modules..."),m.push(ae(s,p,I));let P=m.join(" && "),T=H.default.exec(P,{fatal:!0,cwd:e});if(T.code>0)return C.error("Error building modules: %s",T.stderr),{code:T.code};{let v=g.default.join(e,"package.json");if(await(0,M.pathExists)(v)){let x=await(0,M.readJSON)(v);x.workspaces=["endpoints/**/*","shared/**/*"],x.name=ee,x.version=te,await(0,M.writeJSON)(g.default.join(u,"package.json"),x);let le=g.default.join(e,"package-lock.json"),ye=g.default.join(e,"src","shared");await(0,M.pathExists)(ye)&&(C.info("Copying /src/shared directory into output bundle"),await(0,M.copy)(ye,g.default.join(u,"shared"),{overwrite:!0})),await(0,M.pathExists)(le)&&await(0,M.copy)(le,g.default.join(u,"package-lock.json"),{errorOnExist:!1}),C.debug(`Creating a tarball in ${u}`);let ce=H.default.exec(`npm pack ${u} --pack-destination ${u}`);if(ce.stdout){a=g.default.join(u,ce.stdout.trim()),C.info("Created a tarball at %s",a);let tt=[`rm -rf ${u}/package.json`,`rm -rf ${u}/package-lock.json`,`rm -rf ${u}/endpoints`];H.default.exec(tt.join(";"),{cwd:u})}}else C.warn("Missing package.json file in %s",r);await(0,M.writeFile)(g.default.join(u,be),`${Date.now()}`),C.info("Module build complete in %d ms",Date.now()-o)}}else C.warn("No tsconfig.server.json file found. Please run init first.")}else C.info("No plugin modules to build");return{code:0,path:a}}var Ce=St;var N=d(require("fs-extra")),F=d(require("node:path")),re=d(require("shelljs"));var L=l("buildNext"),dt=async e=>{let t=await A(F.default.join(e,"src","**","*.component.json"));return Promise.all(t.map(async n=>({path:n,descriptor:await N.default.readJson(n)})))},gt=async(e,t)=>{let n={};return await Promise.all(t.map(async a=>{let{descriptor:o,path:r}=a,s=`./${o.id}`,i=F.default.dirname(r),p=F.default.join(i,"Component.tsx");await(0,N.pathExists)(p)||(p=F.default.join(i,`${s}.tsx`)),await(0,N.pathExists)(p)?(L.debug(`React component found at path ${p} for descriptor at path ${r}`),Object.assign(n,{[s]:`./${F.default.relative(e,p)}`})):L.error("No React component found at path %s for descriptor at path %s",p,r)})),n};async function Ae(e,t){let n=await dt(e),a=await gt(e,n);return L.info("Federation config is %O",a),await N.default.writeJSON(F.default.join(e,"federation.config.json"),{name:"auroraComponents"+(t?"Local":""),exposes:a,extraOptions:{debug:!1}}),n}async function Mt(e){re.default.env.NEXT_PRIVATE_LOCAL_WEBPACK="true";let t=`next build ${e}`;try{let n=re.default.exec(t,{async:!1,fatal:!0,cwd:e});return n.code>0&&L.error("Error in NextJS build"),{code:n.code}}catch(n){return L.error("Error running next command: %s",t,n?.message),{code:1}}}var Ee=Mt;var ne=d(require("node:path"));var Pe=l("changeSet");function It(){let e=process.env.CHANGE_SET;return e?.length>0?e.split(/[\s,]/):null}function bt(e){let t=e??It();if(t?.length>0){Pe.info("Parsing changeset: %O",t);let n=!1;t.some(r=>r.includes(ne.default.join("src","components")))&&(n=!0);let a=!1;t.some(r=>r.includes(ne.default.join("src","endpoints")))&&(a=!0),t.some(r=>r=="package.json"||r.startsWith(".github"))&&(n=!0,a=!0);let o={buildComponents:n,buildEndpoints:a};return Pe.info("Changeset result: %O",o),o}return null}var Re=bt;var ve=d(require("dotenv-flow")),xe=d(require("findup-sync")),oe=d(require("node:path")),fe=d(require("yargs")),Fe=require("yargs/helpers");var da=require("graphql-import-node"),Te=require("@urql/core");var Ia=l("GraphqlClient");var va=l("versionCheck");var O=l("cli");function At(){if(!global.sdkConfigLoaded){let e=(0,xe.default)(".env*");if(e){O.debug("Loading config from .env files: $s",e);let{error:t,parsed:n}=ve.default.config({path:oe.default.dirname(e)});t?(O.error(t,"Error reading config file"),process.exit(1)):O.info("Using config values: %O",n)}}global.sdkConfigLoaded=!0}function Et(e){let t=e.indexOf("node_modules");return t===1?e:e.slice(0,t-1)}function Pt(e,t,n,a,o){At(),(0,fe.default)((0,Fe.hideBin)(process.argv)).scriptName(e).options(a??{}).env("PLUGIN").usage("$0 [repoPath]").command("$0 [repoPath]",t,r=>{let s=Et(process.cwd());return r.positional("repoPath",{describe:"The full path to plugin root directory.",default:s,type:"string"})},async r=>{await n(r)}).check(async r=>{let{repoPath:s}=r;if(!s)throw new Error("No plugin repository path found. Please either pass it as an argument to this process or specify it in your .env file as PLUGIN_REPO_PATH. ");if(!oe.default.isAbsolute(s))throw new Error("The plugin repository path must be a full (not relative) path.");return o?await o(r):!0}).help().showHelpOnFail(!1).fail((r,s)=>{s?O.error(s.message):O.error(r),process.exit(1)}).parse()}var he=Pt;var Ue=d(Oe()),Ve=require("fs-extra"),K=d(require("node:path"));var W=l("compress");async function Bt(e,t){let n=K.default.isAbsolute(t)?t:K.default.join(e,t),a=K.default.join(n,"mf");if(await(0,Ve.pathExists)(a)){W.info("Compressing assets in %s",a);try{await(0,Ue.default)({dirs:[a]}),W.info("Compressing assets complete")}catch(o){W.error(o,"Error compressing assets")}}else W.info("No mf assets to compress")}var we=Bt;var U=d(require("node:path")),ke=d(require("shelljs"));var j=l("format");function Lt(e,t){j.info("Formatting plugin directory: %s",t);let n=e==="format:fix"?"--write":"--check",a=`prettier --config ${U.default.join(t,".prettierrc.js")} --ignore-path ${U.default.join(t,".prettierignore")} ${n} ${U.default.join(t,"res")} ${U.default.join(t,"src")} `;j.debug(a);let o=ke.default.exec(a,{cwd:t});return o.code>0?j.warn("Formatting errors found for plugin at %s",t):j.info("Formatting complete for plugin at %s",t),o.code}var qe=Lt;var c=require("fs-extra"),y=d(require("node:path"));var V=l("setup"),Ot={hooks:{"pre-commit":"npm run precommit","post-commit":"git update-index --again"}},Ut={"**/*.{js,jsx,ts,tsx,css,scss,pcss,json}":["prettier --write"],"**/*.{js,ts,tsx}":["eslint --fix --ignore-pattern '!.eslintrc.js' --ignore-pattern '!.prettierrc.js'"]},E=y.default.resolve(__dirname,y.default.join("..")),Vt=y.default.join(E,"templates");async function Ge(e){return(await(0,c.readFile)(e)).toString().split(`
2
+ `).map(n=>n.trim())}async function wt(e,t){let n=y.default.join(e,"package.json");if(await(0,c.pathExists)(n)){let a=await(0,c.readJson)(n,"utf8"),r=(await(0,c.readJson)(y.default.join(E,"package.json"))).name;if(t&&!a.devDependencies[r]&&!a.dependencies[r])V.warn("SDK not found as a dependency of package.json file at %s. Skipping init step.",n);else{V.info("Initializing plugin directory %s",e),await(0,c.remove)(y.default.join(e,"app")),await(0,c.ensureDir)(y.default.join(e,"pages")),await(0,c.ensureDir)(y.default.join(e,"src"));async function s(p,S=!0){let u=y.default.join(Vt,p),I=p.replaceAll(".tmpl",""),m=y.default.join(e,I);if(V.debug(`Copying ${u} to ${m}`),await(0,c.copy)(u,m,{overwrite:S}),!S&&I.startsWith(".")&&I.endsWith("ignore")&&await(0,c.pathExists)(m)){let R=await Ge(m),P=await Ge(u);for(let T of P)R.includes(T)||R.push(T);await(0,c.writeFile)(m,R.filter(T=>!!T).join(`
3
+ `))}}let i={".env.local.tmpl":!1,".eslintignore.tmpl":!1,".eslintrc.tmpl.js":!1,".gitignore.tmpl":!1,".npmrc.tmpl":!0,".nvmrc.tmpl":!0,".prettierignore.tmpl":!1,".prettierrc.tmpl.js":!1,"tsconfig.server.tmpl.json":!0,"tsconfig.tmpl.json":!0,"babelModules.config.tmpl.json":!1};V.info(`Copying template files to the plugin at ${e}`),await Promise.all(Object.keys(i).map(async p=>{await s(p,i[p])})),a.workspaces=["src/**/*"],a.engines={node:">=18"},a.scripts||(a.scripts={}),a.scripts.start=`npm explore ${r} -- npm run start`,a.scripts["start:logger"]=`npm explore ${r} -- npm run start:logger`,a.scripts.dev=`npm explore ${r} -- npm run dev:plugin`,a.scripts.build=`npm explore ${r} -- npm run build:plugin`,a.scripts["build:graphql"]=`npm explore ${r} -- npm run build:graphql`,a.scripts.lint=`npm explore ${r} -- npm run lint:plugin`,a.scripts["lint:fix"]=`npm explore ${r} -- npm run lint:plugin:fix`,a.scripts.format=`npm explore ${r} -- npm run format:plugin`,a.scripts["format:fix"]=`npm explore ${r} -- npm run format:plugin:fix`,a.scripts.init=`npm explore ${r} -- npm run init:plugin`,a.scripts.validate=`npm explore ${r} -- npm run validate:plugin`,a.scripts.gen=`npm explore ${r} -- npm run gen`,a.scripts.precommit="lint-staged",a.husky=Ot,a["lint-staged"]=Ut,await(0,c.writeJson)(n,a,{spaces:" "}),await(0,c.copy)(y.default.join(E,"README.md"),y.default.join(e,"SDK.md"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"next.config.js"),y.default.join(e,"next.config.js"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"next.overrides.js"),y.default.join(e,"next.overrides.js"),{overwrite:!1}),await(0,c.copy)(y.default.join(E,"postcss.config.js"),y.default.join(e,"postcss.config.js"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"types","mf","index.d.ts"),y.default.join(e,"types","mf","aurora.d.ts"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"types","pkg","index.d.ts"),y.default.join(e,"types","pkg","aurora.d.ts"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"types","graphql.d.ts"),y.default.join(e,"types","graphql.d.ts"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"templates","pcss.d.ts.tmpl"),y.default.join(e,"types","pcss.d.ts"),{overwrite:!0}),await(0,c.copy)(y.default.join(E,"types","graphql-schema-types.ts"),y.default.join(e,"types","graphql-schema-types.ts"),{overwrite:!0})}}else V.warn("No package.json file found at %s. Skipping init step.",n)}var He=wt;var pe=d(require("node:path")),Qe=d(require("shelljs"));var We=require("fs-extra"),z=l("lintPlugin");async function kt(e,t){let n=pe.default.join(t,"src");if(await(0,We.pathExists)(n)){z.info("Linting plugin directory: %s",t);let a=e==="lint:fix"?"--fix --max-warnings=0":"",o=`eslint --ext .js --ext .jsx --ext .tsx --ext .ts --cache --config ${pe.default.join(t,".eslintrc.js")} --no-error-on-unmatched-pattern --ignore-pattern '**/types/*' ${a} ${n}`;z.debug(o);let r=Qe.default.exec(o,{fatal:!0,cwd:t});return r.code>0?z.error("Linting failed for plugin at %s",t):z.info("Linting complete for plugin at %s",t),r.code}return 0}var Ke=kt;var w=(r=>(r.Freemarker="FREEMARKER",r.Handlebars="HANDLEBARS",r.Html="HTML",r.Javascript="JAVASCRIPT",r.React="REACT",r))(w||{});var Y=(i=>(i.Delete="DELETE",i.Get="GET",i.Head="HEAD",i.Options="OPTIONS",i.Patch="PATCH",i.Post="POST",i.Put="PUT",i))(Y||{});var k=(r=>(r.Content="CONTENT",r.Custom="CUSTOM",r.People="PEOPLE",r.Places="PLACES",r.Texthtml="TEXTHTML",r))(k||{});var q=require("fs-extra"),b=d(require("node:path"));var J=(r=>(r.Json="JSON",r.Multipart="MULTIPART",r.MultipartFiles="MULTIPART_FILES",r.None="NONE",r.UrlEncoded="URL_ENCODED",r))(J||{});var je=d(require("fs-extra"));var Ya=l("fileUtils");function qt(e){return Promise.all(e.map(async t=>({path:t,descriptor:await je.default.readJson(t)})))}async function X(e){let t=await A(e);return qt(t)}var ue=require("fs-extra"),Ye=require("glob"),Je=require("minimatch"),D=d(require("node:path"));var ze={ReactComponent:["@fluentui/react-*","@coveo/atomic-react","@coveo/atomic","@coveo/headless-react","@coveo/headless","clone-deep","dateformat","isomorphic-dompurify","js-base64","lil-uri","moment-timezone","path-to-regexp","react","react-beautiful-dnd","react-bootstrap","react-hook-form","react-quill","react-select","react-uid","react-use","react-dropzone","sanitize-html","tabbable","tiny-lru","universal-cookie"],Endpoint:["brotli","clone-deep","cookie","dateformat","js-base64","jsonwebtoken","lil-uri","path-to-regexp","tiny-lru","universal-cookie"]};var Qt={async validatePackageDependencies(e,t,n=""){let{path:a}=e,o=D.default.dirname(a),r=D.default.join(o,"package.json"),s=[],i={allowedDependencies:[],disallowedDependencies:[]};if(t==="Endpoint"||t==="ReactComponent"){s=ze[t];let p=await(0,Ye.glob)("**/package.json",{cwd:D.default.join(n,"src"),ignore:[D.default.join(n,"src","endpoints","**","node_modules","**"),D.default.join(n,"src","components","**","node_modules","**")],absolute:!0}),S=await Promise.all(p.map(async u=>(await(0,ue.readJSON)(u)).name));await(0,ue.readJSON)(r).then(u=>(u.dependencies&&(i.allowedDependencies=[...s,...S],i.disallowedDependencies=Object.keys(u.dependencies).filter(I=>!i.allowedDependencies.some(m=>(0,Je.minimatch)(I,m)))),null))}return i}},Xe=Qt;var h=l("validationUtils"),Wt={validateCustomComponentDescriptor(e,t=[]){return e.id||t.push("Component id is missing or empty for descriptor: "+JSON.stringify(e)),e.markupLanguage?Object.values(w).includes(e.markupLanguage)||t.push("Component markupLanguage value is invalid for descriptor: "+JSON.stringify(e)+". Valid markupLanguage values are: "+JSON.stringify(Object.values(w))):t.push("Component markupLanguage field is missing for descriptor: "+JSON.stringify(e)+". Valid markupLanguage values are: "+JSON.stringify(Object.values(w))),e.grouping?Object.values(k).includes(e.grouping)||t.push("Component grouping value is invalid for descriptor: "+JSON.stringify(e)+". Valid grouping values are: "+JSON.stringify(Object.values(k))):t.push("Component grouping field is missing for descriptor: "+JSON.stringify(e)+". Valid grouping values are: "+JSON.stringify(Object.values(k))),!e.components||e.components.length===0?t.push('Missing "components" field for descriptor: '+JSON.stringify(e)):e.components.some(n=>`custom.widget.${e.id}`===n.id)||t.push(`Invalid "components" field for descriptor. Components field id should be "custom.widget.${e.id}": Descriptor is ${JSON.stringify(e)}`),t},validateReactComponentDescriptor(e,t=[]){return this.validateCustomComponentDescriptor(e,t),e.markupLanguage!="REACT"&&t.push('Component descriptor markup language must be "REACT" for descriptor: '+JSON.stringify(e)),t},validateEndpointDescriptor(e,t=[]){return e.id||t.push("Endpoint id field is missing or empty for descriptor: "+JSON.stringify(e)),e.bodyType&&!Object.values(J).includes(e.bodyType)&&t.push("Endpoint body type field is invalid for descriptor: "+JSON.stringify(e)+". Valid body types are: "+JSON.stringify(Object.values(J))),e.httpMethods&&e.httpMethods.some(n=>!Object.values(Y).includes(n))&&t.push("Endpoint httpMethods field is invalid for descriptor: "+JSON.stringify(e)+". Valid httpMethods are: "+JSON.stringify(Object.values(Y))),t},validateModule(e,t=[]){let{descriptor:n,path:a}=e,o=/\.(\w+)\.json/,r=b.default.basename(a).replace(o,""),s=o.exec(a);if(s.length<2)t.push("No descriptor type found");else{let[,i]=s,p=b.default.dirname(a),S=b.default.basename(p);S===i&&t.push(`A descriptor needs to go into its own directory under ${i}s at ${a}.`),r!=S?t.push(`Descriptor filename prefix (${r}) must match descriptor directory name (${S}) at ${a}`):n.id!=S&&t.push(`Descriptor id (${n.id}) must match descriptor directory name (${S}) at ${a}`)}return t},async validatePackageDescriptor(e,t,n="",a=!1,o=[]){let{path:r}=e,s=b.default.dirname(r),i=b.default.join(s,"package.json");if(!await(0,q.pathExists)(i))o.push(`No package descriptor (package.json) found in ${s}`);else{let p=await Xe.validatePackageDependencies(e,t,n);if(p.disallowedDependencies.length>0){let S=`Disallowed dependencies found in ${s}/package.json: ${p.disallowedDependencies.join(", ")}. Only the following dependencies are allowed: ${p.allowedDependencies.sort().join(", ")}`;a?h.warn(S):o.push(S)}}return o},async validateReactComponent(e,t,n=!1,a=[]){let{descriptor:o,path:r}=e;this.validateReactComponentDescriptor(o,a),this.validateModule(e,a),await this.validatePackageDescriptor(e,"ReactComponent",t,n,a);let s=b.default.dirname(r),i=b.default.join(s,"Component.tsx"),p=`${o.id}.tsx`;return await(0,q.pathExists)(i)||(i=b.default.join(s,p)),await(0,q.pathExists)(i)||a.push(`No valid React component (${p}) found in ${s}`),a},async validateEndpoint(e,t,n=!1,a=[]){let{descriptor:o,path:r}=e;this.validateEndpointDescriptor(o,a),this.validateModule(e,a),await this.validatePackageDescriptor(e,"Endpoint",t,n,a);let s=b.default.dirname(r),i=b.default.join(s,"index.ts");return await(0,q.pathExists)(i)||a.push(`No valid endpoint (index.ts) found in ${s}`),a},async validatePlugin(e,t=!1,n=!1,a=!1){h.info("Validating plugin files at %s...",e);let o=[];if(t){h.info("Validating component descriptors...");let r=await A(b.default.join(e,"res","components","*"));for await(let s of r){let i=await X(b.default.join(s,"*.component.json"));if(i.length===0)h.warn(`No component descriptor (<ComponentName>.component.json) found in ${s}`);else for(let p of i)this.validateCustomComponentDescriptor(p.descriptor,o),this.validateModule(p,o)}}if(n){h.info("Validating React components...");let r=await A(b.default.join(e,"src","components","*"));for await(let s of r){let i=await X(b.default.join(s,"*.component.json"));if(i.length===0)o.push(`No component descriptor (<ComponentName>.component.json) found in ${s}`);else for await(let p of i)await this.validateReactComponent(p,e,!1,o)}}if(a){h.info("Validating endpoints...");let r=await A(b.default.join(e,"src","endpoints","*"));for await(let s of r){let i=await X(b.default.join(s,"*.endpoint.json"));if(i.length===0)o.push(`No endpoint descriptor (<EndpointName>.endpoint.json) found in ${s}`);else for await(let p of i)await this.validateEndpoint(p,e,!1,o)}}return h.info(`Plugin files are validated. ${o.length===0?"No":o.length} error(s) found.`),o}},Ze=Wt;var Z=l("build");he("build:modules","Build the plugin modules",async({repoPath:e,outputDirectory:t,init:n,lint:a,format:o,changeSet:r,mf:s,pkg:i})=>{let p=Date.now();if(await(0,$e.pathExists)(t))try{Z.info("Cleaning output directory at %s",t),await(0,et.rimraf)(t)}catch(P){Z.error(P,"Error cleaning output directory at %s",t)}n===!0&&await He(e,!0);let S=Re(r),u=S?.buildComponents??s===!0,I=S?.buildEndpoints??i===!0,m=await Ze.validatePlugin(e,!(s===!1||i===!1),u,I);if(m.length>0){for(let P of m)Z.error("Validation Error: %s",P);throw new Error("Terminating build due to validation errors")}if(a===!0&&await Ke("lint",e)>0)throw new Error("Terminating build due to lint failure");if(o===!0&&qe("format",e),await Ie(e,u,u||I)>0)throw new Error("Terminating build due to failure in building graphql types");if(u)if(await Ae(e,!1),(await Ee(e)).code==0)await we(e,t);else throw new Error("Terminating build due to component build failure");if(I&&(await Ce(e,t)).code>0)throw new Error("Terminating build due to module build failure");Z.info("Plugin build complete in "+(Date.now()-p)+"ms")},{b:{alias:"branchName",demandOption:!1,default:"main",describe:'The branch to build. If not specified, "main" is assumed. This does not control the checked out files but adds an additional branch segment to the S3 file key',type:"string"},c:{alias:"changeSet",demandOption:!1,describe:"A set of changed files. If not specified, all components and middlewares in the plugin will be built. If specified, only components and middlewares with changed files will be built.",type:"array"},o:{alias:"outputDirectory",demandOption:!1,default:"dist",describe:'The output directory. If not specified, "dist" is assumed. This is where the build artifacts will be placed.',type:"string"},i:{alias:"init",demandOption:!1,default:!1,describe:"Whether to init the plugin as part of the build process",type:"boolean"},l:{alias:"lint",demandOption:!1,default:!0,describe:"Whether to run lint as part of the build process.",type:"boolean"},f:{alias:"format",demandOption:!1,default:!1,describe:"Whether to run format as part of the build process.",type:"boolean"},m:{alias:"mf",demandOption:!1,default:!0,describe:"Whether to build the module federation (mf) artifacts.",type:"boolean"},p:{alias:"pkg",demandOption:!1,default:!0,describe:"Whether to build the module (pkg) artifacts.",type:"boolean"}});