khoros-aurora-sdk 25.2.0-pre.2 → 25.2.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/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **25.2.0-pre.2**
4
4
 
5
- - Added validation for React component dependencies
5
+ - Added validation for react component dependencies
6
6
 
7
7
  **25.2.0-pre.1**
8
8
 
package/build-hash.txt CHANGED
@@ -1 +1 @@
1
- 890c9b8
1
+ 81d5efb
@@ -2074,6 +2074,8 @@ type CommunityPolicies {
2074
2074
  canAccessCWAEditorNotificationSetting: PolicyResult!
2075
2075
  "Whether the current logged user can access CWA publisher notification setting for blogs and tkb."
2076
2076
  canAccessCWAPublisherNotificationSetting: PolicyResult!
2077
+ "Whether the current logged user can see rules cards."
2078
+ canViewRules: PolicyResult!
2077
2079
  }
2078
2080
 
2079
2081
  """
@@ -160,6 +160,8 @@ enum MailTemplateName {
160
160
  REGISTRATION_CONFIRM
161
161
  SOLUTION_TO_QUESTION
162
162
  USER_RANK_CHANGE
163
+ CWA_NOTIFICATION
164
+ CO_AUTHOR_NOTIFICATION
163
165
  }
164
166
 
165
167
  """
@@ -3374,12 +3374,14 @@ enum ReplyType {
3374
3374
  Represents the result of a call to mark/unmark message as solution.
3375
3375
  """
3376
3376
  type SolutionResponse {
3377
+ "The result of the mutation. Will be null if there are any errors. Will be true if the mutation was successful."
3378
+ result: Boolean
3377
3379
  "Any errors that occurred when trying to unmark/mark the solution."
3378
3380
  errors: [SolutionError!]
3379
3381
  }
3380
3382
 
3381
3383
  "A known error reason that can be returned by the mark/unmark mutation."
3382
- union SolutionError = PermissionDeniedError
3384
+ union SolutionError = PermissionDeniedError | TopicAlreadySolvedError | MessageAlreadySolvedError
3383
3385
 
3384
3386
  """
3385
3387
  Defines data about a message that is an accepted solution.
@@ -4430,6 +4432,24 @@ type FreezeEditsAlreadySetError implements Error {
4430
4432
  fields: [String]!
4431
4433
  }
4432
4434
 
4435
+ type TopicAlreadySolvedError implements Error {
4436
+ "The localized message of the error."
4437
+ message: String!
4438
+ "The key of the error message."
4439
+ key: String!
4440
+ "Any fields to map this error to."
4441
+ fields: [String]!
4442
+ }
4443
+
4444
+ type MessageAlreadySolvedError implements Error {
4445
+ "The localized message of the error."
4446
+ message: String!
4447
+ "The key of the error message."
4448
+ key: String!
4449
+ "Any fields to map this error to."
4450
+ fields: [String]!
4451
+ }
4452
+
4433
4453
  "A known error reason that can be returned by the moveMessage mutation."
4434
4454
  union MoveMessageError =
4435
4455
  MoveMessageFailedError
@@ -1139,6 +1139,8 @@ input TopicsConstraints {
1139
1139
  nodeIds: IDEqListNotEqlListConstraint
1140
1140
  "Conversation style filter."
1141
1141
  conversationStyle: ConversationStyleEqlInConstraint
1142
+ "Conversation UId constraint."
1143
+ conversationUIds: IDEqListNotEqlListConstraint
1142
1144
  "Interval to fetch chart data at desired time granularity."
1143
1145
  interval: Interval
1144
1146
  "Flag to use the pre-aggregated data."
@@ -0,0 +1,76 @@
1
+ extend type Query {
2
+ rules: [Rule!]!
3
+ }
4
+
5
+ enum Operator {
6
+ EQUAL_TO
7
+ NOT_EQUAL_TO
8
+ GREATER_THAN
9
+ GREATER_THAN_OR_EQUALS
10
+ LESS_THAN
11
+ LESS_THAN_OR_EQUALS
12
+ }
13
+
14
+ enum ActionType {
15
+ ASSIGN_ROLE
16
+ CREATE_FOLLOW
17
+ }
18
+
19
+ enum Trigger {
20
+ USER_REGISTERS
21
+ }
22
+
23
+ enum InvalidConditionReason {
24
+ VALUE_NOT_SPECIFIED
25
+ INVALID_VALUE
26
+ }
27
+
28
+ enum InvalidActionReason {
29
+ ROLE_DOES_NOT_EXIST
30
+ }
31
+
32
+ interface Condition {
33
+ name: String!
34
+ operator: Operator!
35
+ }
36
+
37
+ type InvalidCondition implements Condition {
38
+ name: String!
39
+ operator: Operator!
40
+ value: String!
41
+ reason: InvalidConditionReason!
42
+ }
43
+
44
+ type EmailDomainCondition implements Condition {
45
+ name: String!
46
+ operator: Operator!
47
+ value: String!
48
+ }
49
+
50
+ interface Action {
51
+ name: String!
52
+ }
53
+
54
+ type AssignRoleAction implements Action {
55
+ name: String!
56
+ value: Role!
57
+ }
58
+
59
+ type InvalidAction implements Action {
60
+ name: String!
61
+ value: String!
62
+ type: ActionType!
63
+ reason: InvalidConditionReason!
64
+ }
65
+
66
+ type Rule {
67
+ id: ID!
68
+ name: String!
69
+ description: String
70
+ enabled: Boolean!
71
+ createdAt: DateTime!
72
+ createdBy: User
73
+ conditions: [[Condition!]!]!
74
+ actions: [Action!]!
75
+ trigger: Trigger!
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "khoros-aurora-sdk",
3
- "version": "25.2.0-pre.2",
3
+ "version": "25.2.0",
4
4
  "author": "Khoros, LLC",
5
5
  "keywords": [
6
6
  "Khoros_Aurora_SDK",
@@ -1,3 +1,3 @@
1
- "use strict";var tt=Object.create;var de=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,a,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of rt(t))!ot.call(e,o)&&o!==a&&de(e,o,{get:()=>t[o],enumerable:!(n=at(t,o))||n.enumerable});return e};var S=(e,t,a)=>(a=e!=null?tt(nt(e)):{},it(t||!e||!e.__esModule?de(a,"default",{value:e,enumerable:!0}):a,e));var Oe=st((La,Le)=>{"use strict";var Pt=require("brotli"),f=require("node:fs"),Rt=require("node:zlib"),Tt=require("node:path"),ie=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=ie.promisify(f.writeFile),pe=ie.promisify(f.stat),ft=ie.promisify(f.readFile),De=function(e,t){let a=[];return f.readdir(e,(n,o)=>{if(n)return t(n);let r=o.length;if(!r)return t(null,a);o.forEach(s=>{s=Tt.resolve(e,s),f.stat(s,(i,p)=>{p&&p.isDirectory()?De(s,(d,u)=>{a=a.concat(u),--r||t(null,a)}):(a.push(s),--r||t(null,a))})})})},Q=e=>e/1e3,Ft=async(e,t,a)=>new Promise(async n=>{let o=Pt.compress(await ft(e),Ne);if(o===null)return n(W(`${e}.br`,"result",t));let r=o.length/t,s=!1;try{await pe(`${e}.br`),s=!1}catch{s=!0}return r>a.minRatio&&s===!0?n(W(`${e}.br`,"ratio",t,o.length)):(await xt(`${e}.br`,o),n(Be(`${e}.br`,t,o.length)))}),ht=(e,t,a)=>new Promise(n=>{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 pe(`${e}.gz`);if(i.size/t>a.minRatio){let d=W(`${e}.gz`,"ratio",t,i.size);f.unlink(`${e}.gz`,()=>{}),n(d)}else{let d=Be(`${e}.gz`,t,i.size);n(d)}}).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 a=await pe(e),{size:n}=a;if(n<t.threshold)return W(e,"size",n),{filePath:e,skipped:!0,brotli:null,gzip:null};let o=await ht(e,n,t);t.onGzipProcessed&&t.onGzipProcessed(o);let r=await Ft(e,n,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,a,n){let o=a/t,s=`${o*100}% == ${Q(t)}kB -> ${Q(a)}kB`;return console.log(`[done] ${e}: ${s}`),{filePath:e,initialSize:t,compressedSize:a,type:n,ratio:o}}var W=(e,t,a,n)=>{let o=n/a,r=o*100;return console.log(`[skip:${t}] ${e}: ${Q(a)}kB${n?` -> ${Q(n)}kB (ratio ${o}%)`:""}`),{filePath:e,initialSize:a,compressedSize:n||null,ratio:o||null,ratioPercent:r||null}},Nt=async e=>{e={...vt,...e};let t=[];return e.dirs.forEach(a=>{De(a,(n,o)=>{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 ge=S(require("pino")),pt=(0,ge.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"),h=S(require("node:path")),Ie=S(require("shelljs"));var ut=S(require("fs-extra")),ee=S(require("node:path"));var Me=require("glob");var zt=l("filePathHelper");function A(e,t){return(0,Me.glob)(e?.replaceAll(ee.default.sep,ee.default.posix.sep),t)}var B=l("graphql-types");async function lt(e,t,a){B.info("Building graphql types for plugin directory: %s",e);let n=t&&a?"**":t?"components":"endpoints",o=await A(h.default.join(e,"src",n,"**","package.json"));return(await Promise.all(o.map(async s=>{let i=h.default.dirname(s),p=await A(h.default.join(i,"**","*.graphql"));if(p.length>0){B.debug("Building types types for graphql files: %s",p);let d=h.default.join(i,"types","codegen.json");try{await(0,G.copy)(h.default.join(__dirname,"..","types","codegen.json"),d);let u="graphql-codegen --config ./types/codegen.json ";B.debug(u);let I=Ie.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)(d)}}}))).find(s=>s>0)??0}var be=lt;var me="build-time.txt",te="@khoros/endpoints",ae="1.0.0",yt=te.slice(1).replaceAll("/","-"),$t=`${yt}-${ae}.tgz`;var M=require("fs-extra"),g=S(require("node:path")),H=S(require("shelljs"));var Ce=require("node:fs/promises"),C=l("buildModules");function re(e,t,a){return`babel ${e} --ignore 'types/*.ts' --copy-files --config-file ${t} --out-dir ${a} --extensions ".ts"`}async function ct(e,t,a){let n=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 d=g.default.isAbsolute(t)?t:g.default.join(e,t);C.debug(`Output directory is ${d}`);let u=g.default.join(d,"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,Ce.readdir)(R);for(let x of v)C.info("Compiling shared package %s...",x),m.push(re(g.default.join(R,x),p,g.default.join(u,"shared",x)))}if(a&&a.size>0)for(let v of a)C.info("Compiling endpoint %s...",v),m.push(re(g.default.join(s,v),p,g.default.join(I,v)));else C.info("Compiling all modules..."),m.push(re(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=te,x.version=ae,await(0,M.writeJSON)(g.default.join(u,"package.json"),x);let ye=g.default.join(e,"package-lock.json"),ce=g.default.join(e,"src","shared");await(0,M.pathExists)(ce)&&(C.info("Copying /src/shared directory into output bundle"),await(0,M.copy)(ce,g.default.join(u,"shared"),{overwrite:!0})),await(0,M.pathExists)(ye)&&await(0,M.copy)(ye,g.default.join(u,"package-lock.json"),{errorOnExist:!1}),C.debug(`Creating a tarball in ${u}`);let Se=H.default.exec(`npm pack ${u} --pack-destination ${u}`);if(Se.stdout){n=g.default.join(u,Se.stdout.trim()),C.info("Created a tarball at %s",n);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,me),`${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:n}}var Ae=ct;var _=S(require("fs-extra")),F=S(require("node:path")),ne=S(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 a=>({path:a,descriptor:await _.default.readJson(a)})))},dt=async(e,t)=>{let a={};return await Promise.all(t.map(async n=>{let{descriptor:o,path:r}=n,s=`./${o.id}`,i=F.default.dirname(r),p=F.default.join(i,"Component.tsx");await(0,_.pathExists)(p)||(p=F.default.join(i,`${s}.tsx`)),await(0,_.pathExists)(p)?(L.debug(`React component found at path ${p} for descriptor at path ${r}`),Object.assign(a,{[s]:`./${F.default.relative(e,p)}`})):L.error("No React component found at path %s for descriptor at path %s",p,r)})),a};async function Ee(e,t){let a=await St(e),n=await dt(e,a);return L.info("Federation config is %O",n),await _.default.writeJSON(F.default.join(e,"federation.config.json"),{name:"auroraComponents"+(t?"Local":""),exposes:n,extraOptions:{debug:!1}}),a}async function gt(e){ne.default.env.NEXT_PRIVATE_LOCAL_WEBPACK="true";let t=`next build ${e}`;try{let a=ne.default.exec(t,{async:!1,fatal:!0,cwd:e});return a.code>0&&L.error("Error in NextJS build"),{code:a.code}}catch(a){return L.error("Error running next command: %s",t,a?.message),{code:1}}}var Pe=gt;var oe=S(require("node:path"));var Re=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){Re.info("Parsing changeset: %O",t);let a=!1;t.some(r=>r.includes(oe.default.join("src","components")))&&(a=!0);let n=!1;t.some(r=>r.includes(oe.default.join("src","endpoints")))&&(n=!0),t.some(r=>r=="package.json"||r.startsWith(".github"))&&(a=!0,n=!0);let o={buildComponents:a,buildEndpoints:n};return Re.info("Changeset result: %O",o),o}return null}var Te=It;var xe=S(require("dotenv-flow")),fe=S(require("findup-sync")),se=S(require("node:path")),Fe=S(require("yargs")),he=require("yargs/helpers");var Sa=require("graphql-import-node"),ve=require("@urql/core");var Ma=l("GraphqlClient");var Ta=l("versionCheck");var O=l("cli");function Ct(){if(!global.sdkConfigLoaded){let e=(0,fe.default)(".env*");if(e){O.debug("Loading config from .env files: $s",e);let{error:t,parsed:a}=xe.default.config({path:se.default.dirname(e)});t?(O.error(t,"Error reading config file"),process.exit(1)):O.info("Using config values: %O",a)}}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,a,n,o){Ct(),(0,Fe.default)((0,he.hideBin)(process.argv)).scriptName(e).options(n??{}).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 a(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(!se.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 _e=Et;var Ue=S(Oe()),Ve=require("fs-extra"),j=S(require("node:path"));var K=l("compress");async function Dt(e,t){let a=j.default.isAbsolute(t)?t:j.default.join(e,t),n=j.default.join(a,"mf");if(await(0,Ve.pathExists)(n)){K.info("Compressing assets in %s",n);try{await(0,Ue.default)({dirs:[n]}),K.info("Compressing assets complete")}catch(o){K.error(o,"Error compressing assets")}}else K.info("No mf assets to compress")}var we=Dt;var U=S(require("node:path")),ke=S(require("shelljs"));var z=l("format");function Bt(e,t){z.info("Formatting plugin directory: %s",t);let a=e==="format:fix"?"--write":"--check",n=`prettier --config ${U.default.join(t,".prettierrc.js")} --ignore-path ${U.default.join(t,".prettierignore")} ${a} ${U.default.join(t,"res")} ${U.default.join(t,"src")} `;z.debug(n);let o=ke.default.exec(n,{cwd:t});return o.code>0?z.warn("Formatting errors found for plugin at %s",t):z.info("Formatting complete for plugin at %s",t),o.code}var qe=Bt;var c=require("fs-extra"),y=S(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(`
1
+ "use strict";var tt=Object.create;var de=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,a,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of rt(t))!ot.call(e,o)&&o!==a&&de(e,o,{get:()=>t[o],enumerable:!(n=at(t,o))||n.enumerable});return e};var S=(e,t,a)=>(a=e!=null?tt(nt(e)):{},it(t||!e||!e.__esModule?de(a,"default",{value:e,enumerable:!0}):a,e));var Oe=st((La,Le)=>{"use strict";var Pt=require("brotli"),f=require("node:fs"),Rt=require("node:zlib"),Tt=require("node:path"),ie=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=ie.promisify(f.writeFile),pe=ie.promisify(f.stat),ft=ie.promisify(f.readFile),De=function(e,t){let a=[];return f.readdir(e,(n,o)=>{if(n)return t(n);let r=o.length;if(!r)return t(null,a);o.forEach(s=>{s=Tt.resolve(e,s),f.stat(s,(i,p)=>{p&&p.isDirectory()?De(s,(d,u)=>{a=a.concat(u),--r||t(null,a)}):(a.push(s),--r||t(null,a))})})})},Q=e=>e/1e3,Ft=async(e,t,a)=>new Promise(async n=>{let o=Pt.compress(await ft(e),Ne);if(o===null)return n(W(`${e}.br`,"result",t));let r=o.length/t,s=!1;try{await pe(`${e}.br`),s=!1}catch{s=!0}return r>a.minRatio&&s===!0?n(W(`${e}.br`,"ratio",t,o.length)):(await xt(`${e}.br`,o),n(Be(`${e}.br`,t,o.length)))}),ht=(e,t,a)=>new Promise(n=>{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 pe(`${e}.gz`);if(i.size/t>a.minRatio){let d=W(`${e}.gz`,"ratio",t,i.size);f.unlink(`${e}.gz`,()=>{}),n(d)}else{let d=Be(`${e}.gz`,t,i.size);n(d)}}).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 a=await pe(e),{size:n}=a;if(n<t.threshold)return W(e,"size",n),{filePath:e,skipped:!0,brotli:null,gzip:null};let o=await ht(e,n,t);t.onGzipProcessed&&t.onGzipProcessed(o);let r=await Ft(e,n,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,a,n){let o=a/t,s=`${o*100}% == ${Q(t)}kB -> ${Q(a)}kB`;return console.log(`[done] ${e}: ${s}`),{filePath:e,initialSize:t,compressedSize:a,type:n,ratio:o}}var W=(e,t,a,n)=>{let o=n/a,r=o*100;return console.log(`[skip:${t}] ${e}: ${Q(a)}kB${n?` -> ${Q(n)}kB (ratio ${o}%)`:""}`),{filePath:e,initialSize:a,compressedSize:n||null,ratio:o||null,ratioPercent:r||null}},Nt=async e=>{e={...vt,...e};let t=[];return e.dirs.forEach(a=>{De(a,(n,o)=>{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 ge=S(require("pino")),pt=(0,ge.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"),h=S(require("node:path")),Ie=S(require("shelljs"));var ut=S(require("fs-extra")),ee=S(require("node:path"));var Me=require("glob");var zt=l("filePathHelper");function A(e,t){return(0,Me.glob)(e?.replaceAll(ee.default.sep,ee.default.posix.sep),t)}var B=l("graphql-types");async function lt(e,t,a){B.info("Building graphql types for plugin directory: %s",e);let n=t&&a?"**":t?"components":"endpoints",o=await A(h.default.join(e,"src",n,"**","package.json"));return(await Promise.all(o.map(async s=>{let i=h.default.dirname(s),p=await A(h.default.join(i,"**","*.graphql"));if(p.length>0){B.debug("Building types types for graphql files: %s",p);let d=h.default.join(i,"types","codegen.json");try{await(0,G.copy)(h.default.join(__dirname,"..","types","codegen.json"),d);let u="graphql-codegen --config ./types/codegen.json ";B.debug(u);let I=Ie.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)(d)}}}))).find(s=>s>0)??0}var be=lt;var me="build-time.txt",te="@khoros/endpoints",ae="1.0.0",yt=te.slice(1).replaceAll("/","-"),$t=`${yt}-${ae}.tgz`;var M=require("fs-extra"),g=S(require("node:path")),H=S(require("shelljs"));var Ce=require("node:fs/promises"),C=l("buildModules");function re(e,t,a){return`babel ${e} --ignore 'types/*.ts' --copy-files --config-file ${t} --out-dir ${a} --extensions ".ts"`}async function ct(e,t,a){let n=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 d=g.default.isAbsolute(t)?t:g.default.join(e,t);C.debug(`Output directory is ${d}`);let u=g.default.join(d,"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,Ce.readdir)(R);for(let x of v)C.info("Compiling shared package %s...",x),m.push(re(g.default.join(R,x),p,g.default.join(u,"shared",x)))}if(a&&a.size>0)for(let v of a)C.info("Compiling endpoint %s...",v),m.push(re(g.default.join(s,v),p,g.default.join(I,v)));else C.info("Compiling all modules..."),m.push(re(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=te,x.version=ae,await(0,M.writeJSON)(g.default.join(u,"package.json"),x);let ye=g.default.join(e,"package-lock.json"),ce=g.default.join(e,"src","shared");await(0,M.pathExists)(ce)&&(C.info("Copying /src/shared directory into output bundle"),await(0,M.copy)(ce,g.default.join(u,"shared"),{overwrite:!0})),await(0,M.pathExists)(ye)&&await(0,M.copy)(ye,g.default.join(u,"package-lock.json"),{errorOnExist:!1}),C.debug(`Creating a tarball in ${u}`);let Se=H.default.exec(`npm pack ${u} --pack-destination ${u}`);if(Se.stdout){n=g.default.join(u,Se.stdout.trim()),C.info("Created a tarball at %s",n);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,me),`${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:n}}var Ae=ct;var _=S(require("fs-extra")),F=S(require("node:path")),ne=S(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 a=>({path:a,descriptor:await _.default.readJson(a)})))},dt=async(e,t)=>{let a={};return await Promise.all(t.map(async n=>{let{descriptor:o,path:r}=n,s=`./${o.id}`,i=F.default.dirname(r),p=F.default.join(i,"Component.tsx");await(0,_.pathExists)(p)||(p=F.default.join(i,`${s}.tsx`)),await(0,_.pathExists)(p)?(L.debug(`React component found at path ${p} for descriptor at path ${r}`),Object.assign(a,{[s]:`./${F.default.relative(e,p)}`})):L.error("No React component found at path %s for descriptor at path %s",p,r)})),a};async function Ee(e,t){let a=await St(e),n=await dt(e,a);return L.info("Federation config is %O",n),await _.default.writeJSON(F.default.join(e,"federation.config.json"),{name:"auroraComponents"+(t?"Local":""),exposes:n,extraOptions:{debug:!1}}),a}async function gt(e){ne.default.env.NEXT_PRIVATE_LOCAL_WEBPACK="true";let t=`next build ${e}`;try{let a=ne.default.exec(t,{async:!1,fatal:!0,cwd:e});return a.code>0&&L.error("Error in NextJS build"),{code:a.code}}catch(a){return L.error("Error running next command: %s",t,a?.message),{code:1}}}var Pe=gt;var oe=S(require("node:path"));var Re=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){Re.info("Parsing changeset: %O",t);let a=!1;t.some(r=>r.includes(oe.default.join("src","components")))&&(a=!0);let n=!1;t.some(r=>r.includes(oe.default.join("src","endpoints")))&&(n=!0),t.some(r=>r=="package.json"||r.startsWith(".github"))&&(a=!0,n=!0);let o={buildComponents:a,buildEndpoints:n};return Re.info("Changeset result: %O",o),o}return null}var Te=It;var xe=S(require("dotenv-flow")),fe=S(require("findup-sync")),se=S(require("node:path")),Fe=S(require("yargs")),he=require("yargs/helpers");var Sa=require("graphql-import-node"),ve=require("@urql/core");var Ma=l("GraphqlClient");var Ta=l("versionCheck");var O=l("cli");function Ct(){if(!global.sdkConfigLoaded){let e=(0,fe.default)(".env*");if(e){O.debug("Loading config from .env files: $s",e);let{error:t,parsed:a}=xe.default.config({path:se.default.dirname(e)});t?(O.error(t,"Error reading config file"),process.exit(1)):O.info("Using config values: %O",a)}}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,a,n,o){Ct(),(0,Fe.default)((0,he.hideBin)(process.argv)).scriptName(e).options(n??{}).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 a(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(!se.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 _e=Et;var Ue=S(Oe()),Ve=require("fs-extra"),j=S(require("node:path"));var K=l("compress");async function Dt(e,t){let a=j.default.isAbsolute(t)?t:j.default.join(e,t),n=j.default.join(a,"mf");if(await(0,Ve.pathExists)(n)){K.info("Compressing assets in %s",n);try{await(0,Ue.default)({dirs:[n]}),K.info("Compressing assets complete")}catch(o){K.error(o,"Error compressing assets")}}else K.info("No mf assets to compress")}var we=Dt;var U=S(require("node:path")),qe=S(require("shelljs"));var z=l("format");function Bt(e,t){z.info("Formatting plugin directory: %s",t);let a=e==="format:fix"?"--write":"--check",n=`prettier --config ${U.default.join(t,".prettierrc.js")} --ignore-path ${U.default.join(t,".prettierignore")} ${a} ${U.default.join(t,"res")} ${U.default.join(t,"src")} `;z.debug(n);let o=qe.default.exec(n,{cwd:t});return o.code>0?z.warn("Formatting errors found for plugin at %s",t):z.info("Formatting complete for plugin at %s",t),o.code}var ke=Bt;var c=require("fs-extra"),y=S(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
2
  `).map(a=>a.trim())}async function Vt(e,t){let a=y.default.join(e,"package.json");if(await(0,c.pathExists)(a)){let n=await(0,c.readJson)(a,"utf8"),r=(await(0,c.readJson)(y.default.join(E,"package.json"))).name;if(t&&!n.devDependencies[r]&&!n.dependencies[r])V.warn("SDK not found as a dependency of package.json file at %s. Skipping init step.",a);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,d=!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:d}),!d&&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])})),n.workspaces=["src/**/*"],n.engines={node:">=18"},n.scripts||(n.scripts={}),n.scripts.start=`npm explore ${r} -- npm run start`,n.scripts["start:logger"]=`npm explore ${r} -- npm run start:logger`,n.scripts.dev=`npm explore ${r} -- npm run dev:plugin`,n.scripts.build=`npm explore ${r} -- npm run build:plugin`,n.scripts["build:graphql"]=`npm explore ${r} -- npm run build:graphql`,n.scripts.lint=`npm explore ${r} -- npm run lint:plugin`,n.scripts["lint:fix"]=`npm explore ${r} -- npm run lint:plugin:fix`,n.scripts.format=`npm explore ${r} -- npm run format:plugin`,n.scripts["format:fix"]=`npm explore ${r} -- npm run format:plugin:fix`,n.scripts.init=`npm explore ${r} -- npm run init:plugin`,n.scripts.validate=`npm explore ${r} -- npm run validate:plugin`,n.scripts.gen=`npm explore ${r} -- npm run gen`,n.scripts.precommit="lint-staged",n.husky=Lt,n["lint-staged"]=Ot,await(0,c.writeJson)(a,n,{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.",a)}var He=Vt;var ue=S(require("node:path")),Qe=S(require("shelljs"));var We=require("fs-extra"),Y=l("lintPlugin");async function wt(e,t){let a=ue.default.join(t,"src");if(await(0,We.pathExists)(a)){Y.info("Linting plugin directory: %s",t);let n=e==="lint:fix"?"--fix --max-warnings=0":"",o=`eslint --ext .js --ext .jsx --ext .tsx --ext .ts --cache --config ${ue.default.join(t,".eslintrc.js")} --no-error-on-unmatched-pattern --ignore-pattern '**/types/*' ${n} ${a}`;Y.debug(o);let r=Qe.default.exec(o,{fatal:!0,cwd:t});return r.code>0?Y.error("Linting failed for plugin at %s",t):Y.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 J=(i=>(i.Delete="DELETE",i.Get="GET",i.Head="HEAD",i.Options="OPTIONS",i.Patch="PATCH",i.Post="POST",i.Put="PUT",i))(J||{});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=S(require("node:path"));var X=(r=>(r.Json="JSON",r.Multipart="MULTIPART",r.MultipartFiles="MULTIPART_FILES",r.None="NONE",r.UrlEncoded="URL_ENCODED",r))(X||{});var je=S(require("fs-extra"));var za=l("fileUtils");function kt(e){return Promise.all(e.map(async t=>({path:t,descriptor:await je.default.readJson(t)})))}async function Z(e){let t=await A(e);return kt(t)}var le=require("fs-extra"),Ye=require("glob"),N=S(require("node:path"));var ze={ReactComponent:["react","react-bootstrap","react-hook-form","react-uid","react-dropzone","moment-timezone","@coveo/atomic-react","@coveo/atomic","@coveo/headless-react","@coveo/headless"],Endpoint:["brotli","clone-deep","cookie","dateformat","js-base64","jsonwebtoken","lil-uri","path-to-regexp","tiny-lru","universal-cookie"]};var Ht={async validatePackageDependencies(e,t,a=""){let{path:n}=e,o=N.default.dirname(n),r=N.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:N.default.join(a,"src"),ignore:[N.default.join(a,"src","endpoints","**","node_modules","**"),N.default.join(a,"src","components","**","node_modules","**")],absolute:!0}),d=await Promise.all(p.map(async u=>(await(0,le.readJSON)(u)).name));await(0,le.readJSON)(r).then(u=>(u.dependencies&&(i.allowedDependencies=[...s,...d],i.disallowedDependencies=Object.keys(u.dependencies).filter(I=>!i.allowedDependencies.includes(I))),null))}return i}},Je=Ht;var D=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(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(a=>`custom.widget.${e.id}`===a.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(X).includes(e.bodyType)&&t.push("Endpoint body type field is invalid for descriptor: "+JSON.stringify(e)+". Valid body types are: "+JSON.stringify(Object.values(X))),e.httpMethods&&e.httpMethods.some(a=>!Object.values(J).includes(a))&&t.push("Endpoint httpMethods field is invalid for descriptor: "+JSON.stringify(e)+". Valid httpMethods are: "+JSON.stringify(Object.values(J))),t},validateModule(e,t=[]){let{descriptor:a,path:n}=e,o=/\.(\w+)\.json/,r=b.default.basename(n).replace(o,""),s=o.exec(n);if(s.length<2)t.push("No descriptor type found");else{let[,i]=s,p=b.default.dirname(n),d=b.default.basename(p);d===i&&t.push(`A descriptor needs to go into its own directory under ${i}s at ${n}.`),r!=d?t.push(`Descriptor filename prefix (${r}) must match descriptor directory name (${d}) at ${n}`):a.id!=d&&t.push(`Descriptor id (${a.id}) must match descriptor directory name (${d}) at ${n}`)}return t},async validatePackageDescriptor(e,t,a="",n=[]){let{path:o}=e,r=b.default.dirname(o),s=b.default.join(r,"package.json");if(!await(0,q.pathExists)(s))n.push(`No package descriptor (package.json) found in ${r}`);else{let i=await Je.validatePackageDependencies(e,t,a);i.disallowedDependencies.length>0&&n.push(`Disallowed dependencies found in ${r}/package.json: ${i.disallowedDependencies.join(", ")}. Only the following dependencies are allowed: ${i.allowedDependencies.join(", ")}`)}return n},async validateReactComponent(e,t,a=[]){let{descriptor:n,path:o}=e;this.validateReactComponentDescriptor(n,a),this.validateModule(e,a),await this.validatePackageDescriptor(e,"ReactComponent",t,a);let r=b.default.dirname(o),s=b.default.join(r,"Component.tsx"),i=`${n.id}.tsx`;return await(0,q.pathExists)(s)||(s=b.default.join(r,i)),await(0,q.pathExists)(s)||a.push(`No valid React component (${i}) found in ${r}`),a},async validateEndpoint(e,t,a=[]){let{descriptor:n,path:o}=e;this.validateEndpointDescriptor(n,a),this.validateModule(e,a),await this.validatePackageDescriptor(e,"Endpoint",t,a);let r=b.default.dirname(o),s=b.default.join(r,"index.ts");return await(0,q.pathExists)(s)||a.push(`No valid endpoint (index.ts) found in ${r}`),a},async validatePlugin(e,t=!1,a=!1,n=!1){D.info("Validating plugin files at %s...",e);let o=[];if(t){D.info("Validating component descriptors...");let r=await A(b.default.join(e,"res","components","*"));for await(let s of r){let i=await Z(b.default.join(s,"*.component.json"));if(i.length===0)D.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(a){D.info("Validating React components...");let r=await A(b.default.join(e,"src","components","*"));for await(let s of r){let i=await Z(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,o)}}if(n){D.info("Validating endpoints...");let r=await A(b.default.join(e,"src","endpoints","*"));for await(let s of r){let i=await Z(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,o)}}return D.info(`Plugin files are validated. ${o.length===0?"No":o.length} error(s) found.`),o}},Xe=Qt;var $=l("build");_e("build:modules","Build the plugin modules",async({repoPath:e,outputDirectory:t,init:a,lint:n,format:o,changeSet:r,mf:s,pkg:i})=>{let p=Date.now();if(await(0,Ze.pathExists)(t))try{$.info("Cleaning output directory at %s",t),await(0,$e.rimraf)(t)}catch(P){$.error(P,"Error cleaning output directory at %s",t)}a===!0&&await He(e,!0);let d=Te(r),u=d?.buildComponents??s===!0,I=d?.buildEndpoints??i===!0,m=await Xe.validatePlugin(e,!(s===!1||i===!1),u,I);if(m.length>0){for(let P of m)$.error("Validation Error: %s",P);throw new Error("Terminating build due to validation errors")}if(n===!0&&await Ke("lint",e)>0)throw new Error("Terminating build due to lint failure");if(o===!0&&qe("format",e),await be(e,u,u||I)>0)throw new Error("Terminating build due to failure in building graphql types");if(u)if(await Ee(e,!1),(await Pe(e)).code==0)await we(e,t);else throw new Error("Terminating build due to component build failure");if(I&&(await Ae(e,t)).code>0)throw new Error("Terminating build due to module build failure");$.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"}});
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])})),n.workspaces=["src/**/*"],n.engines={node:">=18"},n.scripts||(n.scripts={}),n.scripts.start=`npm explore ${r} -- npm run start`,n.scripts["start:logger"]=`npm explore ${r} -- npm run start:logger`,n.scripts.dev=`npm explore ${r} -- npm run dev:plugin`,n.scripts.build=`npm explore ${r} -- npm run build:plugin`,n.scripts["build:graphql"]=`npm explore ${r} -- npm run build:graphql`,n.scripts.lint=`npm explore ${r} -- npm run lint:plugin`,n.scripts["lint:fix"]=`npm explore ${r} -- npm run lint:plugin:fix`,n.scripts.format=`npm explore ${r} -- npm run format:plugin`,n.scripts["format:fix"]=`npm explore ${r} -- npm run format:plugin:fix`,n.scripts.init=`npm explore ${r} -- npm run init:plugin`,n.scripts.validate=`npm explore ${r} -- npm run validate:plugin`,n.scripts.gen=`npm explore ${r} -- npm run gen`,n.scripts.precommit="lint-staged",n.husky=Lt,n["lint-staged"]=Ot,await(0,c.writeJson)(a,n,{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.",a)}var He=Vt;var ue=S(require("node:path")),Qe=S(require("shelljs"));var We=require("fs-extra"),Y=l("lintPlugin");async function wt(e,t){let a=ue.default.join(t,"src");if(await(0,We.pathExists)(a)){Y.info("Linting plugin directory: %s",t);let n=e==="lint:fix"?"--fix --max-warnings=0":"",o=`eslint --ext .js --ext .jsx --ext .tsx --ext .ts --cache --config ${ue.default.join(t,".eslintrc.js")} --no-error-on-unmatched-pattern --ignore-pattern '**/types/*' ${n} ${a}`;Y.debug(o);let r=Qe.default.exec(o,{fatal:!0,cwd:t});return r.code>0?Y.error("Linting failed for plugin at %s",t):Y.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 J=(i=>(i.Delete="DELETE",i.Get="GET",i.Head="HEAD",i.Options="OPTIONS",i.Patch="PATCH",i.Post="POST",i.Put="PUT",i))(J||{});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=S(require("node:path"));var X=(r=>(r.Json="JSON",r.Multipart="MULTIPART",r.MultipartFiles="MULTIPART_FILES",r.None="NONE",r.UrlEncoded="URL_ENCODED",r))(X||{});var je=S(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 Z(e){let t=await A(e);return qt(t)}var le=require("fs-extra"),Ye=require("glob"),N=S(require("node:path"));var ze={ReactComponent:["react","react-bootstrap","react-hook-form","react-uid","react-dropzone","moment-timezone","@coveo/atomic-react","@coveo/atomic","@coveo/headless-react","@coveo/headless"],Endpoint:["brotli","clone-deep","cookie","dateformat","js-base64","jsonwebtoken","lil-uri","path-to-regexp","tiny-lru","universal-cookie"]};var Ht={async validatePackageDependencies(e,t,a=""){let{path:n}=e,o=N.default.dirname(n),r=N.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:N.default.join(a,"src"),ignore:[N.default.join(a,"src","endpoints","**","node_modules","**"),N.default.join(a,"src","components","**","node_modules","**")],absolute:!0}),d=await Promise.all(p.map(async u=>(await(0,le.readJSON)(u)).name));await(0,le.readJSON)(r).then(u=>(u.dependencies&&(i.allowedDependencies=[...s,...d],i.disallowedDependencies=Object.keys(u.dependencies).filter(I=>!i.allowedDependencies.includes(I))),null))}return i}},Je=Ht;var D=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(a=>`custom.widget.${e.id}`===a.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(X).includes(e.bodyType)&&t.push("Endpoint body type field is invalid for descriptor: "+JSON.stringify(e)+". Valid body types are: "+JSON.stringify(Object.values(X))),e.httpMethods&&e.httpMethods.some(a=>!Object.values(J).includes(a))&&t.push("Endpoint httpMethods field is invalid for descriptor: "+JSON.stringify(e)+". Valid httpMethods are: "+JSON.stringify(Object.values(J))),t},validateModule(e,t=[]){let{descriptor:a,path:n}=e,o=/\.(\w+)\.json/,r=b.default.basename(n).replace(o,""),s=o.exec(n);if(s.length<2)t.push("No descriptor type found");else{let[,i]=s,p=b.default.dirname(n),d=b.default.basename(p);d===i&&t.push(`A descriptor needs to go into its own directory under ${i}s at ${n}.`),r!=d?t.push(`Descriptor filename prefix (${r}) must match descriptor directory name (${d}) at ${n}`):a.id!=d&&t.push(`Descriptor id (${a.id}) must match descriptor directory name (${d}) at ${n}`)}return t},async validatePackageDescriptor(e,t,a="",n=[]){let{path:o}=e,r=b.default.dirname(o),s=b.default.join(r,"package.json");if(!await(0,k.pathExists)(s))n.push(`No package descriptor (package.json) found in ${r}`);else{let i=await Je.validatePackageDependencies(e,t,a);i.disallowedDependencies.length>0&&n.push(`Disallowed dependencies found in ${r}/package.json: ${i.disallowedDependencies.join(", ")}. Only the following dependencies are allowed: ${i.allowedDependencies.join(", ")}`)}return n},async validateReactComponent(e,t,a=[]){let{descriptor:n,path:o}=e;this.validateReactComponentDescriptor(n,a),this.validateModule(e,a),await this.validatePackageDescriptor(e,"ReactComponent",t,a);let r=b.default.dirname(o),s=b.default.join(r,"Component.tsx"),i=`${n.id}.tsx`;return await(0,k.pathExists)(s)||(s=b.default.join(r,i)),await(0,k.pathExists)(s)||a.push(`No valid React component (${i}) found in ${r}`),a},async validateEndpoint(e,t,a=[]){let{descriptor:n,path:o}=e;this.validateEndpointDescriptor(n,a),this.validateModule(e,a),await this.validatePackageDescriptor(e,"Endpoint",t,a);let r=b.default.dirname(o),s=b.default.join(r,"index.ts");return await(0,k.pathExists)(s)||a.push(`No valid endpoint (index.ts) found in ${r}`),a},async validatePlugin(e,t=!1,a=!1,n=!1){D.info("Validating plugin files at %s...",e);let o=[];if(t){D.info("Validating component descriptors...");let r=await A(b.default.join(e,"res","components","*"));for await(let s of r){let i=await Z(b.default.join(s,"*.component.json"));if(i.length===0)D.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(a){D.info("Validating React components...");let r=await A(b.default.join(e,"src","components","*"));for await(let s of r){let i=await Z(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,o)}}if(n){D.info("Validating endpoints...");let r=await A(b.default.join(e,"src","endpoints","*"));for await(let s of r){let i=await Z(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,o)}}return D.info(`Plugin files are validated. ${o.length===0?"No":o.length} error(s) found.`),o}},Xe=Qt;var $=l("build");_e("build:modules","Build the plugin modules",async({repoPath:e,outputDirectory:t,init:a,lint:n,format:o,changeSet:r,mf:s,pkg:i})=>{let p=Date.now();if(await(0,Ze.pathExists)(t))try{$.info("Cleaning output directory at %s",t),await(0,$e.rimraf)(t)}catch(P){$.error(P,"Error cleaning output directory at %s",t)}a===!0&&await He(e,!0);let d=Te(r),u=d?.buildComponents??s===!0,I=d?.buildEndpoints??i===!0,m=await Xe.validatePlugin(e,!(s===!1||i===!1),u,I);if(m.length>0){for(let P of m)$.error("Validation Error: %s",P);throw new Error("Terminating build due to validation errors")}if(n===!0&&await Ke("lint",e)>0)throw new Error("Terminating build due to lint failure");if(o===!0&&ke("format",e),await be(e,u,u||I)>0)throw new Error("Terminating build due to failure in building graphql types");if(u)if(await Ee(e,!1),(await Pe(e)).code==0)await we(e,t);else throw new Error("Terminating build due to component build failure");if(I&&(await Ae(e,t)).code>0)throw new Error("Terminating build due to module build failure");$.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"}});