@nordcraft/runtime 1.0.34 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/createNode.js +3 -3
- package/dist/components/createNode.js.map +1 -1
- package/dist/custom-element.main.esm.js +1 -1
- package/dist/custom-element.main.esm.js.map +2 -2
- package/dist/editor/graphql.d.ts +12 -0
- package/dist/editor/graphql.js +150 -0
- package/dist/editor/graphql.js.map +1 -0
- package/dist/editor-preview.main.js +77 -42
- package/dist/editor-preview.main.js.map +1 -1
- package/dist/page.main.esm.js +1 -1
- package/dist/page.main.esm.js.map +2 -2
- package/package.json +3 -3
- package/src/components/createNode.ts +3 -3
- package/src/editor/graphql.ts +167 -0
- package/src/editor-preview.main.ts +239 -176
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://github.com/nordcraftengine/nordcraft",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@nordcraft/core": "1.0.
|
|
8
|
-
"@nordcraft/std-lib": "1.0.
|
|
7
|
+
"@nordcraft/core": "1.0.36",
|
|
8
|
+
"@nordcraft/std-lib": "1.0.36",
|
|
9
9
|
"fast-deep-equal": "3.1.3",
|
|
10
10
|
"path-to-regexp": "6.3.0"
|
|
11
11
|
},
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"files": ["dist", "src"],
|
|
22
22
|
"main": "dist/page.main.js",
|
|
23
23
|
"types": "dist/page.main.d.ts",
|
|
24
|
-
"version": "1.0.
|
|
24
|
+
"version": "1.0.36"
|
|
25
25
|
}
|
|
@@ -121,14 +121,14 @@ export function createNode({
|
|
|
121
121
|
|
|
122
122
|
if (!parentElement || ctx.root.contains(parentElement) === false) {
|
|
123
123
|
console.error(
|
|
124
|
-
`Conditional: Parent element does not exist for "${path}" This is likely due to the DOM being modified outside of
|
|
124
|
+
`Conditional: Parent element does not exist for "${path}" This is likely due to the DOM being modified outside of Nordcraft.`,
|
|
125
125
|
)
|
|
126
126
|
return
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
if (parentElement.querySelector(`[data-id="${path}"]`)) {
|
|
130
130
|
console.warn(
|
|
131
|
-
`Conditional: Element with data-id="${path}" already exists. This is likely due to the DOM being modified outside of
|
|
131
|
+
`Conditional: Element with data-id="${path}" already exists. This is likely due to the DOM being modified outside of Nordcraft`,
|
|
132
132
|
)
|
|
133
133
|
return
|
|
134
134
|
}
|
|
@@ -315,7 +315,7 @@ export function createNode({
|
|
|
315
315
|
|
|
316
316
|
if (!parentElement || ctx.root.contains(parentElement) === false) {
|
|
317
317
|
console.error(
|
|
318
|
-
`Repeat: Parent element does not exist for ${path}. This is likely due to the DOM being modified outside of
|
|
318
|
+
`Repeat: Parent element does not exist for ${path}. This is likely due to the DOM being modified outside of Nordcraft.`,
|
|
319
319
|
)
|
|
320
320
|
return
|
|
321
321
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApiRequest,
|
|
3
|
+
HttpMethodsWithAllowedBody,
|
|
4
|
+
} from '@nordcraft/core/dist/api/api'
|
|
5
|
+
import { ApiMethod, type ApiRequest } from '@nordcraft/core/dist/api/apiTypes'
|
|
6
|
+
import type { FormulaContext } from '@nordcraft/core/dist/formula/formula'
|
|
7
|
+
import { PROXY_URL_HEADER } from '@nordcraft/core/dist/utils/url'
|
|
8
|
+
|
|
9
|
+
const INTROSPECTION_QUERY = `\
|
|
10
|
+
query IntrospectionQuery {
|
|
11
|
+
__schema {
|
|
12
|
+
queryType { ...FullType }
|
|
13
|
+
mutationType { ...FullType }
|
|
14
|
+
subscriptionType { ...FullType }
|
|
15
|
+
types {
|
|
16
|
+
...FullType
|
|
17
|
+
}
|
|
18
|
+
directives {
|
|
19
|
+
name
|
|
20
|
+
description
|
|
21
|
+
locations
|
|
22
|
+
args {
|
|
23
|
+
...InputValue
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
fragment FullType on __Type {
|
|
29
|
+
kind
|
|
30
|
+
name
|
|
31
|
+
description
|
|
32
|
+
fields(includeDeprecated: true) {
|
|
33
|
+
name
|
|
34
|
+
description
|
|
35
|
+
args {
|
|
36
|
+
...InputValue
|
|
37
|
+
}
|
|
38
|
+
type {
|
|
39
|
+
...TypeRef
|
|
40
|
+
}
|
|
41
|
+
isDeprecated
|
|
42
|
+
deprecationReason
|
|
43
|
+
}
|
|
44
|
+
inputFields {
|
|
45
|
+
...InputValue
|
|
46
|
+
}
|
|
47
|
+
interfaces {
|
|
48
|
+
...TypeRef
|
|
49
|
+
}
|
|
50
|
+
enumValues(includeDeprecated: true) {
|
|
51
|
+
name
|
|
52
|
+
description
|
|
53
|
+
isDeprecated
|
|
54
|
+
deprecationReason
|
|
55
|
+
}
|
|
56
|
+
possibleTypes {
|
|
57
|
+
...TypeRef
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
fragment InputValue on __InputValue {
|
|
61
|
+
name
|
|
62
|
+
description
|
|
63
|
+
type { ...TypeRef }
|
|
64
|
+
defaultValue
|
|
65
|
+
}
|
|
66
|
+
fragment TypeRef on __Type {
|
|
67
|
+
kind
|
|
68
|
+
name
|
|
69
|
+
ofType {
|
|
70
|
+
kind
|
|
71
|
+
name
|
|
72
|
+
ofType {
|
|
73
|
+
kind
|
|
74
|
+
name
|
|
75
|
+
ofType {
|
|
76
|
+
kind
|
|
77
|
+
name
|
|
78
|
+
ofType {
|
|
79
|
+
kind
|
|
80
|
+
name
|
|
81
|
+
ofType {
|
|
82
|
+
kind
|
|
83
|
+
name
|
|
84
|
+
ofType {
|
|
85
|
+
kind
|
|
86
|
+
name
|
|
87
|
+
ofType {
|
|
88
|
+
kind
|
|
89
|
+
name
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}`
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Run an introspection query for an existing API
|
|
101
|
+
* The introspection will usually be a POST request, but we use the method
|
|
102
|
+
* from the original API to support other methods.
|
|
103
|
+
*/
|
|
104
|
+
export const introspectApiRequest = async ({
|
|
105
|
+
api,
|
|
106
|
+
componentName,
|
|
107
|
+
formulaContext,
|
|
108
|
+
}: {
|
|
109
|
+
api: ApiRequest
|
|
110
|
+
componentName: string
|
|
111
|
+
formulaContext: FormulaContext
|
|
112
|
+
}) => {
|
|
113
|
+
const { url, requestSettings } = createApiRequest({
|
|
114
|
+
api: {
|
|
115
|
+
...(api as ApiRequest),
|
|
116
|
+
// Default to a POST request if the method of the original API doesn't support a body
|
|
117
|
+
// The introspection query should never be initiated in that case though
|
|
118
|
+
method: HttpMethodsWithAllowedBody.includes(api.method ?? ApiMethod.POST)
|
|
119
|
+
? api.method
|
|
120
|
+
: ApiMethod.POST,
|
|
121
|
+
// Overwrite the body with a default introspection query (in a value formula)
|
|
122
|
+
body: {
|
|
123
|
+
type: 'value',
|
|
124
|
+
value: { query: INTROSPECTION_QUERY },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
baseUrl: window.origin,
|
|
128
|
+
defaultHeaders: undefined,
|
|
129
|
+
formulaContext,
|
|
130
|
+
})
|
|
131
|
+
// We must proxy to be able to include cookies
|
|
132
|
+
const proxyUrl = `/.toddle/omvej/components/${encodeURIComponent(
|
|
133
|
+
componentName,
|
|
134
|
+
)}/apis/${encodeURIComponent(componentName)}:${encodeURIComponent(api.name)}`
|
|
135
|
+
const headers = new Headers(requestSettings.headers)
|
|
136
|
+
headers.set(
|
|
137
|
+
PROXY_URL_HEADER,
|
|
138
|
+
decodeURIComponent(url.href.replace(/\+/g, ' ')),
|
|
139
|
+
)
|
|
140
|
+
requestSettings.headers = headers
|
|
141
|
+
const response = await fetch(proxyUrl, {
|
|
142
|
+
...requestSettings,
|
|
143
|
+
// Set credentials to what was set on the original API
|
|
144
|
+
credentials:
|
|
145
|
+
api.client?.credentials &&
|
|
146
|
+
['include', 'same-origin', 'omit'].includes(api.client.credentials)
|
|
147
|
+
? api.client.credentials
|
|
148
|
+
: // Default to same-origin
|
|
149
|
+
undefined,
|
|
150
|
+
})
|
|
151
|
+
try {
|
|
152
|
+
const data = await response.json()
|
|
153
|
+
if (response.ok) {
|
|
154
|
+
return data
|
|
155
|
+
} else {
|
|
156
|
+
// eslint-disable-next-line no-console
|
|
157
|
+
console.error('Failed to introspect API:', api.name, data)
|
|
158
|
+
// Return a generic error message if introspection failed
|
|
159
|
+
return { error: data?.message ?? 'Failed to parse introspection result' }
|
|
160
|
+
}
|
|
161
|
+
} catch (e) {
|
|
162
|
+
// eslint-disable-next-line no-console
|
|
163
|
+
console.error('Failed to parses API response:', api.name, e)
|
|
164
|
+
// Return a generic error message if introspection failed
|
|
165
|
+
return { error: `Failed to introspect API: ${api.name}` }
|
|
166
|
+
}
|
|
167
|
+
}
|