@nordcraft/runtime 1.0.8 → 1.0.10
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/api/createAPIv2.js +53 -50
- package/dist/api/createAPIv2.js.map +1 -1
- package/dist/custom-element.main.esm.js +14 -14
- package/dist/custom-element.main.esm.js.map +3 -3
- package/dist/page.main.esm.js +3 -3
- package/dist/page.main.esm.js.map +3 -3
- package/package.json +4 -4
- package/src/api/createAPIv2.ts +67 -62
package/package.json
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
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.10",
|
|
8
|
+
"@nordcraft/std-lib": "1.0.10",
|
|
9
9
|
"fast-deep-equal": "3.1.3",
|
|
10
10
|
"path-to-regexp": "6.3.0"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@happy-dom/global-registrator": "17.4.
|
|
13
|
+
"@happy-dom/global-registrator": "17.4.7"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "tsc && bun scripts/build.js",
|
|
@@ -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.10"
|
|
25
25
|
}
|
package/src/api/createAPIv2.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
sortObjectEntries,
|
|
32
32
|
} from '@nordcraft/core/dist/utils/collections'
|
|
33
33
|
import { PROXY_URL_HEADER, validateUrl } from '@nordcraft/core/dist/utils/url'
|
|
34
|
+
import { isDefined } from '@nordcraft/core/dist/utils/util'
|
|
34
35
|
import { handleAction } from '../events/handleAction'
|
|
35
36
|
import type { Signal } from '../signal/signal'
|
|
36
37
|
import type { ComponentContext, ContextApi } from '../types'
|
|
@@ -117,7 +118,10 @@ export function createAPI(
|
|
|
117
118
|
},
|
|
118
119
|
})
|
|
119
120
|
if (typeof location === 'string') {
|
|
120
|
-
const url = validateUrl(
|
|
121
|
+
const url = validateUrl({
|
|
122
|
+
path: location,
|
|
123
|
+
origin: window.location.origin,
|
|
124
|
+
})
|
|
121
125
|
if (url) {
|
|
122
126
|
if (ctx.env.runtime === 'preview') {
|
|
123
127
|
// Attempt to notify the parent about the failed navigation attempt
|
|
@@ -748,71 +752,72 @@ export function createAPI(
|
|
|
748
752
|
}
|
|
749
753
|
})
|
|
750
754
|
payloadSignal.subscribe(async (_) => {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
headers: cacheMatch.response?.headers ?? undefined,
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
requestStart:
|
|
785
|
-
cacheMatch.response?.performance?.requestStart ?? null,
|
|
786
|
-
responseStart:
|
|
787
|
-
cacheMatch.response?.performance?.responseStart ?? null,
|
|
788
|
-
responseEnd:
|
|
789
|
-
cacheMatch.response?.performance?.responseEnd ?? null,
|
|
790
|
-
},
|
|
791
|
-
)
|
|
792
|
-
}
|
|
793
|
-
} else {
|
|
794
|
-
// Execute will set the initial status of the api in the dataSignal
|
|
795
|
-
await execute(api, url, requestSettings)
|
|
796
|
-
}
|
|
755
|
+
const { url, requestSettings } = constructRequest(api)
|
|
756
|
+
// Ensure we only use caching if the page is currently loading
|
|
757
|
+
const cacheMatch =
|
|
758
|
+
// We lookup the API from cache as long as autofetch is defined (and not statically falsy)
|
|
759
|
+
// since the autofetch formula could've evaluated to true during SSR
|
|
760
|
+
isDefined(api.autoFetch) &&
|
|
761
|
+
(api.autoFetch.type !== 'value' || api.autoFetch.value === true) &&
|
|
762
|
+
(window?.__toddle?.isPageLoaded ?? false) === false
|
|
763
|
+
? (ctx.toddle.pageState.Apis?.[
|
|
764
|
+
requestHash(url, requestSettings)
|
|
765
|
+
] as ApiStatus)
|
|
766
|
+
: undefined
|
|
767
|
+
|
|
768
|
+
if (cacheMatch) {
|
|
769
|
+
if (cacheMatch.error) {
|
|
770
|
+
apiError(
|
|
771
|
+
api,
|
|
772
|
+
{
|
|
773
|
+
body: cacheMatch.error,
|
|
774
|
+
status: cacheMatch.response?.status,
|
|
775
|
+
headers: cacheMatch.response?.headers ?? undefined,
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
requestStart:
|
|
779
|
+
cacheMatch.response?.performance?.requestStart ?? null,
|
|
780
|
+
responseStart:
|
|
781
|
+
cacheMatch.response?.performance?.responseStart ?? null,
|
|
782
|
+
responseEnd: cacheMatch.response?.performance?.responseEnd ?? null,
|
|
783
|
+
},
|
|
784
|
+
)
|
|
797
785
|
} else {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
786
|
+
apiSuccess(
|
|
787
|
+
api,
|
|
788
|
+
{
|
|
789
|
+
body: cacheMatch.data,
|
|
790
|
+
status: cacheMatch.response?.status,
|
|
791
|
+
headers: cacheMatch.response?.headers ?? undefined,
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
requestStart:
|
|
795
|
+
cacheMatch.response?.performance?.requestStart ?? null,
|
|
796
|
+
responseStart:
|
|
797
|
+
cacheMatch.response?.performance?.responseStart ?? null,
|
|
798
|
+
responseEnd: cacheMatch.response?.performance?.responseEnd ?? null,
|
|
799
|
+
},
|
|
800
|
+
)
|
|
801
801
|
}
|
|
802
802
|
} else {
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
803
|
+
if (applyFormula(api.autoFetch, getFormulaContext(api))) {
|
|
804
|
+
// Execute will set the initial status of the api in the dataSignal
|
|
805
|
+
await execute(api, url, requestSettings)
|
|
806
|
+
} else {
|
|
807
|
+
ctx.dataSignal.update((data) => {
|
|
808
|
+
return {
|
|
809
|
+
...data,
|
|
810
|
+
Apis: {
|
|
811
|
+
...(data.Apis ?? {}),
|
|
812
|
+
[api.name]: {
|
|
813
|
+
isLoading: false,
|
|
814
|
+
data: null,
|
|
815
|
+
error: null,
|
|
816
|
+
},
|
|
812
817
|
},
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
818
|
+
}
|
|
819
|
+
})
|
|
820
|
+
}
|
|
816
821
|
}
|
|
817
822
|
})
|
|
818
823
|
|