@flyo/nitro-astro 2.0.1 → 2.0.2
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/types/cdn.d.ts +4 -0
- package/dist/types/components/BlockSlot.d.ts +3 -0
- package/dist/types/components/FallbackComponent.d.ts +3 -0
- package/dist/types/components/FlyoNitroBlock.d.ts +3 -0
- package/dist/types/components/FlyoNitroPage.d.ts +3 -0
- package/dist/types/components/MetaInfo.d.ts +3 -0
- package/dist/types/components/MetaInfoEntity.d.ts +3 -0
- package/dist/types/components/MetaInfoPage.d.ts +3 -0
- package/dist/types/index.d.ts +66 -0
- package/dist/types/middleware.d.ts +1 -0
- package/dist/types/sitemap.d.ts +3 -0
- package/dist/types/toolbar.d.ts +2 -0
- package/package.json +8 -14
- package/cdn.ts +0 -48
- package/middleware.ts +0 -45
- package/module.d.ts +0 -4
- package/sitemap.ts +0 -34
- package/toolbar.ts +0 -30
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AstroIntegration, AstroGlobal } from 'astro';
|
|
2
|
+
import { Configuration, ConfigApi, EntitiesApi, PagesApi, SearchApi, SitemapApi, VersionApi, Block, ConfigResponse } from '@flyo/nitro-typescript';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for configuring the integration.
|
|
6
|
+
*/
|
|
7
|
+
export interface IntegrationOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Access token for authentication.
|
|
10
|
+
* This is either the production or development token from the flyo cloud interface. Keep in mind that requests for production accessToken will be effectivly cached from the flyo cdn, but the development accessToken requests will not be cached.
|
|
11
|
+
*/
|
|
12
|
+
accessToken: string;
|
|
13
|
+
/**
|
|
14
|
+
* Enables live editing mode.
|
|
15
|
+
* If enabled, the user can interact with the components, also it represents the application to be in development mode.
|
|
16
|
+
*/
|
|
17
|
+
liveEdit: string | boolean | number;
|
|
18
|
+
/** Directory path for components. */
|
|
19
|
+
componentsDir: string;
|
|
20
|
+
/** Object containing component definitions. */
|
|
21
|
+
components: object;
|
|
22
|
+
/**
|
|
23
|
+
* (Optional) Fallback component name.
|
|
24
|
+
* If provided, this component will be used as a fallback. This fallback component will be used when the requested component is not found and only in live editing mode.
|
|
25
|
+
*/
|
|
26
|
+
fallbackComponent?: string;
|
|
27
|
+
/**
|
|
28
|
+
* TTL (Time-To-Live) for client-side cache headers, in seconds.
|
|
29
|
+
* Default is 900 seconds (15 minutes) its only availble if the liveEdit is disabled. Use 0 to disable client caching.
|
|
30
|
+
*/
|
|
31
|
+
clientCacheHeaderTtl: number;
|
|
32
|
+
/**
|
|
33
|
+
* TTL (Time-To-Live) for server-side cache headers, in seconds.
|
|
34
|
+
* Default is 1200 seconds (20 minutes) its only availble if the liveEdit is disabled. Use 0 to disable server caching.
|
|
35
|
+
*/
|
|
36
|
+
serverCacheHeaderTtl: number;
|
|
37
|
+
}
|
|
38
|
+
export interface FlyoIntegration {
|
|
39
|
+
config: Configuration;
|
|
40
|
+
options: {
|
|
41
|
+
liveEdit: boolean;
|
|
42
|
+
componentsDir: string;
|
|
43
|
+
clientCacheHeaderTtl: number;
|
|
44
|
+
serverCacheHeaderTtl: number;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export declare function useFlyoIntegration(): FlyoIntegration;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the API main configuration which is used by the SDK.
|
|
50
|
+
* It holds the access key and is globally available.
|
|
51
|
+
*/
|
|
52
|
+
export declare function useConfiguration(): Configuration;
|
|
53
|
+
/**
|
|
54
|
+
* Resolves (if not done) and returns the main configuration object of
|
|
55
|
+
* the SDK, which is done in the middleware.ts and using the useConfigApi()
|
|
56
|
+
* function.
|
|
57
|
+
*/
|
|
58
|
+
export declare function useConfig(astro: AstroGlobal): Promise<ConfigResponse>;
|
|
59
|
+
export declare function useConfigApi(): ConfigApi;
|
|
60
|
+
export declare function useEntitiesApi(): EntitiesApi;
|
|
61
|
+
export declare function usePagesApi(): PagesApi;
|
|
62
|
+
export declare function useSearchApi(): SearchApi;
|
|
63
|
+
export declare function useSitemapApi(): SitemapApi;
|
|
64
|
+
export declare function useVersionApi(): VersionApi;
|
|
65
|
+
export declare function editableBlock(block: Block): object;
|
|
66
|
+
export default function flyoNitroIntegration(options: IntegrationOptions): AstroIntegration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const onRequest: import('astro').MiddlewareHandler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flyo/nitro-astro",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Nitro Astro connecting Flyo Headless to Astro",
|
|
5
5
|
"main": "./dist/nitro-astro.js",
|
|
6
6
|
"module": "./dist/nitro-astro.mjs",
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
"@flyo/nitro-typescript": "^1.0.9"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"astro": "^4.
|
|
16
|
-
"typescript": "5.
|
|
17
|
-
"@types/node": "20.
|
|
18
|
-
"vite": "^5.
|
|
15
|
+
"astro": "^4.11.4",
|
|
16
|
+
"typescript": "5.5.3",
|
|
17
|
+
"@types/node": "20.14.9",
|
|
18
|
+
"vite": "^5.3.3",
|
|
19
19
|
"vite-plugin-dts": "^3.9.1"
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
-
"types": "./dist/index.d.ts",
|
|
23
|
+
"types": "./dist/types/index.d.ts",
|
|
24
24
|
"import": "./dist/nitro-astro.mjs",
|
|
25
25
|
"require": "./dist/nitro-astro.js"
|
|
26
26
|
},
|
|
@@ -64,17 +64,11 @@
|
|
|
64
64
|
"./sitemap.ts": "./sitemap.ts",
|
|
65
65
|
"./toolbar.ts": "./toolbar.ts"
|
|
66
66
|
},
|
|
67
|
-
"type": "module",
|
|
68
67
|
"files": [
|
|
69
|
-
"module.d.ts",
|
|
70
68
|
"dist",
|
|
71
|
-
"components"
|
|
72
|
-
"cdn.ts",
|
|
73
|
-
"middleware.ts",
|
|
74
|
-
"sitemap.ts",
|
|
75
|
-
"toolbar.ts"
|
|
69
|
+
"components"
|
|
76
70
|
],
|
|
77
|
-
"types": "./dist/index.d.ts",
|
|
71
|
+
"types": "./dist/types/index.d.ts",
|
|
78
72
|
"author": "Basil Suter <git@nadar.io>",
|
|
79
73
|
"license": "MIT",
|
|
80
74
|
"release": {
|
package/cdn.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create an astro ExternalImageService for flyo where the base url with transormations looks like https://storage.flyo.cloud/image_7a158241.jpg/thumb/250x250?format=webp
|
|
3
|
-
*/
|
|
4
|
-
import type { ExternalImageService, ImageTransform } from "astro";
|
|
5
|
-
|
|
6
|
-
const service: ExternalImageService = {
|
|
7
|
-
getURL(options: ImageTransform) {
|
|
8
|
-
// check if the options.src contains already https://storage.flyo.cloud
|
|
9
|
-
// if not we add it to the url
|
|
10
|
-
|
|
11
|
-
let url =
|
|
12
|
-
typeof options.src === "string" &&
|
|
13
|
-
options.src.includes("https://storage.flyo.cloud")
|
|
14
|
-
? options.src
|
|
15
|
-
: `https://storage.flyo.cloud/${options.src}`;
|
|
16
|
-
|
|
17
|
-
// if either width or height are defined we add the /thumb/$widthx$height path to it.
|
|
18
|
-
let width: string | number | null = options.width ? options.width : null;
|
|
19
|
-
let height: string | number | null = options.height ? options.height : null;
|
|
20
|
-
|
|
21
|
-
if (width || height) {
|
|
22
|
-
if (width === null) {
|
|
23
|
-
width = "null";
|
|
24
|
-
}
|
|
25
|
-
if (height === null) {
|
|
26
|
-
height = "null";
|
|
27
|
-
}
|
|
28
|
-
url += `/thumb/${width}x${height}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const format = options.format ? options.format : "webp";
|
|
32
|
-
|
|
33
|
-
return `${url}?format=${format}`;
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
getHTMLAttributes(options) {
|
|
37
|
-
const { ...attributes } = options;
|
|
38
|
-
return {
|
|
39
|
-
...attributes,
|
|
40
|
-
width: options.width ?? null, // width and height are required to prevent CLS and enable lazy loading for chrome.
|
|
41
|
-
height: options.height ?? null, // width and height are required to prevent CLS and enable lazy loading for chrome.
|
|
42
|
-
loading: options.loading ?? "lazy",
|
|
43
|
-
decoding: options.decoding ?? "async",
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export default service;
|
package/middleware.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { defineMiddleware } from "astro:middleware";
|
|
2
|
-
import { useConfigApi, useFlyoIntegration } from "./index.ts";
|
|
3
|
-
|
|
4
|
-
let resolvedValue;
|
|
5
|
-
|
|
6
|
-
async function getConfigPromise(context) {
|
|
7
|
-
if (resolvedValue) {
|
|
8
|
-
// If the value is already resolved, return a resolved promise with the value
|
|
9
|
-
return resolvedValue;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Fetch the config and store the resolved value
|
|
13
|
-
const value = await useConfigApi().config({
|
|
14
|
-
lang: context.currentLocale,
|
|
15
|
-
});
|
|
16
|
-
resolvedValue = value;
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const onRequest = defineMiddleware(async (context, next) => {
|
|
21
|
-
context.locals.config = getConfigPromise(context);
|
|
22
|
-
|
|
23
|
-
const liveEditEnabled = useFlyoIntegration().options.liveEdit;
|
|
24
|
-
|
|
25
|
-
if (!liveEditEnabled) {
|
|
26
|
-
const response = await next();
|
|
27
|
-
|
|
28
|
-
response.headers.set(
|
|
29
|
-
"Vercel-CDN-Cache-Control",
|
|
30
|
-
`max-age=${useFlyoIntegration().options.serverCacheHeaderTtl}`
|
|
31
|
-
);
|
|
32
|
-
response.headers.set(
|
|
33
|
-
"CDN-Cache-Control",
|
|
34
|
-
`max-age=${useFlyoIntegration().options.serverCacheHeaderTtl}`
|
|
35
|
-
);
|
|
36
|
-
response.headers.set(
|
|
37
|
-
"Cache-Control",
|
|
38
|
-
`max-age=${useFlyoIntegration().options.clientCacheHeaderTtl}`
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return response;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return next();
|
|
45
|
-
});
|
package/module.d.ts
DELETED
package/sitemap.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useSitemapApi } from "./index.ts";
|
|
2
|
-
import type { AstroGlobal } from "astro";
|
|
3
|
-
|
|
4
|
-
function buildUrl(path: string, domain: string) {
|
|
5
|
-
return `${domain.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export async function GET(config: AstroGlobal) {
|
|
9
|
-
const sitemap = await useSitemapApi().sitemap();
|
|
10
|
-
|
|
11
|
-
let xml = '<?xml version="1.0" encoding="UTF-8"?>';
|
|
12
|
-
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
|
13
|
-
|
|
14
|
-
const routes = [];
|
|
15
|
-
for (const item of sitemap) {
|
|
16
|
-
if (item.entity_type === "nitro-page") {
|
|
17
|
-
if (routes.includes(item.entity_slug)) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
routes.push(item.entity_slug);
|
|
21
|
-
xml += `<url><loc>${buildUrl(item.entity_slug, config.site.origin)}</loc></url>`;
|
|
22
|
-
} else if (item.routes?.detail) {
|
|
23
|
-
xml += `<url><loc>${buildUrl(item.routes["detail"], config.site.origin)}</loc></url>`;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
xml += "</urlset>";
|
|
28
|
-
|
|
29
|
-
return new Response(xml, {
|
|
30
|
-
headers: {
|
|
31
|
-
"Content-Type": "application/xml",
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}
|
package/toolbar.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { defineToolbarApp } from "astro/toolbar";
|
|
2
|
-
|
|
3
|
-
export default defineToolbarApp({
|
|
4
|
-
init(canvas) {
|
|
5
|
-
const windowElement = document.createElement("astro-dev-toolbar-window");
|
|
6
|
-
|
|
7
|
-
const links = [
|
|
8
|
-
{ link: "https://flyo.cloud", text: "Flyo Cloud Login" },
|
|
9
|
-
{
|
|
10
|
-
link: "https://dev.flyo.cloud/nitro/",
|
|
11
|
-
text: "Flyo Nitro Developer Portal",
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
link: "https://nitro-openapi.flyo.cloud/",
|
|
15
|
-
text: "Flyo Nitro API Documentation",
|
|
16
|
-
},
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
const content = links
|
|
20
|
-
.map(
|
|
21
|
-
(link) =>
|
|
22
|
-
`<astro-dev-toolbar-card link="${link.link}" style="margin-bottom:8px;">
|
|
23
|
-
${link.text}
|
|
24
|
-
</astro-dev-toolbar-card>`
|
|
25
|
-
)
|
|
26
|
-
.join("");
|
|
27
|
-
windowElement.innerHTML = content;
|
|
28
|
-
canvas.appendChild(windowElement);
|
|
29
|
-
},
|
|
30
|
-
});
|