@qoh/core-react 1.0.0-rc.7 → 1.0.0-rc.9
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/LICENSE.md +21 -0
- package/README.md +33 -0
- package/lib/index.d.mts +123 -0
- package/lib/index.d.ts +123 -0
- package/lib/index.js +3 -0
- package/lib/index.mjs +3 -0
- package/package.json +68 -20
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 gravity&storm GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Queen of hearts client core package
|
|
2
|
+
|
|
3
|
+
> [!WARNING] This readme should not be deployed to npm.
|
|
4
|
+
|
|
5
|
+
This package is providing the core client packages in react.
|
|
6
|
+
|
|
7
|
+
# Running locally
|
|
8
|
+
|
|
9
|
+
Run
|
|
10
|
+
|
|
11
|
+
`npx nx serve server-vercel`
|
|
12
|
+
|
|
13
|
+
from the root directory.
|
|
14
|
+
|
|
15
|
+
## Reading Vercel logs from CLI
|
|
16
|
+
|
|
17
|
+
Vercel logs can be read on the web-interface but vercel also provides a cli-tool that can be setup to show the server logs in the cli.
|
|
18
|
+
|
|
19
|
+
### installation
|
|
20
|
+
|
|
21
|
+
`npm i -g vercel`
|
|
22
|
+
|
|
23
|
+
### Setup team
|
|
24
|
+
|
|
25
|
+
Make sure you are on the right team by switching to gravityandstorm:
|
|
26
|
+
|
|
27
|
+
`vercel switch gravityandstorm`
|
|
28
|
+
|
|
29
|
+
### showing logs in cli
|
|
30
|
+
|
|
31
|
+
Make sure you get the url of the deployment you want to watch. For example:
|
|
32
|
+
|
|
33
|
+
`vercel logs queenofhearts-9qnjgvnfw-gravityandstorm.vercel.app`
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { JSX } from 'react';
|
|
3
|
+
|
|
4
|
+
declare function QueenofheartsRenderComponent(props: Readonly<{
|
|
5
|
+
data: {} | [];
|
|
6
|
+
contextProps?: any;
|
|
7
|
+
}>): react_jsx_runtime.JSX.Element;
|
|
8
|
+
|
|
9
|
+
declare enum Filter {
|
|
10
|
+
eq = "eq",
|
|
11
|
+
in = "in",
|
|
12
|
+
neq = "neq",
|
|
13
|
+
notIn = "notIn"
|
|
14
|
+
}
|
|
15
|
+
interface QohResponse {
|
|
16
|
+
pages: {} | null;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
type ComponentTypes = Array<{
|
|
20
|
+
typename: string;
|
|
21
|
+
props: {
|
|
22
|
+
__typename: string;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
interface IFCDictionary {
|
|
26
|
+
[index: string]: ReactFCWithFieldNames;
|
|
27
|
+
}
|
|
28
|
+
interface ReactFCWithFieldNames {
|
|
29
|
+
component?: React.FC<any>;
|
|
30
|
+
fieldNames?: string[];
|
|
31
|
+
loader?: () => any;
|
|
32
|
+
}
|
|
33
|
+
declare let componentRegistry: IFCDictionary;
|
|
34
|
+
declare function unregisterComponent(name: string): void;
|
|
35
|
+
declare function registerComponent(functionalComponent: React.FC<any>, typeName: string, fieldNames?: string[], overwrite?: false): void;
|
|
36
|
+
declare function registerLazyComponent(loader: () => any, typeName: string, fieldNames?: string[], overwrite?: boolean): void;
|
|
37
|
+
declare function getAllregisteredComponents(): IFCDictionary;
|
|
38
|
+
declare const fetchDynamicComponents: (props: any) => Promise<string[]>;
|
|
39
|
+
declare class QueenofheartsService {
|
|
40
|
+
private static instance;
|
|
41
|
+
data: any;
|
|
42
|
+
debug: boolean;
|
|
43
|
+
apiToken: string;
|
|
44
|
+
localServer?: string;
|
|
45
|
+
latestUrl: string;
|
|
46
|
+
latestData: Object;
|
|
47
|
+
private constructor();
|
|
48
|
+
/**
|
|
49
|
+
* Initialize headlessli client
|
|
50
|
+
* @param apiToken headlessli api-token
|
|
51
|
+
* @param localServer optional
|
|
52
|
+
*/
|
|
53
|
+
static init(apiToken: string, localServer?: string): void;
|
|
54
|
+
static getInstance(): QueenofheartsService;
|
|
55
|
+
findComponentsInProps: (props: any) => string[];
|
|
56
|
+
fetchDynamicComponents: (componentsToLoad: string[]) => Promise<(string | null)[]>;
|
|
57
|
+
private loadAsyncComponent;
|
|
58
|
+
createComponent(props: any): JSX.Element | null;
|
|
59
|
+
private readonly buildUrl;
|
|
60
|
+
queryGraphql: (graphqlQuery: string) => Promise<any>;
|
|
61
|
+
query: (queryName: string, options?: {
|
|
62
|
+
filter?: {
|
|
63
|
+
name: string;
|
|
64
|
+
operator: Filter;
|
|
65
|
+
value: string;
|
|
66
|
+
}[];
|
|
67
|
+
components?: string;
|
|
68
|
+
ignoreProperties?: string[];
|
|
69
|
+
variables?: {
|
|
70
|
+
filter?: {
|
|
71
|
+
name: string;
|
|
72
|
+
operator: Filter;
|
|
73
|
+
value: string;
|
|
74
|
+
}[];
|
|
75
|
+
locale?: string;
|
|
76
|
+
[x: string]: unknown;
|
|
77
|
+
};
|
|
78
|
+
locale?: string;
|
|
79
|
+
depth?: number;
|
|
80
|
+
}) => Promise<any>;
|
|
81
|
+
private readonly getRegisteredComponentsWithFields;
|
|
82
|
+
getQueries: () => Promise<any>;
|
|
83
|
+
private injectIds;
|
|
84
|
+
private sendDebugEvent;
|
|
85
|
+
private sendQueriesEvent;
|
|
86
|
+
private sendComponentHTML;
|
|
87
|
+
private highlightComponent;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface Backend {
|
|
91
|
+
token: string;
|
|
92
|
+
uri: string;
|
|
93
|
+
normalize(data: any): any;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class DatoCMS implements Backend {
|
|
97
|
+
token: string;
|
|
98
|
+
uri: string;
|
|
99
|
+
constructor(token: string);
|
|
100
|
+
renameSEOMetaTags(props: any): void;
|
|
101
|
+
normalize(data: any): any;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare class StrapiCMS implements Backend {
|
|
105
|
+
token: string;
|
|
106
|
+
uri: string;
|
|
107
|
+
constructor(token: string, strapiUrl: string);
|
|
108
|
+
renameSEOMetaTags(props: any): void;
|
|
109
|
+
normalize(data: any): any;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
type Body = {
|
|
113
|
+
id: string;
|
|
114
|
+
summary: string;
|
|
115
|
+
details: string;
|
|
116
|
+
};
|
|
117
|
+
declare class ApiError extends Error {
|
|
118
|
+
status: number;
|
|
119
|
+
body: Body;
|
|
120
|
+
constructor(status: number, body: Body);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { ApiError, type Backend, type ComponentTypes, DatoCMS, Filter, type IFCDictionary, type QohResponse, QueenofheartsRenderComponent, QueenofheartsService, type ReactFCWithFieldNames, StrapiCMS, componentRegistry, fetchDynamicComponents, getAllregisteredComponents, registerComponent, registerLazyComponent, unregisterComponent };
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { JSX } from 'react';
|
|
3
|
+
|
|
4
|
+
declare function QueenofheartsRenderComponent(props: Readonly<{
|
|
5
|
+
data: {} | [];
|
|
6
|
+
contextProps?: any;
|
|
7
|
+
}>): react_jsx_runtime.JSX.Element;
|
|
8
|
+
|
|
9
|
+
declare enum Filter {
|
|
10
|
+
eq = "eq",
|
|
11
|
+
in = "in",
|
|
12
|
+
neq = "neq",
|
|
13
|
+
notIn = "notIn"
|
|
14
|
+
}
|
|
15
|
+
interface QohResponse {
|
|
16
|
+
pages: {} | null;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
type ComponentTypes = Array<{
|
|
20
|
+
typename: string;
|
|
21
|
+
props: {
|
|
22
|
+
__typename: string;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
interface IFCDictionary {
|
|
26
|
+
[index: string]: ReactFCWithFieldNames;
|
|
27
|
+
}
|
|
28
|
+
interface ReactFCWithFieldNames {
|
|
29
|
+
component?: React.FC<any>;
|
|
30
|
+
fieldNames?: string[];
|
|
31
|
+
loader?: () => any;
|
|
32
|
+
}
|
|
33
|
+
declare let componentRegistry: IFCDictionary;
|
|
34
|
+
declare function unregisterComponent(name: string): void;
|
|
35
|
+
declare function registerComponent(functionalComponent: React.FC<any>, typeName: string, fieldNames?: string[], overwrite?: false): void;
|
|
36
|
+
declare function registerLazyComponent(loader: () => any, typeName: string, fieldNames?: string[], overwrite?: boolean): void;
|
|
37
|
+
declare function getAllregisteredComponents(): IFCDictionary;
|
|
38
|
+
declare const fetchDynamicComponents: (props: any) => Promise<string[]>;
|
|
39
|
+
declare class QueenofheartsService {
|
|
40
|
+
private static instance;
|
|
41
|
+
data: any;
|
|
42
|
+
debug: boolean;
|
|
43
|
+
apiToken: string;
|
|
44
|
+
localServer?: string;
|
|
45
|
+
latestUrl: string;
|
|
46
|
+
latestData: Object;
|
|
47
|
+
private constructor();
|
|
48
|
+
/**
|
|
49
|
+
* Initialize headlessli client
|
|
50
|
+
* @param apiToken headlessli api-token
|
|
51
|
+
* @param localServer optional
|
|
52
|
+
*/
|
|
53
|
+
static init(apiToken: string, localServer?: string): void;
|
|
54
|
+
static getInstance(): QueenofheartsService;
|
|
55
|
+
findComponentsInProps: (props: any) => string[];
|
|
56
|
+
fetchDynamicComponents: (componentsToLoad: string[]) => Promise<(string | null)[]>;
|
|
57
|
+
private loadAsyncComponent;
|
|
58
|
+
createComponent(props: any): JSX.Element | null;
|
|
59
|
+
private readonly buildUrl;
|
|
60
|
+
queryGraphql: (graphqlQuery: string) => Promise<any>;
|
|
61
|
+
query: (queryName: string, options?: {
|
|
62
|
+
filter?: {
|
|
63
|
+
name: string;
|
|
64
|
+
operator: Filter;
|
|
65
|
+
value: string;
|
|
66
|
+
}[];
|
|
67
|
+
components?: string;
|
|
68
|
+
ignoreProperties?: string[];
|
|
69
|
+
variables?: {
|
|
70
|
+
filter?: {
|
|
71
|
+
name: string;
|
|
72
|
+
operator: Filter;
|
|
73
|
+
value: string;
|
|
74
|
+
}[];
|
|
75
|
+
locale?: string;
|
|
76
|
+
[x: string]: unknown;
|
|
77
|
+
};
|
|
78
|
+
locale?: string;
|
|
79
|
+
depth?: number;
|
|
80
|
+
}) => Promise<any>;
|
|
81
|
+
private readonly getRegisteredComponentsWithFields;
|
|
82
|
+
getQueries: () => Promise<any>;
|
|
83
|
+
private injectIds;
|
|
84
|
+
private sendDebugEvent;
|
|
85
|
+
private sendQueriesEvent;
|
|
86
|
+
private sendComponentHTML;
|
|
87
|
+
private highlightComponent;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface Backend {
|
|
91
|
+
token: string;
|
|
92
|
+
uri: string;
|
|
93
|
+
normalize(data: any): any;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class DatoCMS implements Backend {
|
|
97
|
+
token: string;
|
|
98
|
+
uri: string;
|
|
99
|
+
constructor(token: string);
|
|
100
|
+
renameSEOMetaTags(props: any): void;
|
|
101
|
+
normalize(data: any): any;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare class StrapiCMS implements Backend {
|
|
105
|
+
token: string;
|
|
106
|
+
uri: string;
|
|
107
|
+
constructor(token: string, strapiUrl: string);
|
|
108
|
+
renameSEOMetaTags(props: any): void;
|
|
109
|
+
normalize(data: any): any;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
type Body = {
|
|
113
|
+
id: string;
|
|
114
|
+
summary: string;
|
|
115
|
+
details: string;
|
|
116
|
+
};
|
|
117
|
+
declare class ApiError extends Error {
|
|
118
|
+
status: number;
|
|
119
|
+
body: Body;
|
|
120
|
+
constructor(status: number, body: Body);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { ApiError, type Backend, type ComponentTypes, DatoCMS, Filter, type IFCDictionary, type QohResponse, QueenofheartsRenderComponent, QueenofheartsService, type ReactFCWithFieldNames, StrapiCMS, componentRegistry, fetchDynamicComponents, getAllregisteredComponents, registerComponent, registerLazyComponent, unregisterComponent };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";var G=Object.create;var b=Object.defineProperty,Z=Object.defineProperties,ee=Object.getOwnPropertyDescriptor,te=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertyNames,k=Object.getOwnPropertySymbols,re=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var R=(n,e,t)=>e in n?b(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,x=(n,e)=>{for(var t in e||(e={}))L.call(e,t)&&R(n,t,e[t]);if(k)for(var t of k(e))oe.call(e,t)&&R(n,t,e[t]);return n},P=(n,e)=>Z(n,te(e));var M=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),ie=(n,e)=>{for(var t in e)b(n,t,{get:e[t],enumerable:!0})},Q=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ne(e))!L.call(n,o)&&o!==t&&b(n,o,{get:()=>e[o],enumerable:!(r=ee(e,o))||r.enumerable});return n};var C=(n,e,t)=>(t=n!=null?G(re(n)):{},Q(e||!n||!n.__esModule?b(t,"default",{value:n,enumerable:!0}):t,n)),se=n=>Q(b({},"__esModule",{value:!0}),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=M((Fe,ge)=>{ge.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=M((Ue,y)=>{"use strict";var $=require("fs"),O=require("path"),he=require("os"),ye=require("crypto"),ve=K(),V=ve.version,be=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;function Ee(n){let e={},t=n.toString();t=t.replace(/\r\n?/mg,`
|
|
2
|
+
`);let r;for(;(r=be.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 we(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=De(t,a);i=l.decrypt(c.ciphertext,c.key);break}catch(a){if(s+1>=o)throw a}return l.parse(i)}function _e(n){console.log(`[dotenv@${V}][WARN] ${n}`)}function _(n){console.log(`[dotenv@${V}][DEBUG] ${n}`)}function H(n){console.log(`[dotenv@${V}] ${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 De(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)$.existsSync(t)&&(e=t.endsWith(".vault")?t:`${t}.vault`);else e=n.path.endsWith(".vault")?n.path:`${n.path}.vault`;else e=O.resolve(process.cwd(),".env.vault");return $.existsSync(e)?e:null}function Y(n){return n[0]==="~"?O.join(he.homedir(),n.slice(1)):n}function Te(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 Ae(n){let e=O.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=[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 f=l.parse($.readFileSync(u,{encoding:t}));l.populate(a,f,n)}catch(f){r&&_(`Failed to load ${u} ${f.message}`),s=f}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,f=[];for(let q of i)try{let T=O.relative(process.cwd(),q);f.push(T)}catch(T){r&&_(`Failed to load ${q} ${T.message}`),s=T}H(`injecting env (${u}) from ${f.join(",")}`)}return s?{parsed:a,error:s}:{parsed:a}}function Oe(n){if(z(n).length===0)return l.configDotenv(n);let e=J(n);return e?l._configVault(n):(_e(`You set DOTENV_KEY but you are missing a .env.vault file at ${e}. Did you forget to build it?`),l.configDotenv(n))}function xe(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=ye.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 f=new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");throw f.code="INVALID_DOTENV_KEY",f}else if(u){let f=new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");throw f.code="DECRYPTION_FAILED",f}else throw s}}function Ce(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:Ae,_configVault:Te,_parseVault:we,config:Oe,decrypt:xe,parse:Ee,populate:Ce};y.exports.configDotenv=l.configDotenv;y.exports._configVault=l._configVault;y.exports._parseVault=l._parseVault;y.exports.config=l.config;y.exports.decrypt=l.decrypt;y.exports.parse=l.parse;y.exports.populate=l.populate;y.exports=l});var Ie={};ie(Ie,{ApiError:()=>h,DatoCMS:()=>w,Filter:()=>U,QueenofheartsRenderComponent:()=>ae,QueenofheartsService:()=>v,StrapiCMS:()=>D,componentRegistry:()=>d,fetchDynamicComponents:()=>me,getAllregisteredComponents:()=>B,registerComponent:()=>fe,registerLazyComponent:()=>pe,unregisterComponent:()=>de});module.exports=se(Ie);var I=require("react");var E=require("react/jsx-runtime");function ae(n){let e=v.getInstance(),{data:t,contextProps:r}=n;return t&&e?Array.isArray(t)?(0,E.jsx)(I.Suspense,{fallback:null,children:t.map((o,i)=>e.createComponent({data:o,contextProps:r}))}):(0,E.jsx)(I.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 h=class extends Error{constructor(e,t){super(t.summary),this.name="ApiError",this.status=e,this.body=t}};var A=C(require("react"));var m=require("@mui/material"),N=C(require("@mui/icons-material/ExpandMore")),p=require("react/jsx-runtime");function ce(n,e,t){return(0,p.jsxs)(m.Accordion,{style:{width:"100%"},children:[(0,p.jsxs)(m.AccordionSummary,{style:{padding:0},expandIcon:(0,p.jsx)(N.default,{}),children:[n,": Array[",e.length,"]"]}),(0,p.jsx)(m.AccordionDetails,{children:e.map((r,o)=>S("",r,o))})]},`${n}_${t}`)}function le(n,e,t){return(0,p.jsxs)(m.Accordion,{style:{width:"100%"},children:[(0,p.jsx)(m.AccordionSummary,{expandIcon:(0,p.jsx)(N.default,{}),children:n}),(0,p.jsx)(m.AccordionDetails,{children:Object.entries(e).map((r,o)=>S(r[0],r[1],o))})]},`${n}_${t}`)}function F(n,e,t){return(0,p.jsxs)("div",{children:[n,": ",`${e}`]},`${n}_${t}`)}function S(n,e,t){var o;if(Array.isArray(e))return ce(n,e,t);if(!e||["string","number"].includes(typeof e))return F(n,e,t);if(typeof e=="boolean")return F(n,e?"true":"false",t);let r=`${n?n+": ":""}${(o=e.__typename)!=null?o:"object"}`;return le(r,e,t)}function j(n){return typeof n.data=="object"?(0,p.jsx)(m.Paper,{style:{margin:".5em",width:"calc(100% - 1em)"},children:S("",n.data,1)}):null}var U=(o=>(o.eq="eq",o.in="in",o.neq="neq",o.notIn="notIn",o))(U||{}),ue="https://headless.li/api",d={};function de(n){delete d[n]}function fe(n,e,t,r){if(e!==void 0&&(r||d[e]===void 0)){let o={component:n,fieldNames:t};d[e]=o}}function pe(n,e,t,r=!1){e?(r||d[e]===void 0)&&(d[e]={fieldNames:t,loader:n}):console.warn("registerComponent failed: undefined typeName ")}function B(){return d}var me=n=>g(null,null,function*(){let e=v.getInstance(),t=e.findComponentsInProps(n).filter((o,i,s)=>s.indexOf(o)===i);return(yield e.fetchDynamicComponents(t)).filter(o=>o!==null)}),v=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 d[i]&&d[i].component===void 0?(t=!0,yield this.loadAsyncComponent(i)):(s=d[i])!=null&&s.loader?i:null})));return r=!0,o});this.buildUrl=e=>{var r;return`${(r=this.localServer)!=null?r:ue}/${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 h(r.status,o)}}throw new h(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?x({},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 h(a.status,c)}catch(c){throw new h(a.status,c.toString())}}else throw new h(500,{id:"99",summary:`Query: queryUrl (${r}) or options are invalid`,details:`queryUrl: ${r}`})});this.getRegisteredComponentsWithFields=()=>{let e={},t=Object.entries(B());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=d[e];if(t&&t.component===void 0){if(!(t!=null&&t.component)&&t.loader){let r=t.loader,o=yield r();o?d[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=d[o];i&&i.loader&&(0,A.lazy)(i.loader);let s=(a=i==null?void 0:i.component)!=null?a:j;return A.default.createElement(s,P(x({},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(d),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 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 X=C(W());X.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});
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var X=Object.create;var O=Object.defineProperty,G=Object.defineProperties,Z=Object.getOwnPropertyDescriptor,ee=Object.getOwnPropertyDescriptors,te=Object.getOwnPropertyNames,$=Object.getOwnPropertySymbols,ne=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var V=(n,e,t)=>e in n?O(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,x=(n,e)=>{for(var t in e||(e={}))q.call(e,t)&&V(n,t,e[t]);if($)for(var t of $(e))re.call(e,t)&&V(n,t,e[t]);return n},k=(n,e)=>G(n,ee(e));var E=(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 R=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var oe=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of te(e))!q.call(n,o)&&o!==t&&O(n,o,{get:()=>e[o],enumerable:!(r=Z(e,o))||r.enumerable});return n};var ie=(n,e,t)=>(t=n!=null?X(ne(n)):{},oe(e||!n||!n.__esModule?O(t,"default",{value:n,enumerable:!0}):t,n));var p=(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 B=R((Xe,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 J=R((Ge,m)=>{"use strict";var N=E("fs"),T=E("path"),ge=E("os"),he=E("crypto"),ye=B(),S=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=z(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=H(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@${S}][WARN] ${n}`)}function v(n){console.log(`[dotenv@${S}][DEBUG] ${n}`)}function Y(n){console.log(`[dotenv@${S}] ${n}`)}function H(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 z(n){let e=null;if(n&&n.path&&n.path.length>0)if(Array.isArray(n.path))for(let t of n.path)N.existsSync(t)&&(e=t.endsWith(".vault")?t:`${t}.vault`);else e=n.path.endsWith(".vault")?n.path:`${n.path}.vault`;else e=T.resolve(process.cwd(),".env.vault");return N.existsSync(e)?e:null}function K(n){return n[0]==="~"?T.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)&&Y("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=T.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&&v("No encoding is specified. UTF-8 is used by default");let i=[e];if(n&&n.path)if(!Array.isArray(n.path))i=[K(n.path)];else{i=[];for(let u of n.path)i.push(K(u))}let s,a={};for(let u of i)try{let d=l.parse(N.readFileSync(u,{encoding:t}));l.populate(a,d,n)}catch(d){r&&v(`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 j of i)try{let b=T.relative(process.cwd(),j);d.push(b)}catch(b){r&&v(`Failed to load ${j} ${b.message}`),s=b}Y(`injecting env (${u}) from ${d.join(",")}`)}return s?{parsed:a,error:s}:{parsed:a}}function Ae(n){if(H(n).length===0)return l.configDotenv(n);let e=z(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&&v(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};m.exports.configDotenv=l.configDotenv;m.exports._configVault=l._configVault;m.exports._parseVault=l._parseVault;m.exports.config=l.config;m.exports.decrypt=l.decrypt;m.exports.parse=l.parse;m.exports.populate=l.populate;m.exports=l});import{Suspense as L}from"react";import{jsx as w}from"react/jsx-runtime";function je(n){let e=y.getInstance(),{data:t,contextProps:r}=n;return t&&e?Array.isArray(t)?w(L,{fallback:null,children:t.map((o,i)=>e.createComponent({data:o,contextProps:r}))}):w(L,{fallback:null,children:e.createComponent({data:t,contextProps:r})}):e?w("div",{className:"error",children:"QueenofheartsRenderComponent: Invalid data received."}):w("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}};import le,{lazy as ue}from"react";import{Accordion as M,AccordionDetails as Q,AccordionSummary as F,Paper as se}from"@mui/material";import U from"@mui/icons-material/ExpandMore";import{jsx as h,jsxs as _}from"react/jsx-runtime";function ae(n,e,t){return _(M,{style:{width:"100%"},children:[_(F,{style:{padding:0},expandIcon:h(U,{}),children:[n,": Array[",e.length,"]"]}),h(Q,{children:e.map((r,o)=>C("",r,o))})]},`${n}_${t}`)}function ce(n,e,t){return _(M,{style:{width:"100%"},children:[h(F,{expandIcon:h(U,{}),children:n}),h(Q,{children:Object.entries(e).map((r,o)=>C(r[0],r[1],o))})]},`${n}_${t}`)}function P(n,e,t){return _("div",{children:[n,": ",`${e}`]},`${n}_${t}`)}function C(n,e,t){var o;if(Array.isArray(e))return ae(n,e,t);if(!e||["string","number"].includes(typeof e))return P(n,e,t);if(typeof e=="boolean")return P(n,e?"true":"false",t);let r=`${n?n+": ":""}${(o=e.__typename)!=null?o:"object"}`;return ce(r,e,t)}function I(n){return typeof n.data=="object"?h(se,{style:{margin:".5em",width:"calc(100% - 1em)"},children:C("",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 Be(n){delete f[n]}function Ke(n,e,t,r){if(e!==void 0&&(r||f[e]===void 0)){let o={component:n,fieldNames:t};f[e]=o}}function Ye(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 He=n=>p(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=>p(this,null,function*(){let t=!1,r=!1,o=Promise.all(e.map(i=>p(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=>p(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)=>p(this,null,function*(){var i,s;let r=this.buildUrl("execQuery"),o=t!=null&&t.variables?x({},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 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(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=()=>p(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 p(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:I;return le.createElement(s,k(x({},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 p(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 D=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 W=ie(J());W.default.config();var A=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{g as ApiError,D as DatoCMS,de as Filter,je as QueenofheartsRenderComponent,y as QueenofheartsService,A as StrapiCMS,f as componentRegistry,He as fetchDynamicComponents,pe as getAllregisteredComponents,Ke as registerComponent,Ye as registerLazyComponent,Be as unregisterComponent};
|
package/package.json
CHANGED
|
@@ -1,21 +1,69 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@qoh/core-react",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "1.0.0-rc.
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"module": "lib/index.
|
|
8
|
-
"types": "lib/index.d.ts",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@qoh/core-react",
|
|
3
|
+
"description": "Queen of hearts Core React API",
|
|
4
|
+
"version": "1.0.0-rc.9",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "lib/index.mjs",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"import": "./lib/index.mjs",
|
|
13
|
+
"require": "./lib/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"lib",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "jest --passWithNoTests",
|
|
22
|
+
"build:prod": "tsup src/index.tsx --format esm,cjs --dts --minify --clean --out-dir lib",
|
|
23
|
+
"build": "npm run build:prod",
|
|
24
|
+
"build:dev": "tsup src/index.ts --format esm,cjs --dts --clean --out-dir lib",
|
|
25
|
+
"prepublishOnly": "npm run build:prod",
|
|
26
|
+
"release": "npm publish --access public"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@mui/icons-material": "^5.16.7 || ^6.0.0",
|
|
30
|
+
"@mui/material": "^5.16.7 || ^6.0.0",
|
|
31
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
32
|
+
"react-dom": " ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@mui/icons-material": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"@mui/material": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@mui/icons-material": "^5.16.7",
|
|
44
|
+
"@mui/material": "^5.16.7",
|
|
45
|
+
"@types/jest": "^29.5.14",
|
|
46
|
+
"@types/react": "^17.0.0",
|
|
47
|
+
"@types/react-dom": "^17.0.0",
|
|
48
|
+
"cross-env": "^7.0.3",
|
|
49
|
+
"dotenv": "^16.4.5",
|
|
50
|
+
"identity-obj-proxy": "^3.0.0",
|
|
51
|
+
"jest": "^29.7.0",
|
|
52
|
+
"next": "^16.2.4",
|
|
53
|
+
"prettier": "^3.3.3",
|
|
54
|
+
"ts-jest": "^29.1.0",
|
|
55
|
+
"tsup": "^8.0.0",
|
|
56
|
+
"typescript": "^5.0.0"
|
|
57
|
+
},
|
|
58
|
+
"jest": {
|
|
59
|
+
"preset": "ts-jest",
|
|
60
|
+
"testEnvironment": "jsdom",
|
|
61
|
+
"testPathIgnorePatterns": [
|
|
62
|
+
"<rootDir>/.next/",
|
|
63
|
+
"<rootDir>/node_modules/"
|
|
64
|
+
],
|
|
65
|
+
"moduleNameMapper": {
|
|
66
|
+
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
21
69
|
}
|