@flyo/nitro-astro 1.4.3 → 1.5.0
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/README.md +20 -4
- package/cdn.ts +3 -1
- package/dist/cdn.d.ts +2 -4
- package/dist/components/BlockSlot.d.ts +2 -1
- package/dist/components/FallbackComponent.d.ts +2 -1
- package/dist/components/FlyoNitroBlock.d.ts +2 -1
- package/dist/components/FlyoNitroPage.d.ts +2 -1
- package/dist/components/MetaInfo.d.ts +2 -1
- package/dist/components/MetaInfoEntity.d.ts +2 -1
- package/dist/components/MetaInfoPage.d.ts +2 -1
- package/dist/index.d.ts +3 -2
- package/dist/nitro-astro.js +7 -4
- package/dist/nitro-astro.mjs +457 -437
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -50,14 +50,24 @@ Add a `[...slug].astro` file in the pages directory with the following example c
|
|
|
50
50
|
```astro
|
|
51
51
|
---
|
|
52
52
|
import Layout from '../layouts/Layout.astro';
|
|
53
|
-
import { usePagesApi } from '@flyo/nitro-astro';
|
|
53
|
+
import { usePagesApi, useConfig } from '@flyo/nitro-astro';
|
|
54
54
|
import FlyoNitroPage from '@flyo/nitro-astro/FlyoNitroPage.astro'
|
|
55
55
|
import MetaInfoPage from '@flyo/nitro-astro/MetaInfoPage.astro';
|
|
56
56
|
|
|
57
57
|
const { slug } = Astro.params;
|
|
58
|
+
const resolveSlug = slug === undefined ? '' : slug
|
|
59
|
+
const config = await useConfig()
|
|
58
60
|
let page;
|
|
61
|
+
|
|
59
62
|
try {
|
|
60
|
-
|
|
63
|
+
if (!config.pages.includes(resolveSlug)) {
|
|
64
|
+
return new Response('Not Found', {
|
|
65
|
+
status: 404,
|
|
66
|
+
statusText: 'Page Not Found'
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
page = await usePagesApi().page({slug: resolveSlug})
|
|
61
71
|
} catch (e) {
|
|
62
72
|
return new Response(e.body.name, {
|
|
63
73
|
status: 404,
|
|
@@ -75,9 +85,9 @@ To receive the config in the layout in `src/layouts/Layout.astro`:
|
|
|
75
85
|
|
|
76
86
|
```astro
|
|
77
87
|
---
|
|
78
|
-
import {
|
|
88
|
+
import { useConfig } from "@flyo/nitro-astro";
|
|
79
89
|
|
|
80
|
-
const config = await
|
|
90
|
+
const config = await useConfig();
|
|
81
91
|
const { title } = Astro.props;
|
|
82
92
|
const currentPath = Astro.url.pathname;
|
|
83
93
|
---
|
|
@@ -165,3 +175,9 @@ const isProd = import.meta.env.PROD;
|
|
|
165
175
|
</Layout>
|
|
166
176
|
{ isProd && <script is:inline define:vars={{ api: response.entity.entity_metric.api }}>fetch(api)</script> }
|
|
167
177
|
```
|
|
178
|
+
|
|
179
|
+
# Nitro Astro Integration Local Development
|
|
180
|
+
|
|
181
|
+
1. for yarn go into the example app and replace the dependecie with: `"@flyo/nitro-astro": "file:../nitro-astro"`
|
|
182
|
+
2. always run the `yarn build` command in the nitro-astro package after making changes
|
|
183
|
+
2. don't forget to run `rm -rf node_modules/ && yarn && yarn dev` in the example app whenever you like to test changes.
|
package/cdn.ts
CHANGED
|
@@ -7,7 +7,9 @@ const service: ExternalImageService = {
|
|
|
7
7
|
getURL(options: ImageTransform) {
|
|
8
8
|
|
|
9
9
|
// check if the options.src contains already https://storage.flyo.cloud
|
|
10
|
-
|
|
10
|
+
// if not we add it to the url
|
|
11
|
+
|
|
12
|
+
let url = typeof options.src === 'string' && options.src.includes('https://storage.flyo.cloud') ? options.src : `https://storage.flyo.cloud/${options.src}`
|
|
11
13
|
|
|
12
14
|
// if either width or height are defined we add the /thumb/$widthx$height path to it.
|
|
13
15
|
let width: string | number | null = options.width ? options.width : null;
|
package/dist/cdn.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import type { ExternalImageService } from "astro";
|
|
1
|
+
import { ExternalImageService } from 'astro';
|
|
2
|
+
|
|
5
3
|
declare const service: ExternalImageService;
|
|
6
4
|
export default service;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { AstroIntegration } from "astro";
|
|
2
1
|
import { Configuration, ConfigApi, EntitiesApi, PagesApi, SearchApi, SitemapApi, VersionApi, Block, ConfigResponse } from '@flyo/nitro-typescript';
|
|
2
|
+
import { AstroIntegration } from 'astro';
|
|
3
|
+
|
|
3
4
|
export type IntegrationOptions = {
|
|
4
5
|
accessToken: string;
|
|
5
6
|
liveEdit: any;
|
|
@@ -9,7 +10,7 @@ export type IntegrationOptions = {
|
|
|
9
10
|
};
|
|
10
11
|
export declare function useConfiguration(): Configuration;
|
|
11
12
|
export declare function useConfigApi(): ConfigApi;
|
|
12
|
-
export declare function useConfig(): Promise<
|
|
13
|
+
export declare function useConfig(lang?: string | null): Promise<ConfigResponse>;
|
|
13
14
|
export declare function useEntitiesApi(): EntitiesApi;
|
|
14
15
|
export declare function usePagesApi(): PagesApi;
|
|
15
16
|
export declare function useSearchApi(): SearchApi;
|
package/dist/nitro-astro.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
(function(f,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(f=typeof globalThis<"u"?globalThis:f||self,g(f.flyoNitroIntegration={}))})(this,function(f){"use strict";const g="https://api.flyo.cloud/nitro/v1".replace(/\/+$/,"");class K{constructor(t={}){this.configuration=t}set config(t){this.configuration=t}get basePath(){return this.configuration.basePath!=null?this.configuration.basePath:g}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||E}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){const t=this.configuration.apiKey;if(t)return typeof t=="function"?t:()=>t}get accessToken(){const t=this.configuration.accessToken;if(t)return typeof t=="function"?t:async()=>t}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}}const N=new K,q=class x{constructor(t=N){this.configuration=t,this.fetchApi=async(i,o)=>{let a={url:i,init:o};for(const s of this.middleware)s.pre&&(a=await s.pre({fetch:this.fetchApi,...a})||a);let r;try{r=await(this.configuration.fetchApi||fetch)(a.url,a.init)}catch(s){for(const u of this.middleware)u.onError&&(r=await u.onError({fetch:this.fetchApi,url:a.url,init:a.init,error:s,response:r?r.clone():void 0})||r);if(r===void 0)throw s instanceof Error?new F(s,"The request failed and the interceptors did not return an alternative response"):s}for(const s of this.middleware)s.post&&(r=await s.post({fetch:this.fetchApi,url:a.url,init:a.init,response:r.clone()})||r);return r},this.middleware=t.middleware}withMiddleware(...t){const i=this.clone();return i.middleware=i.middleware.concat(...t),i}withPreMiddleware(...t){const i=t.map(o=>({pre:o}));return this.withMiddleware(...i)}withPostMiddleware(...t){const i=t.map(o=>({post:o}));return this.withMiddleware(...i)}isJsonMime(t){return t?x.jsonRegex.test(t):!1}async request(t,i){const{url:o,init:a}=await this.createFetchParams(t,i),r=await this.fetchApi(o,a);if(r&&r.status>=200&&r.status<300)return r;throw new B(r,"Response returned an error code")}async createFetchParams(t,i){let o=this.configuration.basePath+t.path;t.query!==void 0&&Object.keys(t.query).length!==0&&(o+="?"+this.configuration.queryParamsStringify(t.query));const a=Object.assign({},this.configuration.headers,t.headers);Object.keys(a).forEach(v=>a[v]===void 0?delete a[v]:{});const r=typeof i=="function"?i:async()=>i,s={method:t.method,headers:a,body:t.body,credentials:this.configuration.credentials},u={...s,...await r({init:s,context:t})};let c;$(u.body)||u.body instanceof URLSearchParams||O(u.body)?c=u.body:this.isJsonMime(a["Content-Type"])?c=JSON.stringify(u.body):c=u.body;const d={...u,body:c};return{url:o,init:d}}clone(){const t=this.constructor,i=new t(this.configuration);return i.middleware=this.middleware.slice(),i}};q.jsonRegex=new RegExp("^(:?application/json|[^;/ ]+/[^;/ ]+[+]json)[ ]*(:?;.*)?$","i");let h=q;function O(e){return typeof Blob<"u"&&e instanceof Blob}function $(e){return typeof FormData<"u"&&e instanceof FormData}class B extends Error{constructor(t,i){super(i),this.response=t,this.name="ResponseError"}}class F extends Error{constructor(t,i){super(i),this.cause=t,this.name="FetchError"}}class m extends Error{constructor(t,i){super(i),this.field=t,this.name="RequiredError"}}function n(e,t){return e[t]!=null}function E(e,t=""){return Object.keys(e).map(i=>R(i,e[i],t)).filter(i=>i.length>0).join("&")}function R(e,t,i=""){const o=i+(i.length?`[${e}]`:e);if(t instanceof Array){const a=t.map(r=>encodeURIComponent(String(r))).join(`&${encodeURIComponent(o)}=`);return`${encodeURIComponent(o)}=${a}`}if(t instanceof Set){const a=Array.from(t);return R(e,a,i)}return t instanceof Date?`${encodeURIComponent(o)}=${encodeURIComponent(t.toISOString())}`:t instanceof Object?E(t,o):`${encodeURIComponent(o)}=${encodeURIComponent(String(t))}`}function w(e,t){return Object.keys(e).reduce((i,o)=>({...i,[o]:t(e[o])}),{})}class p{constructor(t,i=o=>o){this.raw=t,this.transformer=i}async value(){return this.transformer(await this.raw.json())}}function M(e){return D(e)}function D(e,t){return e==null?e:{identifier:n(e,"identifier")?e.identifier:void 0,content:n(e,"content")?e.content.map(C):void 0}}function C(e){return G(e)}function G(e,t){return e==null?e:{items:n(e,"items")?e.items:void 0,content:n(e,"content")?e.content:void 0,config:n(e,"config")?e.config:void 0,identifier:n(e,"identifier")?e.identifier:void 0,uid:n(e,"uid")?e.uid:void 0,component:n(e,"component")?e.component:void 0,slots:n(e,"slots")?w(e.slots,M):void 0}}function A(e){return J(e)}function J(e,t){return e==null?e:{type:n(e,"type")?e.type:void 0,target:n(e,"target")?e.target:void 0,label:n(e,"label")?e.label:void 0,href:n(e,"href")?e.href:void 0,slug:n(e,"slug")?e.slug:void 0,properties:n(e,"properties")?e.properties:void 0,children:n(e,"children")?e.children.map(A):void 0}}function V(e){return W(e)}function W(e,t){return e==null?e:{items:n(e,"items")?e.items.map(A):void 0,uid:n(e,"uid")?e.uid:void 0,identifier:n(e,"identifier")?e.identifier:void 0,label:n(e,"label")?e.label:void 0}}function z(e){return Q(e)}function Q(e,t){return e==null?e:{domain:n(e,"domain")?e.domain:void 0,slug:n(e,"slug")?e.slug:void 0,version:n(e,"version")?e.version:void 0,updated_at:n(e,"updated_at")?e.updated_at:void 0,language:n(e,"language")?e.language:void 0}}function H(e){return X(e)}function X(e,t){return e==null?e:{nitro:n(e,"nitro")?z(e.nitro):void 0,pages:n(e,"pages")?e.pages:void 0,containers:n(e,"containers")?w(e.containers,V):void 0,globals:n(e,"globals")?e.globals:void 0}}function Z(e){return Y(e)}function Y(e,t){return e==null?e:{api:n(e,"api")?e.api:void 0,image:n(e,"image")?e.image:void 0}}function ee(e){return te(e)}function te(e,t){return e==null?e:{_version:n(e,"_version")?e._version:void 0,entity_metric:n(e,"entity_metric")?Z(e.entity_metric):void 0,entity_unique_id:n(e,"entity_unique_id")?e.entity_unique_id:void 0,entity_id:n(e,"entity_id")?e.entity_id:void 0,entity_image:n(e,"entity_image")?e.entity_image:void 0,entity_slug:n(e,"entity_slug")?e.entity_slug:void 0,entity_teaser:n(e,"entity_teaser")?e.entity_teaser:void 0,entity_time_end:n(e,"entity_time_end")?e.entity_time_end:void 0,entity_time_start:n(e,"entity_time_start")?e.entity_time_start:void 0,entity_title:n(e,"entity_title")?e.entity_title:void 0,entity_type:n(e,"entity_type")?e.entity_type:void 0,entity_type_id:n(e,"entity_type_id")?e.entity_type_id:void 0,updated_at:n(e,"updated_at")?e.updated_at:void 0,routes:n(e,"routes")?e.routes:void 0}}function k(e){return ie(e)}function ie(e,t){return e==null?e:{entity:n(e,"entity")?ee(e.entity):void 0,model:n(e,"model")?e.model:void 0,language:n(e,"language")?e.language:void 0,jsonld:n(e,"jsonld")?e.jsonld:void 0}}function I(e){return ne(e)}function ne(e,t){return e==null?e:{entity_unique_id:n(e,"entity_unique_id")?e.entity_unique_id:void 0,entity_title:n(e,"entity_title")?e.entity_title:void 0,entity_teaser:n(e,"entity_teaser")?e.entity_teaser:void 0,entity_slug:n(e,"entity_slug")?e.entity_slug:void 0,entity_time_start:n(e,"entity_time_start")?e.entity_time_start:void 0,entity_type:n(e,"entity_type")?e.entity_type:void 0,entity_type_id:n(e,"entity_type_id")?e.entity_type_id:void 0,entity_image:n(e,"entity_image")?e.entity_image:void 0,routes:n(e,"routes")?e.routes:void 0}}function oe(e){return re(e)}function re(e,t){return e==null?e:{description:n(e,"description")?e.description:void 0,image:n(e,"image")?e.image:void 0,title:n(e,"title")?e.title:void 0}}function ae(e){return se(e)}function se(e,t){return e==null?e:{slug:n(e,"slug")?e.slug:void 0,title:n(e,"title")?e.title:void 0}}function ue(e){return ce(e)}function ce(e,t){return e==null?e:{value:n(e,"value")?e.value:void 0,navigation:n(e,"navigation")?e.navigation:void 0,propagate:n(e,"propagate")?e.propagate:void 0}}function S(e){return le(e)}function le(e,t){return e==null?e:{id:n(e,"id")?e.id:void 0,title:n(e,"title")?e.title:void 0,href:n(e,"href")?e.href:void 0,slug:n(e,"slug")?e.slug:void 0,json:n(e,"json")?e.json.map(C):void 0,depth:n(e,"depth")?e.depth:void 0,is_home:n(e,"is_home")?e.is_home:void 0,created_at:n(e,"created_at")?e.created_at:void 0,updated_at:n(e,"updated_at")?e.updated_at:void 0,is_visible:n(e,"is_visible")?e.is_visible:void 0,meta_json:n(e,"meta_json")?oe(e.meta_json):void 0,properties:n(e,"properties")?w(e.properties,ue):void 0,uid:n(e,"uid")?e.uid:void 0,type:n(e,"type")?e.type:void 0,target:n(e,"target")?e.target:void 0,container:n(e,"container")?e.container:void 0,breadcrumb:n(e,"breadcrumb")?e.breadcrumb.map(ae):void 0}}function de(e){return fe(e)}function fe(e,t){return e==null?e:{version:n(e,"version")?e.version:void 0,updated_at:n(e,"updated_at")?e.updated_at:void 0}}class pe extends h{async configRaw(t){const i={},o={};this.configuration&&this.configuration.apiKey&&(i.token=this.configuration.apiKey("token"));const a=await this.request({path:"/config",method:"GET",headers:o,query:i},t);return new p(a,r=>H(r))}async config(t){return await(await this.configRaw(t)).value()}}class ye extends h{async entityBySlugRaw(t,i){if(t.slug===null||t.slug===void 0)throw new m("slug","Required parameter requestParameters.slug was null or undefined when calling entityBySlug.");const o={};t.typeId!==void 0&&(o.typeId=t.typeId);const a={};this.configuration&&this.configuration.apiKey&&(o.token=this.configuration.apiKey("token"));const r=await this.request({path:"/entities/slug/{slug}".replace("{slug}",encodeURIComponent(String(t.slug))),method:"GET",headers:a,query:o},i);return new p(r,s=>k(s))}async entityBySlug(t,i){return await(await this.entityBySlugRaw(t,i)).value()}async entityByUniqueidRaw(t,i){if(t.uniqueid===null||t.uniqueid===void 0)throw new m("uniqueid","Required parameter requestParameters.uniqueid was null or undefined when calling entityByUniqueid.");const o={},a={};this.configuration&&this.configuration.apiKey&&(o.token=this.configuration.apiKey("token"));const r=await this.request({path:"/entities/uniqueid/{uniqueid}".replace("{uniqueid}",encodeURIComponent(String(t.uniqueid))),method:"GET",headers:a,query:o},i);return new p(r,s=>k(s))}async entityByUniqueid(t,i){return await(await this.entityByUniqueidRaw(t,i)).value()}}class he extends h{async homeRaw(t){const i={},o={};this.configuration&&this.configuration.apiKey&&(i.token=this.configuration.apiKey("token"));const a=await this.request({path:"/pages/home",method:"GET",headers:o,query:i},t);return new p(a,r=>S(r))}async home(t){return await(await this.homeRaw(t)).value()}async pageRaw(t,i){const o={};t.slug!==void 0&&(o.slug=t.slug);const a={};this.configuration&&this.configuration.apiKey&&(o.token=this.configuration.apiKey("token"));const r=await this.request({path:"/pages",method:"GET",headers:a,query:o},i);return new p(r,s=>S(s))}async page(t={},i){return await(await this.pageRaw(t,i)).value()}}class ge extends h{async searchRaw(t,i){if(t.query===null||t.query===void 0)throw new m("query","Required parameter requestParameters.query was null or undefined when calling search.");const o={};t.query!==void 0&&(o.query=t.query);const a={};this.configuration&&this.configuration.apiKey&&(o.token=this.configuration.apiKey("token"));const r=await this.request({path:"/search",method:"GET",headers:a,query:o},i);return new p(r,s=>s.map(I))}async search(t,i){return await(await this.searchRaw(t,i)).value()}}class ve extends h{async sitemapRaw(t){const i={},o={};this.configuration&&this.configuration.apiKey&&(i.token=this.configuration.apiKey("token"));const a=await this.request({path:"/sitemap",method:"GET",headers:o,query:i},t);return new p(a,r=>r.map(I))}async sitemap(t){return await(await this.sitemapRaw(t)).value()}}class me extends h{async versionRaw(t){const i={},o={};this.configuration&&this.configuration.apiKey&&(i.token=this.configuration.apiKey("token"));const a=await this.request({path:"/version",method:"GET",headers:o,query:i},t);return new p(a,r=>de(r))}async version(t){return await(await this.versionRaw(t)).value()}}const we=/[\p{Lu}]/u,_e=/[\p{Ll}]/u,T=/^[\p{Lu}](?![\p{Lu}])/gu,j=/([\p{Alpha}\p{N}_]|$)/u,_=/[_.\- ]+/,be=new RegExp("^"+_.source),P=new RegExp(_.source+j.source,"gu"),U=new RegExp("\\d+"+j.source,"gu"),qe=(e,t,i,o)=>{let a=!1,r=!1,s=!1,u=!1;for(let c=0;c<e.length;c++){const d=e[c];u=c>2?e[c-3]==="-":!0,a&&we.test(d)?(e=e.slice(0,c)+"-"+e.slice(c),a=!1,s=r,r=!0,c++):r&&s&&_e.test(d)&&(!u||o)?(e=e.slice(0,c-1)+"-"+e.slice(c-1),s=r,r=!1,a=!0):(a=t(d)===d&&i(d)!==d,s=r,r=i(d)===d&&t(d)!==d)}return e},Ee=(e,t)=>(T.lastIndex=0,e.replace(T,i=>t(i))),Re=(e,t)=>(P.lastIndex=0,U.lastIndex=0,e.replace(P,(i,o)=>t(o)).replace(U,i=>t(i)));function Ce(e,t){if(!(typeof e=="string"||Array.isArray(e)))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},Array.isArray(e)?e=e.map(r=>r.trim()).filter(r=>r.length).join("-"):e=e.trim(),e.length===0)return"";const i=t.locale===!1?r=>r.toLowerCase():r=>r.toLocaleLowerCase(t.locale),o=t.locale===!1?r=>r.toUpperCase():r=>r.toLocaleUpperCase(t.locale);return e.length===1?_.test(e)?"":t.pascalCase?o(e):i(e):(e!==i(e)&&(e=qe(e,i,o,t.preserveConsecutiveUppercase)),e=e.replace(be,""),e=t.preserveConsecutiveUppercase?Ee(e,i):i(e),t.pascalCase&&(e=o(e.charAt(0))+e.slice(1)),Re(e,o))}function Ae(e,t,i){const o="virtual:flyo-components",a="\0"+o;return{name:"vite-plugin-flyo-components",async resolveId(r){if(r===o)return a},async load(r){if(r===a){const s=[];for(const[c,d]of Object.entries(t)){const v=await this.resolve("/"+e+"/"+d+".astro");v&&s.push(`export { default as ${Ce(c)} } from "${v.id}"`)}let u=null;return i&&(u=await this.resolve("/"+e+"/"+i+".astro")),u?s.push(`export { default as fallback } from "${u.id}"`):s.push('export { default as fallback } from "@flyo/nitro-astro/FallbackComponent.astro"'),s.join(";")}}}}let ke=Symbol("clean"),l=[],Ie=(e,t)=>{let i=[],o={get(){return o.lc||o.listen(()=>{})(),o.value},l:t||0,lc:0,listen(a,r){return o.lc=i.push(a,r||o.l)/2,()=>{let s=i.indexOf(a);~s&&(i.splice(s,2),--o.lc||o.off())}},notify(a,r){let s=!l.length;for(let u=0;u<i.length;u+=2)l.push(i[u],i[u+1],o.value,a,r);if(s){for(let u=0;u<l.length;u+=5){let c;for(let d=u+1;!c&&(d+=5)<l.length;)l[d]<l[u+1]&&(c=l.push(l[u],l[u+1],l[u+2],l[u+3],l[u+4]));c||l[u](l[u+2],l[u+3],l[u+4])}l.length=0}},off(){},set(a){let r=o.value;r!==a&&(o.value=a,o.notify(r))},subscribe(a,r){let s=o.listen(a,r);return a(o.value),s},value:e};return process.env.NODE_ENV!=="production"&&(o[ke]=()=>{i=[],o.lc=0,o.off()}),o};function y(){return globalThis.flyoNitroInstance||console.error("The Flyo Typescript Configuration has not been initialized correctly"),globalThis.flyoNitroInstance}function L(){return new pe(y())}const b=Ie(!1);async function Se(){return b.get()||b.set(await L().config()),b.get()}function Te(){return new ye(y())}function je(){return new he(y())}function Pe(){return new ge(y())}function Ue(){return new ve(y())}function Le(){return new me(y())}function xe(e){return{"data-flyo-block-uid":e.uid}}function Ke(e){const t={accessToken:!1,liveEdit:!1,fallbackComponent:null,componentsDir:"src/components/flyo",...e};return t.liveEdit==="true"?t.liveEdit=!0:t.liveEdit==="false"&&(t.liveEdit=!1),{name:"@flyo/nitro-astro",hooks:{"astro:config:setup":({injectScript:i,updateConfig:o,injectRoute:a})=>{a({pattern:"sitemap.xml",entrypoint:"@flyo/nitro-astro/sitemap.ts"}),o({image:{service:{entrypoint:"@flyo/nitro-astro/cdn.ts"}},vite:{plugins:[Ae(e.componentsDir,e.components,e.fallbackComponent)]}}),i("page-ssr",`
|
|
1
|
+
(function(d,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(d=typeof globalThis<"u"?globalThis:d||self,y(d.flyoNitroIntegration={}))})(this,function(d){"use strict";const y="https://api.flyo.cloud/nitro/v1".replace(/\/+$/,"");class N{constructor(n={}){this.configuration=n}set config(n){this.configuration=n}get basePath(){return this.configuration.basePath!=null?this.configuration.basePath:y}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||E}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){const n=this.configuration.apiKey;if(n)return typeof n=="function"?n:()=>n}get accessToken(){const n=this.configuration.accessToken;if(n)return typeof n=="function"?n:async()=>n}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}}const x=new N,b=class L{constructor(n=x){this.configuration=n,this.fetchApi=async(t,i)=>{let r={url:t,init:i};for(const a of this.middleware)a.pre&&(r=await a.pre({fetch:this.fetchApi,...r})||r);let o;try{o=await(this.configuration.fetchApi||fetch)(r.url,r.init)}catch(a){for(const l of this.middleware)l.onError&&(o=await l.onError({fetch:this.fetchApi,url:r.url,init:r.init,error:a,response:o?o.clone():void 0})||o);if(o===void 0)throw a instanceof Error?new $(a,"The request failed and the interceptors did not return an alternative response"):a}for(const a of this.middleware)a.post&&(o=await a.post({fetch:this.fetchApi,url:r.url,init:r.init,response:o.clone()})||o);return o},this.middleware=n.middleware}withMiddleware(...n){const t=this.clone();return t.middleware=t.middleware.concat(...n),t}withPreMiddleware(...n){const t=n.map(i=>({pre:i}));return this.withMiddleware(...t)}withPostMiddleware(...n){const t=n.map(i=>({post:i}));return this.withMiddleware(...t)}isJsonMime(n){return n?L.jsonRegex.test(n):!1}async request(n,t){const{url:i,init:r}=await this.createFetchParams(n,t),o=await this.fetchApi(i,r);if(o&&o.status>=200&&o.status<300)return o;throw new B(o,"Response returned an error code")}async createFetchParams(n,t){let i=this.configuration.basePath+n.path;n.query!==void 0&&Object.keys(n.query).length!==0&&(i+="?"+this.configuration.queryParamsStringify(n.query));const r=Object.assign({},this.configuration.headers,n.headers);Object.keys(r).forEach(h=>r[h]===void 0?delete r[h]:{});const o=typeof t=="function"?t:async()=>t,a={method:n.method,headers:r,body:n.body,credentials:this.configuration.credentials},l={...a,...await o({init:a,context:n})};let s;O(l.body)||l.body instanceof URLSearchParams||K(l.body)?s=l.body:this.isJsonMime(r["Content-Type"])?s=JSON.stringify(l.body):s=l.body;const c={...l,body:s};return{url:i,init:c}}clone(){const n=this.constructor,t=new n(this.configuration);return t.middleware=this.middleware.slice(),t}};b.jsonRegex=new RegExp("^(:?application/json|[^;/ ]+/[^;/ ]+[+]json)[ ]*(:?;.*)?$","i");let g=b;function K(e){return typeof Blob<"u"&&e instanceof Blob}function O(e){return typeof FormData<"u"&&e instanceof FormData}class B extends Error{constructor(n,t){super(t),this.response=n,this.name="ResponseError"}}class $ extends Error{constructor(n,t){super(t),this.cause=n,this.name="FetchError"}}class v extends Error{constructor(n,t){super(t),this.field=n,this.name="RequiredError"}}function E(e,n=""){return Object.keys(e).map(t=>q(t,e[t],n)).filter(t=>t.length>0).join("&")}function q(e,n,t=""){const i=t+(t.length?`[${e}]`:e);if(n instanceof Array){const r=n.map(o=>encodeURIComponent(String(o))).join(`&${encodeURIComponent(i)}=`);return`${encodeURIComponent(i)}=${r}`}if(n instanceof Set){const r=Array.from(n);return q(e,r,t)}return n instanceof Date?`${encodeURIComponent(i)}=${encodeURIComponent(n.toISOString())}`:n instanceof Object?E(n,i):`${encodeURIComponent(i)}=${encodeURIComponent(String(n))}`}function m(e,n){return Object.keys(e).reduce((t,i)=>({...t,[i]:n(e[i])}),{})}class f{constructor(n,t=i=>i){this.raw=n,this.transformer=t}async value(){return this.transformer(await this.raw.json())}}function F(e){return D(e)}function D(e,n){return e==null?e:{identifier:e.identifier==null?void 0:e.identifier,content:e.content==null?void 0:e.content.map(R)}}function R(e){return M(e)}function M(e,n){return e==null?e:{items:e.items==null?void 0:e.items,content:e.content==null?void 0:e.content,config:e.config==null?void 0:e.config,identifier:e.identifier==null?void 0:e.identifier,uid:e.uid==null?void 0:e.uid,component:e.component==null?void 0:e.component,slots:e.slots==null?void 0:m(e.slots,F)}}function C(e){return G(e)}function G(e,n){return e==null?e:{type:e.type==null?void 0:e.type,target:e.target==null?void 0:e.target,label:e.label==null?void 0:e.label,href:e.href==null?void 0:e.href,slug:e.slug==null?void 0:e.slug,properties:e.properties==null?void 0:e.properties,children:e.children==null?void 0:e.children.map(C)}}function J(e){return V(e)}function V(e,n){return e==null?e:{items:e.items==null?void 0:e.items.map(C),uid:e.uid==null?void 0:e.uid,identifier:e.identifier==null?void 0:e.identifier,label:e.label==null?void 0:e.label}}function W(e){return Q(e)}function Q(e,n){return e==null?e:{domain:e.domain==null?void 0:e.domain,slug:e.slug==null?void 0:e.slug,version:e.version==null?void 0:e.version,updated_at:e.updated_at==null?void 0:e.updated_at,language:e.language==null?void 0:e.language,primary_language:e.primary_language==null?void 0:e.primary_language}}function z(e){return H(e)}function H(e,n){return e==null?e:{nitro:e.nitro==null?void 0:W(e.nitro),pages:e.pages==null?void 0:e.pages,containers:e.containers==null?void 0:m(e.containers,J),globals:e.globals==null?void 0:e.globals}}function Y(e){return Z(e)}function Z(e,n){return e==null?e:{api:e.api==null?void 0:e.api,image:e.image==null?void 0:e.image}}function X(e){return ee(e)}function ee(e,n){return e==null?e:{_version:e._version==null?void 0:e._version,entity_metric:e.entity_metric==null?void 0:Y(e.entity_metric),entity_unique_id:e.entity_unique_id==null?void 0:e.entity_unique_id,entity_id:e.entity_id==null?void 0:e.entity_id,entity_image:e.entity_image==null?void 0:e.entity_image,entity_slug:e.entity_slug==null?void 0:e.entity_slug,entity_teaser:e.entity_teaser==null?void 0:e.entity_teaser,entity_time_end:e.entity_time_end==null?void 0:e.entity_time_end,entity_time_start:e.entity_time_start==null?void 0:e.entity_time_start,entity_title:e.entity_title==null?void 0:e.entity_title,entity_type:e.entity_type==null?void 0:e.entity_type,entity_type_id:e.entity_type_id==null?void 0:e.entity_type_id,updated_at:e.updated_at==null?void 0:e.updated_at,routes:e.routes==null?void 0:e.routes}}function A(e){return ne(e)}function ne(e,n){return e==null?e:{entity:e.entity==null?void 0:X(e.entity),model:e.model==null?void 0:e.model,language:e.language==null?void 0:e.language,jsonld:e.jsonld==null?void 0:e.jsonld}}function I(e){return te(e)}function te(e,n){return e==null?e:{entity_unique_id:e.entity_unique_id==null?void 0:e.entity_unique_id,entity_title:e.entity_title==null?void 0:e.entity_title,entity_teaser:e.entity_teaser==null?void 0:e.entity_teaser,entity_slug:e.entity_slug==null?void 0:e.entity_slug,entity_time_start:e.entity_time_start==null?void 0:e.entity_time_start,entity_type:e.entity_type==null?void 0:e.entity_type,entity_type_id:e.entity_type_id==null?void 0:e.entity_type_id,entity_image:e.entity_image==null?void 0:e.entity_image,routes:e.routes==null?void 0:e.routes}}function ie(e){return oe(e)}function oe(e,n){return e==null?e:{description:e.description==null?void 0:e.description,image:e.image==null?void 0:e.image,title:e.title==null?void 0:e.title}}function re(e){return ae(e)}function ae(e,n){return e==null?e:{slug:e.slug==null?void 0:e.slug,title:e.title==null?void 0:e.title}}function le(e){return se(e)}function se(e,n){return e==null?e:{value:e.value==null?void 0:e.value,navigation:e.navigation==null?void 0:e.navigation,propagate:e.propagate==null?void 0:e.propagate}}function k(e){return ue(e)}function ue(e,n){return e==null?e:{id:e.id==null?void 0:e.id,title:e.title==null?void 0:e.title,href:e.href==null?void 0:e.href,slug:e.slug==null?void 0:e.slug,json:e.json==null?void 0:e.json.map(R),depth:e.depth==null?void 0:e.depth,is_home:e.is_home==null?void 0:e.is_home,created_at:e.created_at==null?void 0:e.created_at,updated_at:e.updated_at==null?void 0:e.updated_at,is_visible:e.is_visible==null?void 0:e.is_visible,meta_json:e.meta_json==null?void 0:ie(e.meta_json),properties:e.properties==null?void 0:m(e.properties,le),uid:e.uid==null?void 0:e.uid,type:e.type==null?void 0:e.type,target:e.target==null?void 0:e.target,container:e.container==null?void 0:e.container,breadcrumb:e.breadcrumb==null?void 0:e.breadcrumb.map(re)}}function ce(e){return de(e)}function de(e,n){return e==null?e:{version:e.version==null?void 0:e.version,updated_at:e.updated_at==null?void 0:e.updated_at}}class fe extends g{async configRaw(n,t){const i={};n.lang!=null&&(i.lang=n.lang);const r={};this.configuration&&this.configuration.apiKey&&(i.token=await this.configuration.apiKey("token"));const o=await this.request({path:"/config",method:"GET",headers:r,query:i},t);return new f(o,a=>z(a))}async config(n={},t){return await(await this.configRaw(n,t)).value()}}class pe extends g{async entityBySlugRaw(n,t){if(n.slug==null)throw new v("slug",'Required parameter "slug" was null or undefined when calling entityBySlug().');const i={};n.lang!=null&&(i.lang=n.lang),n.typeId!=null&&(i.typeId=n.typeId);const r={};this.configuration&&this.configuration.apiKey&&(i.token=await this.configuration.apiKey("token"));const o=await this.request({path:"/entities/slug/{slug}".replace("{slug}",encodeURIComponent(String(n.slug))),method:"GET",headers:r,query:i},t);return new f(o,a=>A(a))}async entityBySlug(n,t){return await(await this.entityBySlugRaw(n,t)).value()}async entityByUniqueidRaw(n,t){if(n.uniqueid==null)throw new v("uniqueid",'Required parameter "uniqueid" was null or undefined when calling entityByUniqueid().');const i={};n.lang!=null&&(i.lang=n.lang);const r={};this.configuration&&this.configuration.apiKey&&(i.token=await this.configuration.apiKey("token"));const o=await this.request({path:"/entities/uniqueid/{uniqueid}".replace("{uniqueid}",encodeURIComponent(String(n.uniqueid))),method:"GET",headers:r,query:i},t);return new f(o,a=>A(a))}async entityByUniqueid(n,t){return await(await this.entityByUniqueidRaw(n,t)).value()}}class ge extends g{async homeRaw(n,t){const i={};n.lang!=null&&(i.lang=n.lang);const r={};this.configuration&&this.configuration.apiKey&&(i.token=await this.configuration.apiKey("token"));const o=await this.request({path:"/pages/home",method:"GET",headers:r,query:i},t);return new f(o,a=>k(a))}async home(n={},t){return await(await this.homeRaw(n,t)).value()}async pageRaw(n,t){const i={};n.lang!=null&&(i.lang=n.lang),n.slug!=null&&(i.slug=n.slug);const r={};this.configuration&&this.configuration.apiKey&&(i.token=await this.configuration.apiKey("token"));const o=await this.request({path:"/pages",method:"GET",headers:r,query:i},t);return new f(o,a=>k(a))}async page(n={},t){return await(await this.pageRaw(n,t)).value()}}class ye extends g{async searchRaw(n,t){if(n.query==null)throw new v("query",'Required parameter "query" was null or undefined when calling search().');const i={};n.lang!=null&&(i.lang=n.lang),n.query!=null&&(i.query=n.query);const r={};this.configuration&&this.configuration.apiKey&&(i.token=await this.configuration.apiKey("token"));const o=await this.request({path:"/search",method:"GET",headers:r,query:i},t);return new f(o,a=>a.map(I))}async search(n,t){return await(await this.searchRaw(n,t)).value()}}class he extends g{async sitemapRaw(n,t){const i={};n.lang!=null&&(i.lang=n.lang);const r={};this.configuration&&this.configuration.apiKey&&(i.token=await this.configuration.apiKey("token"));const o=await this.request({path:"/sitemap",method:"GET",headers:r,query:i},t);return new f(o,a=>a.map(I))}async sitemap(n={},t){return await(await this.sitemapRaw(n,t)).value()}}class ve extends g{async versionRaw(n,t){const i={};n.lang!=null&&(i.lang=n.lang);const r={};this.configuration&&this.configuration.apiKey&&(i.token=await this.configuration.apiKey("token"));const o=await this.request({path:"/version",method:"GET",headers:r,query:i},t);return new f(o,a=>ce(a))}async version(n={},t){return await(await this.versionRaw(n,t)).value()}}const me=/[\p{Lu}]/u,we=/[\p{Ll}]/u,S=/^[\p{Lu}](?![\p{Lu}])/gu,T=/([\p{Alpha}\p{N}_]|$)/u,w=/[_.\- ]+/,_e=new RegExp("^"+w.source),U=new RegExp(w.source+T.source,"gu"),j=new RegExp("\\d+"+T.source,"gu"),be=(e,n,t,i)=>{let r=!1,o=!1,a=!1,l=!1;for(let s=0;s<e.length;s++){const c=e[s];l=s>2?e[s-3]==="-":!0,r&&me.test(c)?(e=e.slice(0,s)+"-"+e.slice(s),r=!1,a=o,o=!0,s++):o&&a&&we.test(c)&&(!l||i)?(e=e.slice(0,s-1)+"-"+e.slice(s-1),a=o,o=!1,r=!0):(r=n(c)===c&&t(c)!==c,a=o,o=t(c)===c&&n(c)!==c)}return e},Ee=(e,n)=>(S.lastIndex=0,e.replace(S,t=>n(t))),qe=(e,n)=>(U.lastIndex=0,j.lastIndex=0,e.replace(U,(t,i)=>n(i)).replace(j,t=>n(t)));function Re(e,n){if(!(typeof e=="string"||Array.isArray(e)))throw new TypeError("Expected the input to be `string | string[]`");if(n={pascalCase:!1,preserveConsecutiveUppercase:!1,...n},Array.isArray(e)?e=e.map(o=>o.trim()).filter(o=>o.length).join("-"):e=e.trim(),e.length===0)return"";const t=n.locale===!1?o=>o.toLowerCase():o=>o.toLocaleLowerCase(n.locale),i=n.locale===!1?o=>o.toUpperCase():o=>o.toLocaleUpperCase(n.locale);return e.length===1?w.test(e)?"":n.pascalCase?i(e):t(e):(e!==t(e)&&(e=be(e,t,i,n.preserveConsecutiveUppercase)),e=e.replace(_e,""),e=n.preserveConsecutiveUppercase?Ee(e,t):t(e),n.pascalCase&&(e=i(e.charAt(0))+e.slice(1)),qe(e,i))}function Ce(e,n,t){const i="virtual:flyo-components",r="\0"+i;return{name:"vite-plugin-flyo-components",async resolveId(o){if(o===i)return r},async load(o){if(o===r){const a=[];for(const[s,c]of Object.entries(n)){const h=await this.resolve("/"+e+"/"+c+".astro");h&&a.push(`export { default as ${Re(s)} } from "${h.id}"`)}let l=null;return t&&(l=await this.resolve("/"+e+"/"+t+".astro")),l?a.push(`export { default as fallback } from "${l.id}"`):a.push('export { default as fallback } from "@flyo/nitro-astro/FallbackComponent.astro"'),a.join(";")}}}}let Ae=Symbol("clean"),u=[],Ie=(e,n)=>{let t=[],i={get(){return i.lc||i.listen(()=>{})(),i.value},l:n||0,lc:0,listen(r,o){return i.lc=t.push(r,o||i.l)/2,()=>{let a=t.indexOf(r);~a&&(t.splice(a,2),--i.lc||i.off())}},notify(r,o){let a=!u.length;for(let l=0;l<t.length;l+=2)u.push(t[l],t[l+1],i.value,r,o);if(a){for(let l=0;l<u.length;l+=5){let s;for(let c=l+1;!s&&(c+=5)<u.length;)u[c]<u[l+1]&&(s=u.push(u[l],u[l+1],u[l+2],u[l+3],u[l+4]));s||u[l](u[l+2],u[l+3],u[l+4])}u.length=0}},off(){},set(r){let o=i.value;o!==r&&(i.value=r,i.notify(o))},subscribe(r,o){let a=i.listen(r,o);return r(i.value),a},value:e};return process.env.NODE_ENV!=="production"&&(i[Ae]=()=>{t=[],i.lc=0,i.off()}),i};function p(){return globalThis.flyoNitroInstance||console.error("The Flyo Typescript Configuration has not been initialized correctly"),globalThis.flyoNitroInstance}function P(){return new fe(p())}const _=Ie(!1);async function ke(e=null){return(!_.get()||globalThis.flyoNitroIntegrationOptions.liveEdit)&&_.set(await P().config({lang:e})),_.get()}function Se(){return new pe(p())}function Te(){return new ge(p())}function Ue(){return new ye(p())}function je(){return new he(p())}function Pe(){return new ve(p())}function Le(e){return{"data-flyo-block-uid":e.uid}}function Ne(e){const n={accessToken:!1,liveEdit:!1,fallbackComponent:null,componentsDir:"src/components/flyo",...e};return n.liveEdit==="true"?n.liveEdit=!0:n.liveEdit==="false"&&(n.liveEdit=!1),{name:"@flyo/nitro-astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:i,injectRoute:r})=>{r({pattern:"sitemap.xml",entrypoint:"@flyo/nitro-astro/sitemap.ts"}),i({image:{service:{entrypoint:"@flyo/nitro-astro/cdn.ts"}},vite:{plugins:[Ce(e.componentsDir,e.components,e.fallbackComponent)]}}),t("page-ssr",`
|
|
2
2
|
import { Configuration } from '@flyo/nitro-typescript'
|
|
3
3
|
|
|
4
4
|
var defaultConfig = new Configuration({
|
|
5
|
-
apiKey: '${
|
|
5
|
+
apiKey: '${n.accessToken}'
|
|
6
6
|
})
|
|
7
7
|
|
|
8
8
|
globalThis.flyoNitroInstance = defaultConfig;
|
|
9
|
-
|
|
9
|
+
globalThis.flyoNitroIntegrationOptions = {
|
|
10
|
+
liveEdit: ${n.liveEdit}
|
|
11
|
+
};
|
|
12
|
+
`),n.liveEdit&&t("page",`
|
|
10
13
|
window.addEventListener("message", (event) => {
|
|
11
14
|
if (event.data?.action === 'pageRefresh') {
|
|
12
15
|
window.location.reload(true);
|
|
@@ -37,4 +40,4 @@
|
|
|
37
40
|
openBlockInFlyo(this.getAttribute('data-flyo-block-uid'))
|
|
38
41
|
});
|
|
39
42
|
});
|
|
40
|
-
`)}}}}
|
|
43
|
+
`)}}}}d.default=Ne,d.editableBlock=Le,d.useConfig=ke,d.useConfigApi=P,d.useConfiguration=p,d.useEntitiesApi=Se,d.usePagesApi=Te,d.useSearchApi=Ue,d.useSitemapApi=je,d.useVersionApi=Pe,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|