@qoh/core-react 1.0.0-rc.10 → 1.0.0-rc.12

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/lib/index.js CHANGED
@@ -1,3 +1 @@
1
- "use strict";var te=Object.create;var v=Object.defineProperty,ne=Object.defineProperties,re=Object.getOwnPropertyDescriptor,oe=Object.getOwnPropertyDescriptors,ie=Object.getOwnPropertyNames,P=Object.getOwnPropertySymbols,se=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty,ae=Object.prototype.propertyIsEnumerable;var M=(n,e,t)=>e in n?v(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,b=(n,e)=>{for(var t in e||(e={}))Q.call(e,t)&&M(n,t,e[t]);if(P)for(var t of P(e))ae.call(e,t)&&M(n,t,e[t]);return n},A=(n,e)=>ne(n,oe(e));var F=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),ce=(n,e)=>{for(var t in e)v(n,t,{get:e[t],enumerable:!0})},U=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ie(e))!Q.call(n,o)&&o!==t&&v(n,o,{get:()=>e[o],enumerable:!(r=re(e,o))||r.enumerable});return n};var B=(n,e,t)=>(t=n!=null?te(se(n)):{},U(e||!n||!n.__esModule?v(t,"default",{value:n,enumerable:!0}):t,n)),le=n=>U(v({},"__esModule",{value:!0}),n);var m=(n,e,t)=>new Promise((r,o)=>{var i=c=>{try{a(t.next(c))}catch(d){o(d)}},s=c=>{try{a(t.throw(c))}catch(d){o(d)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);a((t=t.apply(n,e)).next())});var z=F((Ye,ve)=>{ve.exports={name:"dotenv",version:"16.6.1",description:"Loads environment variables from .env file",main:"lib/main.js",types:"lib/main.d.ts",exports:{".":{types:"./lib/main.d.ts",require:"./lib/main.js",default:"./lib/main.js"},"./config":"./config.js","./config.js":"./config.js","./lib/env-options":"./lib/env-options.js","./lib/env-options.js":"./lib/env-options.js","./lib/cli-options":"./lib/cli-options.js","./lib/cli-options.js":"./lib/cli-options.js","./package.json":"./package.json"},scripts:{"dts-check":"tsc --project tests/types/tsconfig.json",lint:"standard",pretest:"npm run lint && npm run dts-check",test:"tap run --allow-empty-coverage --disable-coverage --timeout=60000","test:coverage":"tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",prerelease:"npm test",release:"standard-version"},repository:{type:"git",url:"git://github.com/motdotla/dotenv.git"},homepage:"https://github.com/motdotla/dotenv#readme",funding:"https://dotenvx.com",keywords:["dotenv","env",".env","environment","variables","config","settings"],readmeFilename:"README.md",license:"BSD-2-Clause",devDependencies:{"@types/node":"^18.11.3",decache:"^4.6.2",sinon:"^14.0.1",standard:"^17.0.0","standard-version":"^9.5.0",tap:"^19.2.0",typescript:"^4.8.4"},engines:{node:">=12"},browser:{fs:!1}}});var Z=F((He,h)=>{"use strict";var k=require("fs"),S=require("path"),be=require("os"),Ee=require("crypto"),we=z(),L=we.version,_e=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;function De(n){let e={},t=n.toString();t=t.replace(/\r\n?/mg,`
2
- `);let r;for(;(r=_e.exec(t))!=null;){let o=r[1],i=r[2]||"";i=i.trim();let s=i[0];i=i.replace(/^(['"`])([\s\S]*)\1$/mg,"$2"),s==='"'&&(i=i.replace(/\\n/g,`
3
- `),i=i.replace(/\\r/g,"\r")),e[o]=i}return e}function Te(n){n=n||{};let e=G(n);n.path=e;let t=l.configDotenv(n);if(!t.parsed){let s=new Error(`MISSING_DATA: Cannot parse ${e} for an unknown reason`);throw s.code="MISSING_DATA",s}let r=X(n).split(","),o=r.length,i;for(let s=0;s<o;s++)try{let a=r[s].trim(),c=Oe(t,a);i=l.decrypt(c.ciphertext,c.key);break}catch(a){if(s+1>=o)throw a}return l.parse(i)}function Ae(n){console.log(`[dotenv@${L}][WARN] ${n}`)}function _(n){console.log(`[dotenv@${L}][DEBUG] ${n}`)}function W(n){console.log(`[dotenv@${L}] ${n}`)}function X(n){return n&&n.DOTENV_KEY&&n.DOTENV_KEY.length>0?n.DOTENV_KEY:process.env.DOTENV_KEY&&process.env.DOTENV_KEY.length>0?process.env.DOTENV_KEY:""}function Oe(n,e){let t;try{t=new URL(e)}catch(a){if(a.code==="ERR_INVALID_URL"){let c=new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");throw c.code="INVALID_DOTENV_KEY",c}throw a}let r=t.password;if(!r){let a=new Error("INVALID_DOTENV_KEY: Missing key part");throw a.code="INVALID_DOTENV_KEY",a}let o=t.searchParams.get("environment");if(!o){let a=new Error("INVALID_DOTENV_KEY: Missing environment part");throw a.code="INVALID_DOTENV_KEY",a}let i=`DOTENV_VAULT_${o.toUpperCase()}`,s=n.parsed[i];if(!s){let a=new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${i} in your .env.vault file.`);throw a.code="NOT_FOUND_DOTENV_ENVIRONMENT",a}return{ciphertext:s,key:r}}function G(n){let e=null;if(n&&n.path&&n.path.length>0)if(Array.isArray(n.path))for(let t of n.path)k.existsSync(t)&&(e=t.endsWith(".vault")?t:`${t}.vault`);else e=n.path.endsWith(".vault")?n.path:`${n.path}.vault`;else e=S.resolve(process.cwd(),".env.vault");return k.existsSync(e)?e:null}function J(n){return n[0]==="~"?S.join(be.homedir(),n.slice(1)):n}function xe(n){let e=!!(n&&n.debug),t=n&&"quiet"in n?n.quiet:!0;(e||!t)&&W("Loading env from encrypted .env.vault");let r=l._parseVault(n),o=process.env;return n&&n.processEnv!=null&&(o=n.processEnv),l.populate(o,r,n),{parsed:r}}function Ce(n){let e=S.resolve(process.cwd(),".env"),t="utf8",r=!!(n&&n.debug),o=n&&"quiet"in n?n.quiet:!0;n&&n.encoding?t=n.encoding:r&&_("No encoding is specified. UTF-8 is used by default");let i=[e];if(n&&n.path)if(!Array.isArray(n.path))i=[J(n.path)];else{i=[];for(let d of n.path)i.push(J(d))}let s,a={};for(let d of i)try{let p=l.parse(k.readFileSync(d,{encoding:t}));l.populate(a,p,n)}catch(p){r&&_(`Failed to load ${d} ${p.message}`),s=p}let c=process.env;if(n&&n.processEnv!=null&&(c=n.processEnv),l.populate(c,a,n),r||!o){let d=Object.keys(a).length,p=[];for(let R of i)try{let T=S.relative(process.cwd(),R);p.push(T)}catch(T){r&&_(`Failed to load ${R} ${T.message}`),s=T}W(`injecting env (${d}) from ${p.join(",")}`)}return s?{parsed:a,error:s}:{parsed:a}}function Ie(n){if(X(n).length===0)return l.configDotenv(n);let e=G(n);return e?l._configVault(n):(Ae(`You set DOTENV_KEY but you are missing a .env.vault file at ${e}. Did you forget to build it?`),l.configDotenv(n))}function Ne(n,e){let t=Buffer.from(e.slice(-64),"hex"),r=Buffer.from(n,"base64"),o=r.subarray(0,12),i=r.subarray(-16);r=r.subarray(12,-16);try{let s=Ee.createDecipheriv("aes-256-gcm",t,o);return s.setAuthTag(i),`${s.update(r)}${s.final()}`}catch(s){let a=s instanceof RangeError,c=s.message==="Invalid key length",d=s.message==="Unsupported state or unable to authenticate data";if(a||c){let p=new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");throw p.code="INVALID_DOTENV_KEY",p}else if(d){let p=new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");throw p.code="DECRYPTION_FAILED",p}else throw s}}function Se(n,e,t={}){let r=!!(t&&t.debug),o=!!(t&&t.override);if(typeof e!="object"){let i=new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");throw i.code="OBJECT_REQUIRED",i}for(let i of Object.keys(e))Object.prototype.hasOwnProperty.call(n,i)?(o===!0&&(n[i]=e[i]),r&&_(o===!0?`"${i}" is already defined and WAS overwritten`:`"${i}" is already defined and was NOT overwritten`)):n[i]=e[i]}var l={configDotenv:Ce,_configVault:xe,_parseVault:Te,config:Ie,decrypt:Ne,parse:De,populate:Se};h.exports.configDotenv=l.configDotenv;h.exports._configVault=l._configVault;h.exports._parseVault=l._parseVault;h.exports.config=l.config;h.exports.decrypt=l.decrypt;h.exports.parse=l.parse;h.exports.populate=l.populate;h.exports=l});var je={};ce(je,{ApiError:()=>g,DatoCMS:()=>w,Filter:()=>Y,QueenofheartsRenderComponent:()=>ue,QueenofheartsService:()=>y,StrapiCMS:()=>D,componentRegistry:()=>f,fetchDynamicComponents:()=>ye,getAllregisteredComponents:()=>H,registerComponent:()=>ge,registerLazyComponent:()=>he,unregisterComponent:()=>me});module.exports=le(je);var j=require("react");var E=require("react/jsx-runtime");function ue(n){let e=y.getInstance(),{data:t,contextProps:r}=n;return t&&e?Array.isArray(t)?(0,E.jsx)(j.Suspense,{fallback:null,children:t.map((o,i)=>e.createComponent({data:o,contextProps:r}))}):(0,E.jsx)(j.Suspense,{fallback:null,children:e.createComponent({data:t,contextProps:r})}):e?(0,E.jsx)("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):(0,E.jsx)("div",{children:"QueenofheartsService is not initialized"})}var g=class extends Error{constructor(e,t){super(t.summary),this.name="ApiError",this.status=e,this.body=t}};var N=B(require("react"));var u=require("react/jsx-runtime"),O,x,C,q,I;try{O=require("@mui/material/Accordion").default,x=require("@mui/material/AccordionSummary").default,C=require("@mui/material/AccordionDetails").default,q=require("@mui/material/Paper").default,I=require("@mui/icons-material/ExpandMore").default}catch(n){O=({children:e,style:t})=>(0,u.jsx)("details",{style:t,children:e}),x=({children:e})=>(0,u.jsx)("summary",{children:e}),C=({children:e})=>(0,u.jsx)("div",{style:{paddingLeft:"1em"},children:e}),q=({children:e,style:t})=>(0,u.jsx)("div",{style:A(b({},t),{border:"1px solid #ccc",padding:".5em"}),children:e}),I=()=>(0,u.jsx)("span",{children:"\u25BC"})}function de(n,e,t){return(0,u.jsxs)(O,{style:{width:"100%"},children:[(0,u.jsxs)(x,{style:{padding:0},expandIcon:(0,u.jsx)(I,{}),children:[n,": Array[",e.length,"]"]}),(0,u.jsx)(C,{children:e.map((r,o)=>$("",r,o))})]},`${n}_${t}`)}function fe(n,e,t){return(0,u.jsxs)(O,{style:{width:"100%"},children:[(0,u.jsx)(x,{expandIcon:(0,u.jsx)(I,{}),children:n}),(0,u.jsx)(C,{children:Object.entries(e).map((r,o)=>$(r[0],r[1],o))})]},`${n}_${t}`)}function K(n,e,t){return(0,u.jsxs)("div",{children:[n,": ",`${e}`]},`${n}_${t}`)}function $(n,e,t){var o;if(Array.isArray(e))return de(n,e,t);if(!e||["string","number"].includes(typeof e))return K(n,e,t);if(typeof e=="boolean")return K(n,e?"true":"false",t);let r=`${n?n+": ":""}${(o=e.__typename)!=null?o:"object"}`;return fe(r,e,t)}function V(n){return typeof n.data=="object"?(0,u.jsx)(q,{style:{margin:".5em",width:"calc(100% - 1em)"},children:$("",n.data,1)}):null}var Y=(o=>(o.eq="eq",o.in="in",o.neq="neq",o.notIn="notIn",o))(Y||{}),pe="https://headless.li/api",f={};function me(n){delete f[n]}function ge(n,e,t,r){if(e!==void 0&&(r||f[e]===void 0)){let o={component:n,fieldNames:t};f[e]=o}}function he(n,e,t,r=!1){e?(r||f[e]===void 0)&&(f[e]={fieldNames:t,loader:n}):console.warn("registerComponent failed: undefined typeName ")}function H(){return f}var ye=n=>m(null,null,function*(){let e=y.getInstance(),t=e.findComponentsInProps(n).filter((o,i,s)=>s.indexOf(o)===i);return(yield e.fetchDynamicComponents(t)).filter(o=>o!==null)}),y=class n{constructor(e,t){this.latestUrl="";this.latestData={};this.findComponentsInProps=e=>{if(e&&typeof e!="string"){let t=e.__typename?[e.__typename]:[],r=Array.isArray(e)?e:Object.values(e);return[...t,...r.reduce((i,s)=>{let a=this.findComponentsInProps(s);return a&&(i=[...i,...a]),i},[])]}return[]};this.fetchDynamicComponents=e=>m(this,null,function*(){let t=!1,r=!1,o=Promise.all(e.map(i=>m(this,null,function*(){var s;return f[i]&&f[i].component===void 0?(t=!0,yield this.loadAsyncComponent(i)):(s=f[i])!=null&&s.loader?i:null})));return r=!0,o});this.buildUrl=e=>{var r;return`${(r=this.localServer)!=null?r:pe}/${e}`};this.queryGraphql=e=>m(this,null,function*(){let t=this.buildUrl("execGraphqlQuery");if(console.info(`using url : ${t}`),t){let r=yield fetch(t,{method:"POST",headers:{Authorization:`Bearer ${this.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify({query:e})});if(r.ok){let o=yield r.json();return this.sendDebugEvent(),o}else{let o=yield r.json();throw console.log(o),new g(r.status,o)}}throw new g(500,{id:"99",summary:"queryUrl was not set",details:`LocalServer: ${this.localServer}`})});this.query=(e,t)=>m(this,null,function*(){var i,s;let r=this.buildUrl("execQuery"),o=t!=null&&t.variables?b({},t.variables):{};if(t!=null&&t.locale&&(o.locale=t.locale),t!=null&&t.filter&&Array.isArray(t.filter)&&(o.filter||(o.filter=[]),o.filter.push(...t.filter),(i=t==null?void 0:t.variables)!=null&&i.filter&&Array.isArray(t.variables.filter)&&o.filter.push(...t.variables.filter)),r&&t){let a=yield fetch(r,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiToken}`},method:"POST",credentials:"include",body:JSON.stringify({queryname:e,variables:o,components:this.getRegisteredComponentsWithFields(),ignoreProperties:t.ignoreProperties,depth:t.depth})});if(a.ok){let c=(s=yield a.json())==null?void 0:s.data,d=this.debug?this.injectIds(c):c;return this.latestData=d,this.sendDebugEvent(),d}else try{let c=yield a.json();throw console.log(c),new g(a.status,c)}catch(c){throw new g(a.status,c.toString())}}else throw new g(500,{id:"99",summary:`Query: queryUrl (${r}) or options are invalid`,details:`queryUrl: ${r}`})});this.getRegisteredComponentsWithFields=()=>{let e={},t=Object.entries(H());return t&&Array.isArray(t)&&t.forEach(([r,o])=>{let i={},s=o.fieldNames,a=!1;s&&Array.isArray(s)&&s.forEach(c=>{i[c]=!0,a=!0}),a?e[r]=i:e[r]={__all:!0}}),e};this.getQueries=()=>m(this,null,function*(){let e=this.buildUrl("queries");if(e){let t=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json"}});if(t.ok)try{return yield t.json()}catch(r){console.error(r)}}else console.error("api, uri and CMSToken have to be provided");return""});this.apiToken=e,this.localServer=t,this.debug=typeof document!="undefined"&&document.getElementsByTagName("body")[0].classList.contains("qoh-inject-ids"),this.debug&&typeof globalThis.window!="undefined"&&(globalThis.window.addEventListener("QueenOfHearts-RequestData",()=>{this.sendDebugEvent()}),globalThis.window.addEventListener("QueenOfHearts-RequestQueries",()=>{this.sendQueriesEvent()}),globalThis.window.addEventListener("QueenOfHearts-HighlightComponent",(r=>{this.highlightComponent(r.detail)})),globalThis.window.addEventListener("QueenOfHearts-RequestComponentHTML",(r=>{this.sendComponentHTML(r.detail)})))}static init(e,t){n.instance=new n(e,t)}static getInstance(){return n.instance||console.error("QueenofheartsService was not initialized using QueenofheartsService.init(backend, apiToken)"),n.instance}loadAsyncComponent(e){return m(this,null,function*(){let t=f[e];if(t&&t.component===void 0){if(!(t!=null&&t.component)&&t.loader){let r=t.loader,o=yield r();o?f[e].component=o.default:(console.error(`error loading ${e}`),console.error(o))}return e}return null})}createComponent(e){var a;let{data:t,contextProps:r={}}=e,o=t.__typename,i=f[o];i&&i.loader&&(0,N.lazy)(i.loader);let s=(a=i==null?void 0:i.component)!=null?a:V;return N.default.createElement(s,A(b({},t),{contextProps:r}))}injectIds(e){if(Array.isArray(e))e.forEach(t=>this.injectIds(t));else if(e&&typeof e=="object"){if(e.hasOwnProperty("__typename")){let t=Math.random().toString();e.__qohId=t.substr(t.indexOf(".")+1)}Object.keys(e).forEach(t=>e[t]=this.injectIds(e[t]))}return e}sendDebugEvent(){if(typeof window=="undefined")return;let e={registeredComponents:Object.keys(f),url:this.latestUrl,data:this.latestData},t=new CustomEvent("QueenOfHearts-DebuggingData",{detail:e});window.dispatchEvent(t)}sendQueriesEvent(){return m(this,null,function*(){if(typeof window=="undefined")return;let e=new CustomEvent("QueenOfHearts-AvailableQueries",{detail:yield this.getQueries()});window.dispatchEvent(e)})}sendComponentHTML(e){var r;if(typeof window=="undefined")return;let t=(r=document.querySelector(`[qohId='${e}']`))==null?void 0:r.nextElementSibling;if(t){let o=new CustomEvent("QueenOfHearts-SelectedComponentHTML",{detail:{qohId:e,html:t.outerHTML}});window.dispatchEvent(o)}}highlightComponent(e){var i;let t=[{outline:"thick auto white"},{outline:"thick auto red"}],r={duration:1e3,iterations:2},o=(i=document.querySelector(`[qohId='${e}']`))==null?void 0:i.nextElementSibling;o&&o.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),o&&o.animate(t,r)}};var w=class{constructor(e){this.token="";this.uri="https://graphql.datocms.com/";this.token=e}renameSEOMetaTags(e){e.forEach(function(t,r,o){o[r].__typename="SEOMetaTag"})}normalize(e){if(e)return e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(t=>{Array.isArray(e[t])&&(e[t]=e[t].map(r=>this.normalize(r))),e[t]&&typeof e[t]=="object"&&(e[t]=this.normalize(e[t]))}),e}};var ee=B(Z());ee.default.config();var D=class{constructor(e,t){this.token="";this.uri="";this.token=e,this.uri=t}renameSEOMetaTags(e){e.forEach(function(t,r,o){o[r].__typename="SEOMetaTag"})}normalize(e){return e&&(e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(t=>{Array.isArray(e[t])&&(e[t]=e[t].map(r=>this.normalize(r))),e[t]&&typeof e[t]=="object"&&(e[t]=this.normalize(e[t]))}),e)}};0&&(module.exports={ApiError,DatoCMS,Filter,QueenofheartsRenderComponent,QueenofheartsService,StrapiCMS,componentRegistry,fetchDynamicComponents,getAllregisteredComponents,registerComponent,registerLazyComponent,unregisterComponent});
1
+ "use strict";var L=Object.create;var g=Object.defineProperty,M=Object.defineProperties,z=Object.getOwnPropertyDescriptor,B=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertyNames,O=Object.getOwnPropertySymbols,U=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var q=(t,e,n)=>e in t?g(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,b=(t,e)=>{for(var n in e||(e={}))j.call(e,n)&&q(t,n,e[n]);if(O)for(var n of O(e))J.call(e,n)&&q(t,n,e[n]);return t},E=(t,e)=>M(t,B(e));var N=(t,e)=>{for(var n in e)g(t,n,{get:e[n],enumerable:!0})},R=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of H(e))!j.call(t,i)&&i!==n&&g(t,i,{get:()=>e[i],enumerable:!(r=z(e,i))||r.enumerable});return t};var p=(t,e,n)=>(n=t!=null?L(U(t)):{},R(e||!t||!t.__esModule?g(n,"default",{value:t,enumerable:!0}):n,t)),X=t=>R(g({},"__esModule",{value:!0}),t);var u=(t,e,n)=>new Promise((r,i)=>{var o=c=>{try{s(n.next(c))}catch(y){i(y)}},l=c=>{try{s(n.throw(c))}catch(y){i(y)}},s=c=>c.done?r(c.value):Promise.resolve(c.value).then(o,l);s((n=n.apply(t,e)).next())});var ae={};N(ae,{ApiError:()=>m,DatoCMS:()=>w,Filter:()=>P,QueenofheartsRenderComponent:()=>W,QueenofheartsService:()=>h,StrapiCMS:()=>C,componentRegistry:()=>d,fetchDynamicComponents:()=>se,getAllregisteredComponents:()=>$,registerComponent:()=>ie,registerLazyComponent:()=>oe,unregisterComponent:()=>re});module.exports=X(ae);var A=require("react");var v=require("react/jsx-runtime");function W(t){let e=h.getInstance(),{data:n,contextProps:r}=t;return n&&e?Array.isArray(n)?(0,v.jsx)(A.Suspense,{fallback:null,children:n.map((i,o)=>e.createComponent({data:i,contextProps:r}))}):(0,v.jsx)(A.Suspense,{fallback:null,children:e.createComponent({data:n,contextProps:r})}):e?(0,v.jsx)("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):(0,v.jsx)("div",{children:"QueenofheartsService is not initialized"})}var m=class extends Error{constructor(e,n){super(n.summary),this.name="ApiError",this.status=e,this.body=n}};var x=p(require("react"));var f=p(require("react"));var a=require("react/jsx-runtime"),G=({children:t,style:e})=>(0,a.jsx)("details",{style:e,children:t}),V=({children:t})=>(0,a.jsx)("summary",{children:t}),K=({children:t})=>(0,a.jsx)("div",{style:{paddingLeft:"1em"},children:t}),_=({children:t,style:e})=>(0,a.jsx)("div",{style:E(b({},e),{border:"1px solid #ccc",padding:".5em"}),children:t}),Y=()=>(0,a.jsx)("span",{children:"\u25BC"}),D=f.lazy(()=>import("@mui/material/Accordion").catch(()=>({default:G}))),Q=f.lazy(()=>import("@mui/material/AccordionSummary").catch(()=>({default:V}))),k=f.lazy(()=>import("@mui/material/AccordionDetails").catch(()=>({default:K}))),Z=f.lazy(()=>import("@mui/material/Paper").catch(()=>({default:_}))),F=f.lazy(()=>import("@mui/icons-material/ExpandMore").catch(()=>({default:Y})));function ee(t,e,n){return(0,a.jsxs)(D,{style:{width:"100%"},children:[(0,a.jsxs)(Q,{style:{padding:0},expandIcon:(0,a.jsx)(F,{}),children:[t,": Array[",e.length,"]"]}),(0,a.jsx)(k,{children:e.map((r,i)=>S("",r,i))})]},`${t}_${n}`)}function ne(t,e,n){return(0,a.jsxs)(D,{style:{width:"100%"},children:[(0,a.jsx)(Q,{expandIcon:(0,a.jsx)(F,{}),children:t}),(0,a.jsx)(k,{children:Object.entries(e).map((r,i)=>S(r[0],r[1],i))})]},`${t}_${n}`)}function I(t,e,n){return(0,a.jsxs)("div",{children:[t,": ",`${e}`]},`${t}_${n}`)}function S(t,e,n){var i;if(Array.isArray(e))return ee(t,e,n);if(!e||["string","number"].includes(typeof e))return I(t,e,n);if(typeof e=="boolean")return I(t,e?"true":"false",n);let r=`${t?t+": ":""}${(i=e.__typename)!=null?i:"object"}`;return ne(r,e,n)}function T(t){return typeof t.data=="object"?(0,a.jsx)(f.Suspense,{fallback:(0,a.jsx)(_,{style:{margin:".5em",width:"calc(100% - 1em)"},children:S("",t.data,1)}),children:(0,a.jsx)(Z,{style:{margin:".5em",width:"calc(100% - 1em)"},children:S("",t.data,1)})}):null}var P=(i=>(i.eq="eq",i.in="in",i.neq="neq",i.notIn="notIn",i))(P||{}),te="https://headless.li/api",d={};function re(t){delete d[t]}function ie(t,e,n,r){if(e!==void 0&&(r||d[e]===void 0)){let i={component:t,fieldNames:n};d[e]=i}}function oe(t,e,n,r=!1){e?(r||d[e]===void 0)&&(d[e]={fieldNames:n,loader:t}):console.warn("registerComponent failed: undefined typeName ")}function $(){return d}var se=t=>u(null,null,function*(){let e=h.getInstance(),n=e.findComponentsInProps(t).filter((i,o,l)=>l.indexOf(i)===o);return(yield e.fetchDynamicComponents(n)).filter(i=>i!==null)}),h=class t{constructor(e,n){this.latestUrl="";this.latestData={};this.findComponentsInProps=e=>{if(e&&typeof e!="string"){let n=e.__typename?[e.__typename]:[],r=Array.isArray(e)?e:Object.values(e);return[...n,...r.reduce((o,l)=>{let s=this.findComponentsInProps(l);return s&&(o=[...o,...s]),o},[])]}return[]};this.fetchDynamicComponents=e=>u(this,null,function*(){let n=!1,r=!1,i=Promise.all(e.map(o=>u(this,null,function*(){var l;return d[o]&&d[o].component===void 0?(n=!0,yield this.loadAsyncComponent(o)):(l=d[o])!=null&&l.loader?o:null})));return r=!0,i});this.buildUrl=e=>{var r;return`${(r=this.localServer)!=null?r:te}/${e}`};this.queryGraphql=e=>u(this,null,function*(){let n=this.buildUrl("execGraphqlQuery");if(console.info(`using url : ${n}`),n){let r=yield fetch(n,{method:"POST",headers:{Authorization:`Bearer ${this.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify({query:e})});if(r.ok){let i=yield r.json();return this.sendDebugEvent(),i}else{let i=yield r.json();throw console.log(i),new m(r.status,i)}}throw new m(500,{id:"99",summary:"queryUrl was not set",details:`LocalServer: ${this.localServer}`})});this.query=(e,n)=>u(this,null,function*(){var o,l;let r=this.buildUrl("execQuery"),i=n!=null&&n.variables?b({},n.variables):{};if(n!=null&&n.locale&&(i.locale=n.locale),n!=null&&n.filter&&Array.isArray(n.filter)&&(i.filter||(i.filter=[]),i.filter.push(...n.filter),(o=n==null?void 0:n.variables)!=null&&o.filter&&Array.isArray(n.variables.filter)&&i.filter.push(...n.variables.filter)),r&&n){let s=yield fetch(r,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiToken}`},method:"POST",credentials:"include",body:JSON.stringify({queryname:e,variables:i,components:this.getRegisteredComponentsWithFields(),ignoreProperties:n.ignoreProperties,depth:n.depth})});if(s.ok){let c=(l=yield s.json())==null?void 0:l.data,y=this.debug?this.injectIds(c):c;return this.latestData=y,this.sendDebugEvent(),y}else try{let c=yield s.json();throw console.log(c),new m(s.status,c)}catch(c){throw new m(s.status,c.toString())}}else throw new m(500,{id:"99",summary:`Query: queryUrl (${r}) or options are invalid`,details:`queryUrl: ${r}`})});this.getRegisteredComponentsWithFields=()=>{let e={},n=Object.entries($());return n&&Array.isArray(n)&&n.forEach(([r,i])=>{let o={},l=i.fieldNames,s=!1;l&&Array.isArray(l)&&l.forEach(c=>{o[c]=!0,s=!0}),s?e[r]=o:e[r]={__all:!0}}),e};this.getQueries=()=>u(this,null,function*(){let e=this.buildUrl("queries");if(e){let n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json"}});if(n.ok)try{return yield n.json()}catch(r){console.error(r)}}else console.error("api, uri and CMSToken have to be provided");return""});this.apiToken=e,this.localServer=n,this.debug=typeof document!="undefined"&&document.getElementsByTagName("body")[0].classList.contains("qoh-inject-ids"),this.debug&&typeof globalThis.window!="undefined"&&(globalThis.window.addEventListener("QueenOfHearts-RequestData",()=>{this.sendDebugEvent()}),globalThis.window.addEventListener("QueenOfHearts-RequestQueries",()=>{this.sendQueriesEvent()}),globalThis.window.addEventListener("QueenOfHearts-HighlightComponent",(r=>{this.highlightComponent(r.detail)})),globalThis.window.addEventListener("QueenOfHearts-RequestComponentHTML",(r=>{this.sendComponentHTML(r.detail)})))}static init(e,n){t.instance=new t(e,n)}static getInstance(){return t.instance||console.error("QueenofheartsService was not initialized using QueenofheartsService.init(backend, apiToken)"),t.instance}loadAsyncComponent(e){return u(this,null,function*(){let n=d[e];if(n&&n.component===void 0){if(!(n!=null&&n.component)&&n.loader){let r=n.loader,i=yield r();i?d[e].component=i.default:(console.error(`error loading ${e}`),console.error(i))}return e}return null})}createComponent(e){var s;let{data:n,contextProps:r={}}=e,i=n.__typename,o=d[i];o&&o.loader&&(0,x.lazy)(o.loader);let l=(s=o==null?void 0:o.component)!=null?s:T;return x.default.createElement(l,E(b({},n),{contextProps:r}))}injectIds(e){if(Array.isArray(e))e.forEach(n=>this.injectIds(n));else if(e&&typeof e=="object"){if(e.hasOwnProperty("__typename")){let n=Math.random().toString();e.__qohId=n.substr(n.indexOf(".")+1)}Object.keys(e).forEach(n=>e[n]=this.injectIds(e[n]))}return e}sendDebugEvent(){if(typeof window=="undefined")return;let e={registeredComponents:Object.keys(d),url:this.latestUrl,data:this.latestData},n=new CustomEvent("QueenOfHearts-DebuggingData",{detail:e});window.dispatchEvent(n)}sendQueriesEvent(){return u(this,null,function*(){if(typeof window=="undefined")return;let e=new CustomEvent("QueenOfHearts-AvailableQueries",{detail:yield this.getQueries()});window.dispatchEvent(e)})}sendComponentHTML(e){var r;if(typeof window=="undefined")return;let n=(r=document.querySelector(`[qohId='${e}']`))==null?void 0:r.nextElementSibling;if(n){let i=new CustomEvent("QueenOfHearts-SelectedComponentHTML",{detail:{qohId:e,html:n.outerHTML}});window.dispatchEvent(i)}}highlightComponent(e){var o;let n=[{outline:"thick auto white"},{outline:"thick auto red"}],r={duration:1e3,iterations:2},i=(o=document.querySelector(`[qohId='${e}']`))==null?void 0:o.nextElementSibling;i&&i.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),i&&i.animate(n,r)}};var w=class{constructor(e){this.token="";this.uri="https://graphql.datocms.com/";this.token=e}renameSEOMetaTags(e){e.forEach(function(n,r,i){i[r].__typename="SEOMetaTag"})}normalize(e){if(e)return e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(r=>this.normalize(r))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e}};var C=class{constructor(e,n){this.token="";this.uri="";this.token=e,this.uri=n}renameSEOMetaTags(e){e.forEach(function(n,r,i){i[r].__typename="SEOMetaTag"})}normalize(e){return e&&(e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(r=>this.normalize(r))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e)}};0&&(module.exports={ApiError,DatoCMS,Filter,QueenofheartsRenderComponent,QueenofheartsService,StrapiCMS,componentRegistry,fetchDynamicComponents,getAllregisteredComponents,registerComponent,registerLazyComponent,unregisterComponent});
package/lib/index.mjs CHANGED
@@ -1,3 +1 @@
1
- var G=Object.create;var j=Object.defineProperty,Z=Object.defineProperties,ee=Object.getOwnPropertyDescriptor,te=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertyNames,P=Object.getOwnPropertySymbols,re=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var M=(n,e,t)=>e in n?j(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,v=(n,e)=>{for(var t in e||(e={}))Q.call(e,t)&&M(n,t,e[t]);if(P)for(var t of P(e))oe.call(e,t)&&M(n,t,e[t]);return n},_=(n,e)=>Z(n,te(e));var m=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(e,t)=>(typeof require!="undefined"?require:e)[t]}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var F=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var ie=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ne(e))!Q.call(n,o)&&o!==t&&j(n,o,{get:()=>e[o],enumerable:!(r=ee(e,o))||r.enumerable});return n};var se=(n,e,t)=>(t=n!=null?G(re(n)):{},ie(e||!n||!n.__esModule?j(t,"default",{value:n,enumerable:!0}):t,n));var g=(n,e,t)=>new Promise((r,o)=>{var i=c=>{try{a(t.next(c))}catch(u){o(u)}},s=c=>{try{a(t.throw(c))}catch(u){o(u)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(i,s);a((t=t.apply(n,e)).next())});var K=F((We,me)=>{me.exports={name:"dotenv",version:"16.6.1",description:"Loads environment variables from .env file",main:"lib/main.js",types:"lib/main.d.ts",exports:{".":{types:"./lib/main.d.ts",require:"./lib/main.js",default:"./lib/main.js"},"./config":"./config.js","./config.js":"./config.js","./lib/env-options":"./lib/env-options.js","./lib/env-options.js":"./lib/env-options.js","./lib/cli-options":"./lib/cli-options.js","./lib/cli-options.js":"./lib/cli-options.js","./package.json":"./package.json"},scripts:{"dts-check":"tsc --project tests/types/tsconfig.json",lint:"standard",pretest:"npm run lint && npm run dts-check",test:"tap run --allow-empty-coverage --disable-coverage --timeout=60000","test:coverage":"tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",prerelease:"npm test",release:"standard-version"},repository:{type:"git",url:"git://github.com/motdotla/dotenv.git"},homepage:"https://github.com/motdotla/dotenv#readme",funding:"https://dotenvx.com",keywords:["dotenv","env",".env","environment","variables","config","settings"],readmeFilename:"README.md",license:"BSD-2-Clause",devDependencies:{"@types/node":"^18.11.3",decache:"^4.6.2",sinon:"^14.0.1",standard:"^17.0.0","standard-version":"^9.5.0",tap:"^19.2.0",typescript:"^4.8.4"},engines:{node:">=12"},browser:{fs:!1}}});var W=F((Xe,h)=>{"use strict";var k=m("fs"),N=m("path"),ge=m("os"),he=m("crypto"),ye=K(),L=ye.version,ve=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;function be(n){let e={},t=n.toString();t=t.replace(/\r\n?/mg,`
2
- `);let r;for(;(r=ve.exec(t))!=null;){let o=r[1],i=r[2]||"";i=i.trim();let s=i[0];i=i.replace(/^(['"`])([\s\S]*)\1$/mg,"$2"),s==='"'&&(i=i.replace(/\\n/g,`
3
- `),i=i.replace(/\\r/g,"\r")),e[o]=i}return e}function Ee(n){n=n||{};let e=J(n);n.path=e;let t=l.configDotenv(n);if(!t.parsed){let s=new Error(`MISSING_DATA: Cannot parse ${e} for an unknown reason`);throw s.code="MISSING_DATA",s}let r=z(n).split(","),o=r.length,i;for(let s=0;s<o;s++)try{let a=r[s].trim(),c=_e(t,a);i=l.decrypt(c.ciphertext,c.key);break}catch(a){if(s+1>=o)throw a}return l.parse(i)}function we(n){console.log(`[dotenv@${L}][WARN] ${n}`)}function E(n){console.log(`[dotenv@${L}][DEBUG] ${n}`)}function H(n){console.log(`[dotenv@${L}] ${n}`)}function z(n){return n&&n.DOTENV_KEY&&n.DOTENV_KEY.length>0?n.DOTENV_KEY:process.env.DOTENV_KEY&&process.env.DOTENV_KEY.length>0?process.env.DOTENV_KEY:""}function _e(n,e){let t;try{t=new URL(e)}catch(a){if(a.code==="ERR_INVALID_URL"){let c=new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");throw c.code="INVALID_DOTENV_KEY",c}throw a}let r=t.password;if(!r){let a=new Error("INVALID_DOTENV_KEY: Missing key part");throw a.code="INVALID_DOTENV_KEY",a}let o=t.searchParams.get("environment");if(!o){let a=new Error("INVALID_DOTENV_KEY: Missing environment part");throw a.code="INVALID_DOTENV_KEY",a}let i=`DOTENV_VAULT_${o.toUpperCase()}`,s=n.parsed[i];if(!s){let a=new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${i} in your .env.vault file.`);throw a.code="NOT_FOUND_DOTENV_ENVIRONMENT",a}return{ciphertext:s,key:r}}function J(n){let e=null;if(n&&n.path&&n.path.length>0)if(Array.isArray(n.path))for(let t of n.path)k.existsSync(t)&&(e=t.endsWith(".vault")?t:`${t}.vault`);else e=n.path.endsWith(".vault")?n.path:`${n.path}.vault`;else e=N.resolve(process.cwd(),".env.vault");return k.existsSync(e)?e:null}function Y(n){return n[0]==="~"?N.join(ge.homedir(),n.slice(1)):n}function De(n){let e=!!(n&&n.debug),t=n&&"quiet"in n?n.quiet:!0;(e||!t)&&H("Loading env from encrypted .env.vault");let r=l._parseVault(n),o=process.env;return n&&n.processEnv!=null&&(o=n.processEnv),l.populate(o,r,n),{parsed:r}}function Te(n){let e=N.resolve(process.cwd(),".env"),t="utf8",r=!!(n&&n.debug),o=n&&"quiet"in n?n.quiet:!0;n&&n.encoding?t=n.encoding:r&&E("No encoding is specified. UTF-8 is used by default");let i=[e];if(n&&n.path)if(!Array.isArray(n.path))i=[Y(n.path)];else{i=[];for(let u of n.path)i.push(Y(u))}let s,a={};for(let u of i)try{let d=l.parse(k.readFileSync(u,{encoding:t}));l.populate(a,d,n)}catch(d){r&&E(`Failed to load ${u} ${d.message}`),s=d}let c=process.env;if(n&&n.processEnv!=null&&(c=n.processEnv),l.populate(c,a,n),r||!o){let u=Object.keys(a).length,d=[];for(let R of i)try{let w=N.relative(process.cwd(),R);d.push(w)}catch(w){r&&E(`Failed to load ${R} ${w.message}`),s=w}H(`injecting env (${u}) from ${d.join(",")}`)}return s?{parsed:a,error:s}:{parsed:a}}function Ae(n){if(z(n).length===0)return l.configDotenv(n);let e=J(n);return e?l._configVault(n):(we(`You set DOTENV_KEY but you are missing a .env.vault file at ${e}. Did you forget to build it?`),l.configDotenv(n))}function Oe(n,e){let t=Buffer.from(e.slice(-64),"hex"),r=Buffer.from(n,"base64"),o=r.subarray(0,12),i=r.subarray(-16);r=r.subarray(12,-16);try{let s=he.createDecipheriv("aes-256-gcm",t,o);return s.setAuthTag(i),`${s.update(r)}${s.final()}`}catch(s){let a=s instanceof RangeError,c=s.message==="Invalid key length",u=s.message==="Unsupported state or unable to authenticate data";if(a||c){let d=new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");throw d.code="INVALID_DOTENV_KEY",d}else if(u){let d=new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");throw d.code="DECRYPTION_FAILED",d}else throw s}}function xe(n,e,t={}){let r=!!(t&&t.debug),o=!!(t&&t.override);if(typeof e!="object"){let i=new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");throw i.code="OBJECT_REQUIRED",i}for(let i of Object.keys(e))Object.prototype.hasOwnProperty.call(n,i)?(o===!0&&(n[i]=e[i]),r&&E(o===!0?`"${i}" is already defined and WAS overwritten`:`"${i}" is already defined and was NOT overwritten`)):n[i]=e[i]}var l={configDotenv:Te,_configVault:De,_parseVault:Ee,config:Ae,decrypt:Oe,parse:be,populate:xe};h.exports.configDotenv=l.configDotenv;h.exports._configVault=l._configVault;h.exports._parseVault=l._parseVault;h.exports.config=l.config;h.exports.decrypt=l.decrypt;h.exports.parse=l.parse;h.exports.populate=l.populate;h.exports=l});import{Suspense as U}from"react";import{jsx as D}from"react/jsx-runtime";function je(n){let e=b.getInstance(),{data:t,contextProps:r}=n;return t&&e?Array.isArray(t)?D(U,{fallback:null,children:t.map((o,i)=>e.createComponent({data:o,contextProps:r}))}):D(U,{fallback:null,children:e.createComponent({data:t,contextProps:r})}):e?D("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):D("div",{children:"QueenofheartsService is not initialized"})}var y=class extends Error{constructor(e,t){super(t.summary),this.name="ApiError",this.status=e,this.body=t}};import le,{lazy as ue}from"react";import{jsx as p,jsxs as C}from"react/jsx-runtime";var T,A,O,q,x;try{T=m("@mui/material/Accordion").default,A=m("@mui/material/AccordionSummary").default,O=m("@mui/material/AccordionDetails").default,q=m("@mui/material/Paper").default,x=m("@mui/icons-material/ExpandMore").default}catch(n){T=({children:e,style:t})=>p("details",{style:t,children:e}),A=({children:e})=>p("summary",{children:e}),O=({children:e})=>p("div",{style:{paddingLeft:"1em"},children:e}),q=({children:e,style:t})=>p("div",{style:_(v({},t),{border:"1px solid #ccc",padding:".5em"}),children:e}),x=()=>p("span",{children:"\u25BC"})}function ae(n,e,t){return C(T,{style:{width:"100%"},children:[C(A,{style:{padding:0},expandIcon:p(x,{}),children:[n,": Array[",e.length,"]"]}),p(O,{children:e.map((r,o)=>$("",r,o))})]},`${n}_${t}`)}function ce(n,e,t){return C(T,{style:{width:"100%"},children:[p(A,{expandIcon:p(x,{}),children:n}),p(O,{children:Object.entries(e).map((r,o)=>$(r[0],r[1],o))})]},`${n}_${t}`)}function B(n,e,t){return C("div",{children:[n,": ",`${e}`]},`${n}_${t}`)}function $(n,e,t){var o;if(Array.isArray(e))return ae(n,e,t);if(!e||["string","number"].includes(typeof e))return B(n,e,t);if(typeof e=="boolean")return B(n,e?"true":"false",t);let r=`${n?n+": ":""}${(o=e.__typename)!=null?o:"object"}`;return ce(r,e,t)}function V(n){return typeof n.data=="object"?p(q,{style:{margin:".5em",width:"calc(100% - 1em)"},children:$("",n.data,1)}):null}var de=(o=>(o.eq="eq",o.in="in",o.neq="neq",o.notIn="notIn",o))(de||{}),fe="https://headless.li/api",f={};function Ue(n){delete f[n]}function Be(n,e,t,r){if(e!==void 0&&(r||f[e]===void 0)){let o={component:n,fieldNames:t};f[e]=o}}function Ke(n,e,t,r=!1){e?(r||f[e]===void 0)&&(f[e]={fieldNames:t,loader:n}):console.warn("registerComponent failed: undefined typeName ")}function pe(){return f}var Ye=n=>g(null,null,function*(){let e=b.getInstance(),t=e.findComponentsInProps(n).filter((o,i,s)=>s.indexOf(o)===i);return(yield e.fetchDynamicComponents(t)).filter(o=>o!==null)}),b=class n{constructor(e,t){this.latestUrl="";this.latestData={};this.findComponentsInProps=e=>{if(e&&typeof e!="string"){let t=e.__typename?[e.__typename]:[],r=Array.isArray(e)?e:Object.values(e);return[...t,...r.reduce((i,s)=>{let a=this.findComponentsInProps(s);return a&&(i=[...i,...a]),i},[])]}return[]};this.fetchDynamicComponents=e=>g(this,null,function*(){let t=!1,r=!1,o=Promise.all(e.map(i=>g(this,null,function*(){var s;return f[i]&&f[i].component===void 0?(t=!0,yield this.loadAsyncComponent(i)):(s=f[i])!=null&&s.loader?i:null})));return r=!0,o});this.buildUrl=e=>{var r;return`${(r=this.localServer)!=null?r:fe}/${e}`};this.queryGraphql=e=>g(this,null,function*(){let t=this.buildUrl("execGraphqlQuery");if(console.info(`using url : ${t}`),t){let r=yield fetch(t,{method:"POST",headers:{Authorization:`Bearer ${this.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify({query:e})});if(r.ok){let o=yield r.json();return this.sendDebugEvent(),o}else{let o=yield r.json();throw console.log(o),new y(r.status,o)}}throw new y(500,{id:"99",summary:"queryUrl was not set",details:`LocalServer: ${this.localServer}`})});this.query=(e,t)=>g(this,null,function*(){var i,s;let r=this.buildUrl("execQuery"),o=t!=null&&t.variables?v({},t.variables):{};if(t!=null&&t.locale&&(o.locale=t.locale),t!=null&&t.filter&&Array.isArray(t.filter)&&(o.filter||(o.filter=[]),o.filter.push(...t.filter),(i=t==null?void 0:t.variables)!=null&&i.filter&&Array.isArray(t.variables.filter)&&o.filter.push(...t.variables.filter)),r&&t){let a=yield fetch(r,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiToken}`},method:"POST",credentials:"include",body:JSON.stringify({queryname:e,variables:o,components:this.getRegisteredComponentsWithFields(),ignoreProperties:t.ignoreProperties,depth:t.depth})});if(a.ok){let c=(s=yield a.json())==null?void 0:s.data,u=this.debug?this.injectIds(c):c;return this.latestData=u,this.sendDebugEvent(),u}else try{let c=yield a.json();throw console.log(c),new y(a.status,c)}catch(c){throw new y(a.status,c.toString())}}else throw new y(500,{id:"99",summary:`Query: queryUrl (${r}) or options are invalid`,details:`queryUrl: ${r}`})});this.getRegisteredComponentsWithFields=()=>{let e={},t=Object.entries(pe());return t&&Array.isArray(t)&&t.forEach(([r,o])=>{let i={},s=o.fieldNames,a=!1;s&&Array.isArray(s)&&s.forEach(c=>{i[c]=!0,a=!0}),a?e[r]=i:e[r]={__all:!0}}),e};this.getQueries=()=>g(this,null,function*(){let e=this.buildUrl("queries");if(e){let t=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json"}});if(t.ok)try{return yield t.json()}catch(r){console.error(r)}}else console.error("api, uri and CMSToken have to be provided");return""});this.apiToken=e,this.localServer=t,this.debug=typeof document!="undefined"&&document.getElementsByTagName("body")[0].classList.contains("qoh-inject-ids"),this.debug&&typeof globalThis.window!="undefined"&&(globalThis.window.addEventListener("QueenOfHearts-RequestData",()=>{this.sendDebugEvent()}),globalThis.window.addEventListener("QueenOfHearts-RequestQueries",()=>{this.sendQueriesEvent()}),globalThis.window.addEventListener("QueenOfHearts-HighlightComponent",(r=>{this.highlightComponent(r.detail)})),globalThis.window.addEventListener("QueenOfHearts-RequestComponentHTML",(r=>{this.sendComponentHTML(r.detail)})))}static init(e,t){n.instance=new n(e,t)}static getInstance(){return n.instance||console.error("QueenofheartsService was not initialized using QueenofheartsService.init(backend, apiToken)"),n.instance}loadAsyncComponent(e){return g(this,null,function*(){let t=f[e];if(t&&t.component===void 0){if(!(t!=null&&t.component)&&t.loader){let r=t.loader,o=yield r();o?f[e].component=o.default:(console.error(`error loading ${e}`),console.error(o))}return e}return null})}createComponent(e){var a;let{data:t,contextProps:r={}}=e,o=t.__typename,i=f[o];i&&i.loader&&ue(i.loader);let s=(a=i==null?void 0:i.component)!=null?a:V;return le.createElement(s,_(v({},t),{contextProps:r}))}injectIds(e){if(Array.isArray(e))e.forEach(t=>this.injectIds(t));else if(e&&typeof e=="object"){if(e.hasOwnProperty("__typename")){let t=Math.random().toString();e.__qohId=t.substr(t.indexOf(".")+1)}Object.keys(e).forEach(t=>e[t]=this.injectIds(e[t]))}return e}sendDebugEvent(){if(typeof window=="undefined")return;let e={registeredComponents:Object.keys(f),url:this.latestUrl,data:this.latestData},t=new CustomEvent("QueenOfHearts-DebuggingData",{detail:e});window.dispatchEvent(t)}sendQueriesEvent(){return g(this,null,function*(){if(typeof window=="undefined")return;let e=new CustomEvent("QueenOfHearts-AvailableQueries",{detail:yield this.getQueries()});window.dispatchEvent(e)})}sendComponentHTML(e){var r;if(typeof window=="undefined")return;let t=(r=document.querySelector(`[qohId='${e}']`))==null?void 0:r.nextElementSibling;if(t){let o=new CustomEvent("QueenOfHearts-SelectedComponentHTML",{detail:{qohId:e,html:t.outerHTML}});window.dispatchEvent(o)}}highlightComponent(e){var i;let t=[{outline:"thick auto white"},{outline:"thick auto red"}],r={duration:1e3,iterations:2},o=(i=document.querySelector(`[qohId='${e}']`))==null?void 0:i.nextElementSibling;o&&o.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),o&&o.animate(t,r)}};var I=class{constructor(e){this.token="";this.uri="https://graphql.datocms.com/";this.token=e}renameSEOMetaTags(e){e.forEach(function(t,r,o){o[r].__typename="SEOMetaTag"})}normalize(e){if(e)return e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(t=>{Array.isArray(e[t])&&(e[t]=e[t].map(r=>this.normalize(r))),e[t]&&typeof e[t]=="object"&&(e[t]=this.normalize(e[t]))}),e}};var X=se(W());X.default.config();var S=class{constructor(e,t){this.token="";this.uri="";this.token=e,this.uri=t}renameSEOMetaTags(e){e.forEach(function(t,r,o){o[r].__typename="SEOMetaTag"})}normalize(e){return e&&(e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(t=>{Array.isArray(e[t])&&(e[t]=e[t].map(r=>this.normalize(r))),e[t]&&typeof e[t]=="object"&&(e[t]=this.normalize(e[t]))}),e)}};export{y as ApiError,I as DatoCMS,de as Filter,je as QueenofheartsRenderComponent,b as QueenofheartsService,S as StrapiCMS,f as componentRegistry,Ye as fetchDynamicComponents,pe as getAllregisteredComponents,Be as registerComponent,Ke as registerLazyComponent,Ue as unregisterComponent};
1
+ var D=Object.defineProperty,Q=Object.defineProperties;var k=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var A=(r,e,n)=>e in r?D(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n,y=(r,e)=>{for(var n in e||(e={}))F.call(e,n)&&A(r,n,e[n]);if(x)for(var n of x(e))P.call(e,n)&&A(r,n,e[n]);return r},g=(r,e)=>Q(r,k(e));var u=(r,e,n)=>new Promise((t,i)=>{var o=a=>{try{s(n.next(a))}catch(p){i(p)}},c=a=>{try{s(n.throw(a))}catch(p){i(p)}},s=a=>a.done?t(a.value):Promise.resolve(a.value).then(o,c);s((n=n.apply(r,e)).next())});import{Suspense as T}from"react";import{jsx as b}from"react/jsx-runtime";function ee(r){let e=h.getInstance(),{data:n,contextProps:t}=r;return n&&e?Array.isArray(n)?b(T,{fallback:null,children:n.map((i,o)=>e.createComponent({data:i,contextProps:t}))}):b(T,{fallback:null,children:e.createComponent({data:n,contextProps:t})}):e?b("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):b("div",{children:"QueenofheartsService is not initialized"})}var m=class extends Error{constructor(e,n){super(n.summary),this.name="ApiError",this.status=e,this.body=n}};import J,{lazy as N}from"react";import*as f from"react";import{jsx as l,jsxs as w}from"react/jsx-runtime";var $=({children:r,style:e})=>l("details",{style:e,children:r}),L=({children:r})=>l("summary",{children:r}),M=({children:r})=>l("div",{style:{paddingLeft:"1em"},children:r}),q=({children:r,style:e})=>l("div",{style:g(y({},e),{border:"1px solid #ccc",padding:".5em"}),children:r}),z=()=>l("span",{children:"\u25BC"}),j=f.lazy(()=>import("@mui/material/Accordion").catch(()=>({default:$}))),R=f.lazy(()=>import("@mui/material/AccordionSummary").catch(()=>({default:L}))),I=f.lazy(()=>import("@mui/material/AccordionDetails").catch(()=>({default:M}))),B=f.lazy(()=>import("@mui/material/Paper").catch(()=>({default:q}))),_=f.lazy(()=>import("@mui/icons-material/ExpandMore").catch(()=>({default:z})));function H(r,e,n){return w(j,{style:{width:"100%"},children:[w(R,{style:{padding:0},expandIcon:l(_,{}),children:[r,": Array[",e.length,"]"]}),l(I,{children:e.map((t,i)=>v("",t,i))})]},`${r}_${n}`)}function U(r,e,n){return w(j,{style:{width:"100%"},children:[l(R,{expandIcon:l(_,{}),children:r}),l(I,{children:Object.entries(e).map((t,i)=>v(t[0],t[1],i))})]},`${r}_${n}`)}function O(r,e,n){return w("div",{children:[r,": ",`${e}`]},`${r}_${n}`)}function v(r,e,n){var i;if(Array.isArray(e))return H(r,e,n);if(!e||["string","number"].includes(typeof e))return O(r,e,n);if(typeof e=="boolean")return O(r,e?"true":"false",n);let t=`${r?r+": ":""}${(i=e.__typename)!=null?i:"object"}`;return U(t,e,n)}function S(r){return typeof r.data=="object"?l(f.Suspense,{fallback:l(q,{style:{margin:".5em",width:"calc(100% - 1em)"},children:v("",r.data,1)}),children:l(B,{style:{margin:".5em",width:"calc(100% - 1em)"},children:v("",r.data,1)})}):null}var X=(i=>(i.eq="eq",i.in="in",i.neq="neq",i.notIn="notIn",i))(X||{}),W="https://headless.li/api",d={};function ue(r){delete d[r]}function me(r,e,n,t){if(e!==void 0&&(t||d[e]===void 0)){let i={component:r,fieldNames:n};d[e]=i}}function fe(r,e,n,t=!1){e?(t||d[e]===void 0)&&(d[e]={fieldNames:n,loader:r}):console.warn("registerComponent failed: undefined typeName ")}function G(){return d}var pe=r=>u(null,null,function*(){let e=h.getInstance(),n=e.findComponentsInProps(r).filter((i,o,c)=>c.indexOf(i)===o);return(yield e.fetchDynamicComponents(n)).filter(i=>i!==null)}),h=class r{constructor(e,n){this.latestUrl="";this.latestData={};this.findComponentsInProps=e=>{if(e&&typeof e!="string"){let n=e.__typename?[e.__typename]:[],t=Array.isArray(e)?e:Object.values(e);return[...n,...t.reduce((o,c)=>{let s=this.findComponentsInProps(c);return s&&(o=[...o,...s]),o},[])]}return[]};this.fetchDynamicComponents=e=>u(this,null,function*(){let n=!1,t=!1,i=Promise.all(e.map(o=>u(this,null,function*(){var c;return d[o]&&d[o].component===void 0?(n=!0,yield this.loadAsyncComponent(o)):(c=d[o])!=null&&c.loader?o:null})));return t=!0,i});this.buildUrl=e=>{var t;return`${(t=this.localServer)!=null?t:W}/${e}`};this.queryGraphql=e=>u(this,null,function*(){let n=this.buildUrl("execGraphqlQuery");if(console.info(`using url : ${n}`),n){let t=yield fetch(n,{method:"POST",headers:{Authorization:`Bearer ${this.apiToken}`,"Content-Type":"application/json"},body:JSON.stringify({query:e})});if(t.ok){let i=yield t.json();return this.sendDebugEvent(),i}else{let i=yield t.json();throw console.log(i),new m(t.status,i)}}throw new m(500,{id:"99",summary:"queryUrl was not set",details:`LocalServer: ${this.localServer}`})});this.query=(e,n)=>u(this,null,function*(){var o,c;let t=this.buildUrl("execQuery"),i=n!=null&&n.variables?y({},n.variables):{};if(n!=null&&n.locale&&(i.locale=n.locale),n!=null&&n.filter&&Array.isArray(n.filter)&&(i.filter||(i.filter=[]),i.filter.push(...n.filter),(o=n==null?void 0:n.variables)!=null&&o.filter&&Array.isArray(n.variables.filter)&&i.filter.push(...n.variables.filter)),t&&n){let s=yield fetch(t,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiToken}`},method:"POST",credentials:"include",body:JSON.stringify({queryname:e,variables:i,components:this.getRegisteredComponentsWithFields(),ignoreProperties:n.ignoreProperties,depth:n.depth})});if(s.ok){let a=(c=yield s.json())==null?void 0:c.data,p=this.debug?this.injectIds(a):a;return this.latestData=p,this.sendDebugEvent(),p}else try{let a=yield s.json();throw console.log(a),new m(s.status,a)}catch(a){throw new m(s.status,a.toString())}}else throw new m(500,{id:"99",summary:`Query: queryUrl (${t}) or options are invalid`,details:`queryUrl: ${t}`})});this.getRegisteredComponentsWithFields=()=>{let e={},n=Object.entries(G());return n&&Array.isArray(n)&&n.forEach(([t,i])=>{let o={},c=i.fieldNames,s=!1;c&&Array.isArray(c)&&c.forEach(a=>{o[a]=!0,s=!0}),s?e[t]=o:e[t]={__all:!0}}),e};this.getQueries=()=>u(this,null,function*(){let e=this.buildUrl("queries");if(e){let n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json"}});if(n.ok)try{return yield n.json()}catch(t){console.error(t)}}else console.error("api, uri and CMSToken have to be provided");return""});this.apiToken=e,this.localServer=n,this.debug=typeof document!="undefined"&&document.getElementsByTagName("body")[0].classList.contains("qoh-inject-ids"),this.debug&&typeof globalThis.window!="undefined"&&(globalThis.window.addEventListener("QueenOfHearts-RequestData",()=>{this.sendDebugEvent()}),globalThis.window.addEventListener("QueenOfHearts-RequestQueries",()=>{this.sendQueriesEvent()}),globalThis.window.addEventListener("QueenOfHearts-HighlightComponent",(t=>{this.highlightComponent(t.detail)})),globalThis.window.addEventListener("QueenOfHearts-RequestComponentHTML",(t=>{this.sendComponentHTML(t.detail)})))}static init(e,n){r.instance=new r(e,n)}static getInstance(){return r.instance||console.error("QueenofheartsService was not initialized using QueenofheartsService.init(backend, apiToken)"),r.instance}loadAsyncComponent(e){return u(this,null,function*(){let n=d[e];if(n&&n.component===void 0){if(!(n!=null&&n.component)&&n.loader){let t=n.loader,i=yield t();i?d[e].component=i.default:(console.error(`error loading ${e}`),console.error(i))}return e}return null})}createComponent(e){var s;let{data:n,contextProps:t={}}=e,i=n.__typename,o=d[i];o&&o.loader&&N(o.loader);let c=(s=o==null?void 0:o.component)!=null?s:S;return J.createElement(c,g(y({},n),{contextProps:t}))}injectIds(e){if(Array.isArray(e))e.forEach(n=>this.injectIds(n));else if(e&&typeof e=="object"){if(e.hasOwnProperty("__typename")){let n=Math.random().toString();e.__qohId=n.substr(n.indexOf(".")+1)}Object.keys(e).forEach(n=>e[n]=this.injectIds(e[n]))}return e}sendDebugEvent(){if(typeof window=="undefined")return;let e={registeredComponents:Object.keys(d),url:this.latestUrl,data:this.latestData},n=new CustomEvent("QueenOfHearts-DebuggingData",{detail:e});window.dispatchEvent(n)}sendQueriesEvent(){return u(this,null,function*(){if(typeof window=="undefined")return;let e=new CustomEvent("QueenOfHearts-AvailableQueries",{detail:yield this.getQueries()});window.dispatchEvent(e)})}sendComponentHTML(e){var t;if(typeof window=="undefined")return;let n=(t=document.querySelector(`[qohId='${e}']`))==null?void 0:t.nextElementSibling;if(n){let i=new CustomEvent("QueenOfHearts-SelectedComponentHTML",{detail:{qohId:e,html:n.outerHTML}});window.dispatchEvent(i)}}highlightComponent(e){var o;let n=[{outline:"thick auto white"},{outline:"thick auto red"}],t={duration:1e3,iterations:2},i=(o=document.querySelector(`[qohId='${e}']`))==null?void 0:o.nextElementSibling;i&&i.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),i&&i.animate(n,t)}};var C=class{constructor(e){this.token="";this.uri="https://graphql.datocms.com/";this.token=e}renameSEOMetaTags(e){e.forEach(function(n,t,i){i[t].__typename="SEOMetaTag"})}normalize(e){if(e)return e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(t=>this.normalize(t))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e}};var E=class{constructor(e,n){this.token="";this.uri="";this.token=e,this.uri=n}renameSEOMetaTags(e){e.forEach(function(n,t,i){i[t].__typename="SEOMetaTag"})}normalize(e){return e&&(e._seoMetaTags&&this.renameSEOMetaTags(e._seoMetaTags),Object.keys(e).forEach(n=>{Array.isArray(e[n])&&(e[n]=e[n].map(t=>this.normalize(t))),e[n]&&typeof e[n]=="object"&&(e[n]=this.normalize(e[n]))}),e)}};export{m as ApiError,C as DatoCMS,X as Filter,ee as QueenofheartsRenderComponent,h as QueenofheartsService,E as StrapiCMS,d as componentRegistry,pe as fetchDynamicComponents,G as getAllregisteredComponents,me as registerComponent,fe as registerLazyComponent,ue as unregisterComponent};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qoh/core-react",
3
3
  "description": "Queen of hearts Core React API",
4
- "version": "1.0.0-rc.10",
4
+ "version": "1.0.0-rc.12",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
7
7
  "module": "lib/index.mjs",
@@ -19,9 +19,9 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "test": "jest --passWithNoTests",
22
- "build:prod": "tsup src/index.tsx --format esm,cjs --dts --minify --clean --out-dir lib",
22
+ "build:prod": "tsup",
23
23
  "build": "npm run build:prod",
24
- "build:dev": "tsup src/index.ts --format esm,cjs --dts --clean --out-dir lib",
24
+ "build:dev": "tsup --no-minify",
25
25
  "prepublishOnly": "npm run build:prod",
26
26
  "release": "npm publish --access public"
27
27
  },
@@ -46,8 +46,7 @@
46
46
  "@types/react": "^17.0.0",
47
47
  "@types/react-dom": "^17.0.0",
48
48
  "cross-env": "^7.0.3",
49
- "dotenv": "^16.4.5",
50
- "identity-obj-proxy": "^3.0.0",
49
+ "identity-obj-proxy": "^3.0.0",
51
50
  "jest": "^29.7.0",
52
51
  "next": "^16.2.4",
53
52
  "prettier": "^3.3.3",