@kyro-cms/core 0.12.3 → 0.12.4
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/{WebhookService-DTNKXpXp.d.ts → WebhookService-B15DnDeH.d.cts} +3 -7
- package/dist/{WebhookService-DRQLv_jR.d.cts → WebhookService-DJ75IwdZ.d.ts} +3 -7
- package/dist/api-handler-graphql.cjs +1 -1
- package/dist/api-handler-graphql.js +1 -1
- package/dist/api-handler-trpc.cjs +1 -1
- package/dist/api-handler-trpc.js +1 -1
- package/dist/api-handler.cjs +1 -1
- package/dist/api-handler.js +1 -1
- package/dist/{base-Dk6eKGJJ.d.cts → base-CXZxchcr.d.cts} +1 -1
- package/dist/{base-BKGB0Y3W.d.ts → base-CjuIfzH2.d.ts} +1 -1
- package/dist/{chunk-GDCTY6JO.js → chunk-EHLNY6BK.js} +1 -1
- package/dist/{chunk-7WQ4D7WW.cjs → chunk-GZGP4THY.cjs} +1 -1
- package/dist/chunk-I67R6MR5.js +2 -0
- package/dist/{chunk-5BPMMIAQ.js → chunk-ISCIUG37.js} +1 -1
- package/dist/chunk-UTFLD5DC.cjs +86 -0
- package/dist/{chunk-32GUKU7D.cjs → chunk-W7OSRADF.cjs} +2 -2
- package/dist/{chunk-ER2PUSHG.cjs → chunk-WMZEULS2.cjs} +1 -1
- package/dist/chunk-XSGRGUHP.js +86 -0
- package/dist/chunk-XUONID6O.cjs +2 -0
- package/dist/{chunk-MAWFXNW4.js → chunk-ZRSXM4BY.js} +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/drizzle/index.d.cts +2 -2
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/graphql/index.d.cts +2 -2
- package/dist/graphql/index.d.ts +2 -2
- package/dist/{index-yPGko8UV.d.cts → index-BCUSHYBf.d.cts} +1 -1
- package/dist/{index-cBgeiKp1.d.ts → index-C7FPi-Fj.d.ts} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -1
- package/dist/mongodb/index.d.cts +2 -2
- package/dist/mongodb/index.d.ts +2 -2
- package/dist/rest/index.cjs +1 -1
- package/dist/rest/index.d.cts +3 -3
- package/dist/rest/index.d.ts +3 -3
- package/dist/rest/index.js +1 -1
- package/dist/templates/index.d.cts +1 -1
- package/dist/templates/index.d.ts +1 -1
- package/dist/trpc/index.cjs +1 -1
- package/dist/trpc/index.d.cts +2 -2
- package/dist/trpc/index.d.ts +2 -2
- package/dist/trpc/index.js +1 -1
- package/dist/{types-BowAPGjD.d.cts → types-CqqoM3Dy.d.cts} +2 -1
- package/dist/{types-Bj3d_ys8.d.ts → types-L-qNugRL.d.ts} +2 -1
- package/package.json +1 -1
- package/dist/chunk-54B2Q567.cjs +0 -86
- package/dist/chunk-B7V5KOIM.js +0 -86
- package/dist/chunk-KG7V6O2Z.js +0 -2
- package/dist/chunk-WE46GGL4.cjs +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BaseAdapter } from './types-
|
|
1
|
+
import { B as BaseAdapter } from './types-CqqoM3Dy.cjs';
|
|
2
2
|
|
|
3
3
|
declare const WEBHOOK_EVENTS: {
|
|
4
4
|
readonly COLLECTION_CREATE: "collection.create";
|
|
@@ -16,15 +16,11 @@ declare const WEBHOOK_EVENTS: {
|
|
|
16
16
|
};
|
|
17
17
|
type WebhookEvent = (typeof WEBHOOK_EVENTS)[keyof typeof WEBHOOK_EVENTS];
|
|
18
18
|
declare const ALL_WEBHOOK_EVENTS: WebhookEvent[];
|
|
19
|
-
type WebhookActionType = "generic" | "github-
|
|
19
|
+
type WebhookActionType = "generic" | "github-push";
|
|
20
20
|
interface WebhookActionConfig {
|
|
21
21
|
githubOwner?: string;
|
|
22
22
|
githubRepo?: string;
|
|
23
|
-
|
|
24
|
-
dokployProjectId?: string;
|
|
25
|
-
dokployBranch?: string;
|
|
26
|
-
coolifyProjectUuid?: string;
|
|
27
|
-
coolifyEnvironmentName?: string;
|
|
23
|
+
githubBranch?: string;
|
|
28
24
|
}
|
|
29
25
|
interface WebhookConfig {
|
|
30
26
|
id: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BaseAdapter } from './types-
|
|
1
|
+
import { B as BaseAdapter } from './types-L-qNugRL.js';
|
|
2
2
|
|
|
3
3
|
declare const WEBHOOK_EVENTS: {
|
|
4
4
|
readonly COLLECTION_CREATE: "collection.create";
|
|
@@ -16,15 +16,11 @@ declare const WEBHOOK_EVENTS: {
|
|
|
16
16
|
};
|
|
17
17
|
type WebhookEvent = (typeof WEBHOOK_EVENTS)[keyof typeof WEBHOOK_EVENTS];
|
|
18
18
|
declare const ALL_WEBHOOK_EVENTS: WebhookEvent[];
|
|
19
|
-
type WebhookActionType = "generic" | "github-
|
|
19
|
+
type WebhookActionType = "generic" | "github-push";
|
|
20
20
|
interface WebhookActionConfig {
|
|
21
21
|
githubOwner?: string;
|
|
22
22
|
githubRepo?: string;
|
|
23
|
-
|
|
24
|
-
dokployProjectId?: string;
|
|
25
|
-
dokployBranch?: string;
|
|
26
|
-
coolifyProjectUuid?: string;
|
|
27
|
-
coolifyEnvironmentName?: string;
|
|
23
|
+
githubBranch?: string;
|
|
28
24
|
}
|
|
29
25
|
interface WebhookConfig {
|
|
30
26
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkGZGP4THY_cjs=require('./chunk-GZGP4THY.cjs');require('./chunk-W7OSRADF.cjs'),require('./chunk-UJNSOOYZ.cjs'),require('./chunk-65G73T7Z.cjs'),require('./chunk-KD7LUCFY.cjs'),require('./chunk-WMZEULS2.cjs'),require('./chunk-HS2KNFAB.cjs'),require('./chunk-UTFLD5DC.cjs'),require('./chunk-AJAZ7D3W.cjs'),require('./chunk-WIZ6C5QZ.cjs'),require('./chunk-GFU7AOI3.cjs'),require('./chunk-ET6NN2V2.cjs'),require('./chunk-HVXO3OFB.cjs'),require('./chunk-XUONID6O.cjs'),require('./chunk-NY47CFVP.cjs'),require('./chunk-G3J2EU5D.cjs'),require('./chunk-4ORJMSJU.cjs'),require('./chunk-Z7CNY2UV.cjs'),require('./chunk-GYQMNXXW.cjs'),require('./chunk-MIOMMB23.cjs'),require('./chunk-UBHFUFD4.cjs'),require('./chunk-UCCFT5OO.cjs'),require('./chunk-ATLSIYRH.cjs'),require('./chunk-EJDIR56C.cjs'),require('./chunk-Q3Q7BJVQ.cjs'),require('./chunk-AHSFSERC.cjs');function n(e){return new Response(e.body,e)}var p={graphqlEnabled:false,trpcEnabled:false,wsEnabled:false,requireAuth:false};function r(){return new Response(JSON.stringify({error:"GraphQL is disabled"}),{status:503,headers:{"Content-Type":"application/json"}})}async function o(){try{return (await chunkGZGP4THY_cjs.a.db.findOne({collection:"_globals_access-settings",where:{},draft:!0}))?.apiAccess?.graphqlEnabled??p.graphqlEnabled}catch{return true}}var l=async e=>{if(await chunkGZGP4THY_cjs.b(),!await o())return r();let t=await chunkGZGP4THY_cjs.a.getGraphQL().fetch(e.request,e.locals);return n(t)},u=async e=>{if(await chunkGZGP4THY_cjs.b(),!await o())return r();let t=await chunkGZGP4THY_cjs.a.getGraphQL().fetch(e.request,e.locals);return n(t)};exports.GET=u;exports.POST=l;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b,a}from'./chunk-
|
|
1
|
+
import {b,a}from'./chunk-ZRSXM4BY.js';import'./chunk-EHLNY6BK.js';import'./chunk-FO3HLBC7.js';import'./chunk-NZ35PV5R.js';import'./chunk-5SEHX7ON.js';import'./chunk-ISCIUG37.js';import'./chunk-PP7W5UKL.js';import'./chunk-XSGRGUHP.js';import'./chunk-7WOX27LK.js';import'./chunk-K6WUOU6P.js';import'./chunk-AE6GXUT7.js';import'./chunk-2W4FK6CJ.js';import'./chunk-NRLIGDYF.js';import'./chunk-I67R6MR5.js';import'./chunk-HLSB2MCK.js';import'./chunk-GKYEJ2UF.js';import'./chunk-PP5S2UBV.js';import'./chunk-3YGGZ2VN.js';import'./chunk-RHCWCG3O.js';import'./chunk-OG7CNQGU.js';import'./chunk-QRXDCV6K.js';import'./chunk-YPDRUVWG.js';import'./chunk-P7CESLDJ.js';import'./chunk-TQNM4C7H.js';import'./chunk-KDNYHLD2.js';import'./chunk-5J6HXUF6.js';function n(e){return new Response(e.body,e)}var p={graphqlEnabled:false,trpcEnabled:false,wsEnabled:false,requireAuth:false};function r(){return new Response(JSON.stringify({error:"GraphQL is disabled"}),{status:503,headers:{"Content-Type":"application/json"}})}async function o(){try{return (await a.db.findOne({collection:"_globals_access-settings",where:{},draft:!0}))?.apiAccess?.graphqlEnabled??p.graphqlEnabled}catch{return true}}var l=async e=>{if(await b(),!await o())return r();let t=await a.getGraphQL().fetch(e.request,e.locals);return n(t)},u=async e=>{if(await b(),!await o())return r();let t=await a.getGraphQL().fetch(e.request,e.locals);return n(t)};export{u as GET,l as POST};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkGZGP4THY_cjs=require('./chunk-GZGP4THY.cjs');require('./chunk-W7OSRADF.cjs'),require('./chunk-UJNSOOYZ.cjs'),require('./chunk-65G73T7Z.cjs'),require('./chunk-KD7LUCFY.cjs'),require('./chunk-WMZEULS2.cjs'),require('./chunk-HS2KNFAB.cjs'),require('./chunk-UTFLD5DC.cjs'),require('./chunk-AJAZ7D3W.cjs'),require('./chunk-WIZ6C5QZ.cjs'),require('./chunk-GFU7AOI3.cjs'),require('./chunk-ET6NN2V2.cjs'),require('./chunk-HVXO3OFB.cjs'),require('./chunk-XUONID6O.cjs'),require('./chunk-NY47CFVP.cjs'),require('./chunk-G3J2EU5D.cjs'),require('./chunk-4ORJMSJU.cjs'),require('./chunk-Z7CNY2UV.cjs'),require('./chunk-GYQMNXXW.cjs'),require('./chunk-MIOMMB23.cjs'),require('./chunk-UBHFUFD4.cjs'),require('./chunk-UCCFT5OO.cjs'),require('./chunk-ATLSIYRH.cjs'),require('./chunk-EJDIR56C.cjs'),require('./chunk-Q3Q7BJVQ.cjs'),require('./chunk-AHSFSERC.cjs');function n(){return new Response(JSON.stringify({error:"tRPC is disabled"}),{status:503,headers:{"Content-Type":"application/json"}})}var r={graphqlEnabled:false,trpcEnabled:false,wsEnabled:false,requireAuth:false};async function s(){try{return (await chunkGZGP4THY_cjs.a.db.findOne({collection:"_globals_access-settings",where:{},draft:!0}))?.apiAccess?.trpcEnabled??r.trpcEnabled}catch{return true}}var i=async e=>(await chunkGZGP4THY_cjs.b(),await s()?chunkGZGP4THY_cjs.a.getTRPC().fetch(e.request,e.locals):n());exports.ALL=i;
|
package/dist/api-handler-trpc.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b,a}from'./chunk-
|
|
1
|
+
import {b,a}from'./chunk-ZRSXM4BY.js';import'./chunk-EHLNY6BK.js';import'./chunk-FO3HLBC7.js';import'./chunk-NZ35PV5R.js';import'./chunk-5SEHX7ON.js';import'./chunk-ISCIUG37.js';import'./chunk-PP7W5UKL.js';import'./chunk-XSGRGUHP.js';import'./chunk-7WOX27LK.js';import'./chunk-K6WUOU6P.js';import'./chunk-AE6GXUT7.js';import'./chunk-2W4FK6CJ.js';import'./chunk-NRLIGDYF.js';import'./chunk-I67R6MR5.js';import'./chunk-HLSB2MCK.js';import'./chunk-GKYEJ2UF.js';import'./chunk-PP5S2UBV.js';import'./chunk-3YGGZ2VN.js';import'./chunk-RHCWCG3O.js';import'./chunk-OG7CNQGU.js';import'./chunk-QRXDCV6K.js';import'./chunk-YPDRUVWG.js';import'./chunk-P7CESLDJ.js';import'./chunk-TQNM4C7H.js';import'./chunk-KDNYHLD2.js';import'./chunk-5J6HXUF6.js';function n(){return new Response(JSON.stringify({error:"tRPC is disabled"}),{status:503,headers:{"Content-Type":"application/json"}})}var r={graphqlEnabled:false,trpcEnabled:false,wsEnabled:false,requireAuth:false};async function s(){try{return (await a.db.findOne({collection:"_globals_access-settings",where:{},draft:!0}))?.apiAccess?.trpcEnabled??r.trpcEnabled}catch{return true}}var i=async e=>(await b(),await s()?a.getTRPC().fetch(e.request,e.locals):n());export{i as ALL};
|
package/dist/api-handler.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkGZGP4THY_cjs=require('./chunk-GZGP4THY.cjs');require('./chunk-W7OSRADF.cjs'),require('./chunk-UJNSOOYZ.cjs'),require('./chunk-65G73T7Z.cjs'),require('./chunk-KD7LUCFY.cjs'),require('./chunk-WMZEULS2.cjs'),require('./chunk-HS2KNFAB.cjs'),require('./chunk-UTFLD5DC.cjs'),require('./chunk-AJAZ7D3W.cjs'),require('./chunk-WIZ6C5QZ.cjs'),require('./chunk-GFU7AOI3.cjs'),require('./chunk-ET6NN2V2.cjs'),require('./chunk-HVXO3OFB.cjs'),require('./chunk-XUONID6O.cjs'),require('./chunk-NY47CFVP.cjs'),require('./chunk-G3J2EU5D.cjs'),require('./chunk-4ORJMSJU.cjs'),require('./chunk-Z7CNY2UV.cjs'),require('./chunk-GYQMNXXW.cjs'),require('./chunk-MIOMMB23.cjs'),require('./chunk-UBHFUFD4.cjs'),require('./chunk-UCCFT5OO.cjs'),require('./chunk-ATLSIYRH.cjs'),require('./chunk-EJDIR56C.cjs'),require('./chunk-Q3Q7BJVQ.cjs'),require('./chunk-AHSFSERC.cjs');Object.defineProperty(exports,"ALL",{enumerable:true,get:function(){return chunkGZGP4THY_cjs.c}});Object.defineProperty(exports,"kyroInstance",{enumerable:true,get:function(){return chunkGZGP4THY_cjs.a}});Object.defineProperty(exports,"warmKyroInstance",{enumerable:true,get:function(){return chunkGZGP4THY_cjs.b}});
|
package/dist/api-handler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{c as ALL,a as kyroInstance,b as warmKyroInstance}from'./chunk-
|
|
1
|
+
export{c as ALL,a as kyroInstance,b as warmKyroInstance}from'./chunk-ZRSXM4BY.js';import'./chunk-EHLNY6BK.js';import'./chunk-FO3HLBC7.js';import'./chunk-NZ35PV5R.js';import'./chunk-5SEHX7ON.js';import'./chunk-ISCIUG37.js';import'./chunk-PP7W5UKL.js';import'./chunk-XSGRGUHP.js';import'./chunk-7WOX27LK.js';import'./chunk-K6WUOU6P.js';import'./chunk-AE6GXUT7.js';import'./chunk-2W4FK6CJ.js';import'./chunk-NRLIGDYF.js';import'./chunk-I67R6MR5.js';import'./chunk-HLSB2MCK.js';import'./chunk-GKYEJ2UF.js';import'./chunk-PP5S2UBV.js';import'./chunk-3YGGZ2VN.js';import'./chunk-RHCWCG3O.js';import'./chunk-OG7CNQGU.js';import'./chunk-QRXDCV6K.js';import'./chunk-YPDRUVWG.js';import'./chunk-P7CESLDJ.js';import'./chunk-TQNM4C7H.js';import'./chunk-KDNYHLD2.js';import'./chunk-5J6HXUF6.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BaseAdapter, C as CollectionConfig, G as GlobalConfig, T as TenantContext, F as FindArgs, b as FindResult, c as FindByIDArgs, d as CreateArgs, e as UpdateArgs, D as DeleteArgs, f as FindVersionsArgs, g as VersionRecord, h as CreateVersionArgs } from './types-
|
|
1
|
+
import { B as BaseAdapter, C as CollectionConfig, G as GlobalConfig, T as TenantContext, F as FindArgs, b as FindResult, c as FindByIDArgs, d as CreateArgs, e as UpdateArgs, D as DeleteArgs, f as FindVersionsArgs, g as VersionRecord, h as CreateVersionArgs } from './types-CqqoM3Dy.cjs';
|
|
2
2
|
import { F as Field, k as RelationshipField, U as UploadField } from './types-fvldOd92.cjs';
|
|
3
3
|
|
|
4
4
|
declare abstract class AbstractBaseAdapter implements BaseAdapter {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BaseAdapter, C as CollectionConfig, G as GlobalConfig, T as TenantContext, F as FindArgs, b as FindResult, c as FindByIDArgs, d as CreateArgs, e as UpdateArgs, D as DeleteArgs, f as FindVersionsArgs, g as VersionRecord, h as CreateVersionArgs } from './types-
|
|
1
|
+
import { B as BaseAdapter, C as CollectionConfig, G as GlobalConfig, T as TenantContext, F as FindArgs, b as FindResult, c as FindByIDArgs, d as CreateArgs, e as UpdateArgs, D as DeleteArgs, f as FindVersionsArgs, g as VersionRecord, h as CreateVersionArgs } from './types-L-qNugRL.js';
|
|
2
2
|
import { F as Field, k as RelationshipField, U as UploadField } from './types-fvldOd92.js';
|
|
3
3
|
|
|
4
4
|
declare abstract class AbstractBaseAdapter implements BaseAdapter {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-NZ35PV5R.js';import {a}from'./chunk-5SEHX7ON.js';import {a as a$3,i}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-NZ35PV5R.js';import {a}from'./chunk-5SEHX7ON.js';import {a as a$3,i}from'./chunk-ISCIUG37.js';import {c as c$1,a as a$2}from'./chunk-PP7W5UKL.js';import {f,s,a as a$5,b as b$2,c as c$3}from'./chunk-XSGRGUHP.js';import {o,f as f$1,g as g$1}from'./chunk-I67R6MR5.js';import {d,f as f$2,e,g as g$2}from'./chunk-HLSB2MCK.js';import {b,d as d$1}from'./chunk-GKYEJ2UF.js';import {c}from'./chunk-3YGGZ2VN.js';import {g}from'./chunk-OG7CNQGU.js';import {a as a$4,c as c$2,b as b$1,d as d$2}from'./chunk-TQNM4C7H.js';import {z as z$1}from'zod';import {createYoga}from'graphql-yoga';import {createRequire}from'module';import {randomBytes}from'crypto';function O(s,e){for(let t of s){if(t.name===e)return true;if("tabs"in t&&t.tabs){for(let n of t.tabs)if(O(n.fields,e))return true}if("fields"in t&&t.fields&&O(t.fields,e))return true}return false}var K=class extends Error{errors;constructor(e){super(`Configuration validation failed:
|
|
2
2
|
${e.join(`
|
|
3
3
|
`)}`),this.name="ConfigValidationError",this.errors=e;}};function V(s){let e=[];if(s.slug?/^[a-z][a-z0-9_-]*$/.test(s.slug)||e.push(`Collection slug "${s.slug}" must be lowercase alphanumeric with dashes`):e.push('Collection is missing a "slug" property'),!s.fields||s.fields.length===0)e.push(`Collection "${s.slug}" has no fields defined`);else {let t=N(s.fields,s.slug);e.push(...t);}if(s.access)for(let[t,n]of Object.entries(s.access))typeof n!="boolean"&&typeof n!="function"&&e.push(`Collection "${s.slug}" has invalid access.${t} (must be boolean or function)`);if(s.admin?.useAsTitle&&(O(s.fields,s.admin.useAsTitle)||e.push(`Collection "${s.slug}" admin.useAsTitle references unknown field "${s.admin.useAsTitle}"`)),s.admin?.defaultColumns)for(let t of s.admin.defaultColumns)O(s.fields,t)||e.push(`Collection "${s.slug}" admin.defaultColumns references unknown field "${t}"`);if(s.upload&&s.upload.fileSize&&s.upload.fileSize<=0&&e.push(`Collection "${s.slug}" upload.fileSize must be positive`),s.versions&&s.versions.maxPerDoc&&s.versions.maxPerDoc<=0&&e.push(`Collection "${s.slug}" versions.maxPerDoc must be positive`),s.auth){let t=s.fields.some(a=>a.name==="email"),n=s.fields.some(a=>a.name==="password");t||e.push(`Collection "${s.slug}" with auth enabled requires an "email" field`),n||e.push(`Collection "${s.slug}" with auth enabled requires a "password" field`);}return e}function B(s){let e=[];if(s.slug?/^[a-z][a-z0-9_-]*$/.test(s.slug)||e.push(`Global slug "${s.slug}" must be lowercase alphanumeric with dashes`):e.push('Global is missing a "slug" property'),!s.fields||s.fields.length===0)e.push(`Global "${s.slug}" has no fields defined`);else {let t=N(s.fields,`global:${s.slug}`);e.push(...t);}return e}function N(s,e){let t=[],n=new Set;for(let a=0;a<s.length;a++){let i=s[a];if(i.type==="row"||i.type==="collapsible"||i.type==="tabs"){if("fields"in i&&i.fields){let r=N(i.fields,e);t.push(...r);}else if("tabs"in i)for(let r of i.tabs){let c=N(r.fields,e);t.push(...c);}continue}let o=i.name;if(!o){t.push(`${e}: Field at index ${a} is missing a "name" property`);continue}if(n.has(o)&&t.push(`${e}: Duplicate field name "${o}"`),n.add(o),/^[a-zA-Z][a-zA-Z0-9_]*$/.test(o)||t.push(`${e}: Field name "${o}" must be alphanumeric with underscores`),!i.type){t.push(`${e}: Field "${o}" is missing a "type" property`);continue}switch(i.type){case "relationship":i.relationTo||t.push(`${e}: Relationship field "${o}" is missing "relationTo"`);break;case "array":if(!i.fields||i.fields.length===0)t.push(`${e}: Array field "${o}" has no fields defined`);else {let r=N(i.fields,`${e}.${o}`);t.push(...r);}break;case "group":if(!i.fields||i.fields.length===0)t.push(`${e}: Group field "${o}" has no fields defined`);else {let r=N(i.fields,`${e}.${o}`);t.push(...r);}break;case "blocks":if(!i.blocks||i.blocks.length===0)t.push(`${e}: Blocks field "${o}" has no blocks defined`);else {let r=Ie(i.blocks,`${e}.${o}`);t.push(...r);}break;case "select":case "radio":if(typeof i.options=="function")break;if((!i.options||i.options.length===0)&&!i.dynamicOptions)t.push(`${e}: ${i.type} field "${o}" has no options defined`);else if(Array.isArray(i.options)){let r=i.options.map(d=>d.value),c=new Set(r);r.length!==c.size&&t.push(`${e}: ${i.type} field "${o}" has duplicate option values`);}break;case "upload":i.relationTo||t.push(`${e}: Upload field "${o}" is missing "relationTo"`);break}"min"in i&&"max"in i&&i.min>i.max&&t.push(`${e}: Field "${o}" has min greater than max`),"minLength"in i&&"maxLength"in i&&i.minLength>i.maxLength&&t.push(`${e}: Field "${o}" has minLength greater than maxLength`),"minRows"in i&&"maxRows"in i&&i.minRows>i.maxRows&&t.push(`${e}: Field "${o}" has minRows greater than maxRows`);}return t}function Ie(s,e){let t=[],n=new Set;for(let a of s){if(!a.slug){t.push(`${e}: Block is missing a "slug" property`);continue}if(n.has(a.slug)&&t.push(`${e}: Duplicate block slug "${a.slug}"`),n.add(a.slug),a.label||t.push(`${e}: Block "${a.slug}" is missing a "label" property`),!a.fields||a.fields.length===0)t.push(`${e}: Block "${a.slug}" has no fields defined`);else {let i=N(a.fields,`${e}.${a.slug}`);t.push(...i);}}return t}function fe(s,e=[]){let t=[],n=new Set;for(let a of s)n.has(a.slug)&&t.push(`Duplicate collection slug "${a.slug}"`),n.add(a.slug);for(let a of e)n.has(a.slug)&&t.push(`Duplicate global slug "${a.slug}"`),n.add(a.slug);for(let a of s){let i=V(a);t.push(...i);}for(let a of e){let i=B(a);t.push(...i);}for(let a of s){let i=$(a.fields,s);t.push(...i);}if(t.length>0)throw new K(t)}function $(s,e){let t=[],n=new Set(e.map(a=>a.slug));for(let a of s){if(a.type==="relationship"){let i=Array.isArray(a.relationTo)?a.relationTo:[a.relationTo];for(let o of i)n.has(o)||console.warn(`[Kyro Config Warning]: Relationship field "${a.name}" references unknown collection "${o}". Select options will not be available until this collection is registered.`);}if(a.type==="upload"){let i=Array.isArray(a.relationTo)?a.relationTo:[a.relationTo];for(let o of i)n.has(o)||t.push(`Upload field "${a.name}" references unknown collection "${o}"`);}if("fields"in a&&a.fields){let i=$(a.fields,e);t.push(...i);}if("tabs"in a)for(let i of a.tabs){let o=$(i.fields,e);t.push(...o);}if("blocks"in a)for(let i of a.blocks){let o=$(i.fields,e);t.push(...o);}}return t}function C(s){switch(s.type){case "text":return $e(s);case "number":return Oe(s);case "checkbox":return Pe(s);case "date":return Le(s);case "email":return ke(s);case "password":return _e(s);case "textarea":return je(s);case "select":return Ze(s);case "radio":return qe(s);case "color":return Ue(s);case "richtext":return Ge(s);case "json":return Ke(s);case "code":return Ve(s);case "upload":return ye(s);case "image":return ye(s);case "markdown":return Be(s);case "relationship":return he(s);case "relationship-block":return he(s);case "array":return Me(s);case "list":return ze(s);case "group":return We(s);case "blocks":return Xe(s);case "row":return Je(s);case "collapsible":return He(s);case "tabs":return Ye(s);default:return z$1.any()}}function $e(s){let e=z$1.string();return s.minLength&&(e=e.min(s.minLength)),s.maxLength&&(e=e.max(s.maxLength)),s.pattern&&(e=e.regex(new RegExp(s.pattern))),s.variant==="email"&&(e=e.email()),s.variant==="url"&&(e=e.url()),s.hasMany&&(e=z$1.array(e)),s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Oe(s){let e=s.integer?z$1.coerce.number().int():z$1.coerce.number();return s.min!==void 0&&(e=e.min(s.min)),s.max!==void 0&&(e=e.max(s.max)),s.step&&(e=e.refine(t=>Number.isInteger(t/s.step),`Value must be divisible by ${s.step}`)),s.hasMany&&(e=z$1.array(e)),s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Pe(s){let e=z$1.boolean();return s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Le(s){let e=z$1.string().refine(t=>!isNaN(Date.parse(t)),"Invalid date format");return s.minDate&&(e=e.refine(t=>new Date(t)>=new Date(s.minDate),`Date must be after ${s.minDate}`)),s.maxDate&&(e=e.refine(t=>new Date(t)<=new Date(s.maxDate),`Date must be before ${s.maxDate}`)),s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function ke(s){let e=z$1.string().email("Invalid email");return s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function _e(s){let e=z$1.string().min(6,"Password must be at least 6 characters");return s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function je(s){let e=z$1.string();return s.minLength&&(e=e.min(s.minLength)),s.maxLength&&(e=e.max(s.maxLength)),s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Ze(s){let e;if(Array.isArray(s.options)&&s.options.length>0){let t=s.options.map(n=>n.value);s.hasMany?e=z$1.array(z$1.enum(t)):e=z$1.enum(t);}else e=s.hasMany?z$1.array(z$1.string()):z$1.string();return s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function qe(s){let e;if(Array.isArray(s.options)&&s.options.length>0){let t=s.options.map(n=>n.value);e=z$1.enum(t);}else e=z$1.string();return s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Ue(s){let e=z$1.string();return s.format==="hex"&&(e=e.regex(/^#[0-9A-Fa-f]{6}$/)),s.format==="rgb"&&(e=e.regex(/^rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)$/)),s.format==="hsl"&&(e=e.regex(/^hsl\(\s*\d{1,3}\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%\s*\)$/)),s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Ge(s){let e=z$1.array(z$1.record(z$1.any()));return s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Ke(s){let e=z$1.union([z$1.record(z$1.any()),z$1.array(z$1.any())]);return s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Ve(s){let e=z$1.string();return s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function ye(s){let e;if(s.relationTo){let t=z$1.object({id:z$1.string(),url:z$1.string().optional(),filename:z$1.string().optional(),mimeType:z$1.string().optional()});e=z$1.union([z$1.string(),t]);}else e=z$1.string();return s.hasMany&&(e=z$1.array(e)),s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Be(s){let e=z$1.string();return s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function he(s){let e;return Array.isArray(s.relationTo)?e=z$1.object({relationTo:z$1.enum(s.relationTo),value:z$1.string()}):e=z$1.union([z$1.string(),z$1.object({relationTo:z$1.string(),value:z$1.string()})]),s.hasMany&&(e=z$1.array(e)),s.required||(e=e.optional().nullable()),s.validate&&(e=T(e,s.validate)),e}function Me(s){let e=z$1.object(Object.fromEntries(s.fields.filter(n=>n.name).map(n=>[n.name,C(n)]))).passthrough(),t=z$1.array(e);return s.minRows&&(t=t.min(s.minRows)),s.maxRows&&(t=t.max(s.maxRows)),s.required||(t=t.optional().nullable()),s.validate&&(t=T(t,s.validate)),t}function ze(s){let e=z$1.array(z$1.string());return s.required||(e=e.optional().nullable()),e}function We(s){let e=z$1.object(Object.fromEntries(s.fields.filter(t=>t.name).map(t=>[t.name,C(t)])));return s.required?e:e.optional().nullable()}function Xe(s){let e=s.blocks||[];e.map(i=>z$1.object({blockType:z$1.literal(i.slug),...Object.fromEntries(i.fields.filter(o=>o.name).map(o=>[o.name,C(o)]))}));let n=e.map(i=>i.slug),a;if(n.length>0){let i=z$1.object({blockType:z$1.enum(n)}).catchall(z$1.any()),o=z$1.object({blockType:z$1.string()}).catchall(z$1.any());a=z$1.array(z$1.union([i,o,z$1.record(z$1.any())]));}else a=z$1.array(z$1.union([z$1.object({blockType:z$1.string()}).catchall(z$1.any()),z$1.record(z$1.any())]));return s.minRows&&(a=a.min(s.minRows)),s.maxRows&&(a=a.max(s.maxRows)),s.required||(a=a.optional().nullable()),s.validate&&(a=T(a,s.validate)),a}function Je(s){return z$1.object(Object.fromEntries(s.fields.filter(t=>t.name).map(t=>[t.name,C(t)])))}function He(s){return z$1.object(Object.fromEntries(s.fields.filter(t=>t.name).map(t=>[t.name,C(t)])))}function Ye(s){let e={};for(let t of s.tabs)for(let n of t.fields)n.name&&(e[n.name]=C(n));return z$1.object(e).passthrough().optional()}function T(s,e){return s.refine(async t=>await e(t,{required:false})===true,{message:"Custom validation failed"})}function R(s){let e={};for(let t of s)if(t.name)if(t.type==="tabs"&&"tabs"in t){let n={};for(let a of t.tabs){let i=R(a.fields);Object.assign(n,i);}e[t.name]=z$1.object(n).passthrough().optional();}else if(t.type==="row"&&"fields"in t){let n=R(t.fields);Object.assign(e,n);}else t.type==="collapsible"&&"fields"in t?e[t.name]=z$1.object(R(t.fields)).passthrough().optional():e[t.name]=C(t);return e}function E(s){let e={};for(let t of s)if(t.name)if(t.type==="tabs"&&"tabs"in t){let n={};for(let a of t.tabs){let i=E(a.fields);Object.assign(n,i);}e[t.name]=z$1.object(n).passthrough().optional().nullable();}else if(t.type==="row"&&"fields"in t){let n=E(t.fields);Object.assign(e,n);}else t.type==="collapsible"&&"fields"in t?e[t.name]=z$1.object(E(t.fields)).passthrough().optional().nullable():t.type==="group"&&"fields"in t?e[t.name]=z$1.object(E(t.fields)).passthrough().optional().nullable():e[t.name]=C(t).optional().nullable();return e}function ge(s){let e=R(s.fields);return s.timestamps&&(e.createdAt=z$1.string().optional(),e.updatedAt=z$1.string().optional()),s.tenantScoped&&(e.tenantId=z$1.string().optional()),e.id=z$1.string().optional(),z$1.object(e).passthrough()}function me(s){let e=R(s.fields);return z$1.object(e).passthrough()}function be(s){let e={};for(let t of s.fields)if(t.name)if(t.type==="tabs"&&"tabs"in t){let n={};for(let a of t.tabs)for(let i of a.fields)i.name&&(n[i.name]=C(i).optional().nullable());e[t.name]=z$1.object(n).optional().nullable();}else if(t.type==="row"&&"fields"in t){let n={};for(let a of t.fields)a.name&&(n[a.name]=C(a).optional().nullable());Object.assign(e,n);}else t.type==="collapsible"&&"fields"in t?e[t.name]=z$1.object(E(t.fields)).optional().nullable():t.type==="group"&&"fields"in t?e[t.name]=z$1.object(E(t.fields)).optional().nullable():e[t.name]=C(t).optional().nullable();return z$1.object(e).passthrough()}function Te(s){let e={};for(let t of s.fields)t.name&&(e[t.name]=z$1.object({equals:z$1.any().optional(),not_equals:z$1.any().optional(),in:z$1.array(z$1.any()).optional(),not_in:z$1.array(z$1.any()).optional(),greater_than:z$1.number().optional(),greater_than_equal:z$1.number().optional(),less_than:z$1.number().optional(),less_than_equal:z$1.number().optional(),like:z$1.string().optional(),not_like:z$1.string().optional(),contains:z$1.string().optional(),exists:z$1.boolean().optional()}).optional());return e.AND=z$1.array(z$1.lazy(()=>z$1.object(e))).optional(),e.OR=z$1.array(z$1.lazy(()=>z$1.object(e))).optional(),z$1.object(e).optional()}function Ae(s){let e=R(s.fields);return e.id=z$1.string().optional(),z$1.object(e).passthrough()}function Ce(s){let e={};for(let t of s.fields)if(t.name)if(t.type==="tabs"&&"tabs"in t){let n={};for(let a of t.tabs)for(let i of a.fields)i.name&&(n[i.name]=C(i).optional().nullable());e[t.name]=z$1.object(n).optional().nullable();}else t.type==="collapsible"&&"fields"in t?e[t.name]=z$1.object(E(t.fields)).optional().nullable():t.type==="group"&&"fields"in t?e[t.name]=z$1.object(E(t.fields)).optional().nullable():e[t.name]=C(t).optional().nullable();return z$1.object(e).passthrough()}var D=class{storageProviders=f();collections=new Map;globals=new Map;plugins=[];schemaCache=new Map;initialized=false;addCollection(e){if(this.initialized)throw new Error("Cannot add collections after Registry has been initialized");if(this.collections.has(e.slug)){console.warn(`[Registry] Duplicate collection slug "${e.slug}" \u2014 skipping`);return}let t={...e};for(let a of this.plugins)a.extendCollection&&(t=a.extendCollection(t.slug,t));if(t.seo){let a$1=a(),i=t.fields.find(o=>o.type==="tabs"&&o.name==="tabs");i&&i.tabs?i.tabs.push({label:"SEO Settings",fields:a$1.fields}):t.fields.push(a$1);}t.fields=this.applyFieldDefaults(t);let n=V(t);if(n.length>0)throw new Error(`Invalid collection config: ${n.join(", ")}`);this.collections.set(t.slug,t),this.clearSchemaCache(t.slug);}addCollections(e){for(let t of e)this.addCollection(t);}getCollection(e){return this.collections.get(e)}getCollections(){return Array.from(this.collections.values())}getCollectionSlugs(){return Array.from(this.collections.keys())}hasCollection(e){return this.collections.has(e)}removeCollection(e){if(this.initialized)throw new Error("Cannot remove collections after Registry has been initialized");return this.clearSchemaCache(e),this.collections.delete(e)}addGlobal(e){if(this.initialized)throw new Error("Cannot add globals after Registry has been initialized");this._addGlobalUnsafe(e);}addGlobalPostInit(e){this.globals.has(e.slug)&&this.globals.delete(e.slug),this._addGlobalUnsafe(e);}_addGlobalUnsafe(e){if(this.globals.has(e.slug)){console.warn(`[Registry] Duplicate global slug "${e.slug}" \u2014 skipping`);return}let t=B(e);if(t.length>0)throw new Error(`Invalid global config: ${t.join(", ")}`);let n={...e};for(let a of this.plugins)a.extendGlobal&&(n=a.extendGlobal(n.slug,n));this.globals.set(n.slug,n),this.clearSchemaCache(`global:${n.slug}`);}addGlobals(e){for(let t of e)this.addGlobal(t);}getGlobal(e){return this.globals.get(e)}getGlobals(){return Array.from(this.globals.values())}getGlobalSlugs(){return Array.from(this.globals.keys())}hasGlobal(e){return this.globals.has(e)}removeGlobal(e){if(this.initialized)throw new Error("Cannot remove globals after Registry has been initialized");return this.clearSchemaCache(`global:${e}`),this.globals.delete(e)}addPlugin(e){if(this.initialized)throw new Error("Cannot add plugins after Registry has been initialized");this.plugins.push(e);}getPlugins(){return [...this.plugins]}getZodSchema(e){let t=this.schemaCache.get(e);if(t)return t;let n=this.collections.get(e);if(n){let i=ge(n);return this.schemaCache.set(e,i),i}let a=this.globals.get(e);if(a){let i=Ae(a);return this.schemaCache.set(`global:${e}`,i),i}throw new Error(`No collection or global found with slug "${e}"`)}getCreateZodSchema(e){let t=`${e}:create`,n=this.schemaCache.get(t);if(n)return n;let a=this.collections.get(e);if(a){let i=me(a);return this.schemaCache.set(t,i),i}throw new Error(`No collection found with slug "${e}"`)}getUpdateZodSchema(e){let t=`${e}:update`,n=this.schemaCache.get(t);if(n)return n;let a=this.collections.get(e);if(a){let o=be(a);return this.schemaCache.set(t,o),o}let i=this.globals.get(e);if(i){let o=Ce(i);return this.schemaCache.set(`global:${e}:update`,o),o}throw new Error(`No collection or global found with slug "${e}"`)}getWhereZodSchema(e){let t=`${e}:where`,n=this.schemaCache.get(t);if(n)return n;let a=this.collections.get(e);if(a){let i=Te(a);return this.schemaCache.set(t,i),i}throw new Error(`No collection found with slug "${e}"`)}getFieldZodSchema(e){return C(e)}clearSchemaCache(e){this.schemaCache.delete(e),this.schemaCache.delete(`${e}:create`),this.schemaCache.delete(`${e}:update`),this.schemaCache.delete(`${e}:where`);}applyFieldDefaults(e){let t=[...e.fields];return t.some(n=>n.name==="id")||t.unshift({name:"id",type:"text",admin:{readOnly:true,hidden:true}}),e.tenantScoped&&!t.some(n=>n.name==="tenantId")&&t.push({name:"tenantId",type:"text",required:true,admin:{readOnly:true,hidden:true}}),e.timestamps&&!t.some(n=>n.name==="createdAt")&&(t.push({name:"createdAt",type:"date",admin:{readOnly:true,hidden:true}}),t.push({name:"updatedAt",type:"date",admin:{readOnly:true,hidden:true}})),e.versions?.drafts&&!t.some(n=>n.name==="status")&&t.push({name:"status",type:"select",options:[{value:"draft",label:"Draft"},{value:"published",label:"Published"}],admin:{readOnly:true,hidden:true}}),e.auth&&!t.some(n=>n.name==="password")&&t.push({name:"password",type:"password",required:true,admin:{hidden:true}}),t}getFields(e){let t=this.collections.get(e);if(t)return t.fields;let n=this.globals.get(e);if(n)return n.fields;throw new Error(`No collection or global found with slug "${e}"`)}getFieldMap(e){let t=this.getFields(e),n=new Map,a=i=>{for(let o of i){if(o.name&&n.set(o.name,o),"fields"in o&&o.fields&&a(o.fields),"tabs"in o)for(let r of o.tabs)a(r.fields);if("blocks"in o)for(let r of o.blocks)a(r.fields);}};return a(t),n}getVisibleFields(e){return this.getFields(e).filter(n=>!n.admin?.hidden)}validate(){let e=this.getCollections(),t=this.getGlobals();fe(e,t);}async init(e){this.validate();for(let t of this.plugins)t.init&&await t.init(e||this);this.initialized=true;}isInitialized(){return this.initialized}getPaginationDefaults(e){let t=this.collections.get(e);return {defaultLimit:t?.admin?.pagination?.defaultLimit||10,limits:t?.admin?.pagination?.limits||[10,25,50,100]}}getDefaultSort(e){let n=this.collections.get(e)?.admin?.useAsTitle;return n||"createdAt"}getDefaultColumns(e){let t=this.collections.get(e);return t?.admin?.defaultColumns?t.admin.defaultColumns:this.getVisibleFields(e).slice(0,4).map(a=>a.name)}getAdminTitle(e){let t=this.collections.get(e);return t?.label||t?.admin?.description||e}getAdminLabel(e){let t=this.collections.get(e);return t?.singularLabel||t?.label||e}getAdminGroup(e){return this.collections.get(e)?.admin?.group}getStats(){let e=0;for(let t of this.collections.values())e+=t.fields.length;for(let t of this.globals.values())e+=t.fields.length;return {collections:this.collections.size,globals:this.globals.size,plugins:this.plugins.length,fields:e}}toJSON(){return {collections:this.getCollections(),globals:this.getGlobals()}}},v=null;function Qe(){return v||(v=new D),v}function et(){v=null;}function M(){return v=new D,v}var tt={aws:{type:"aws",configKey:"s3",displayName:"S3 Compatible (AWS, Backblaze, Wasabi, etc.)",configFields:[{name:"bucket",type:"text",label:"Bucket Name",required:true},{name:"region",type:"text",label:"Region",defaultValue:"us-east-1",admin:{placeholder:"us-east-1"}},{name:"accessKeyId",type:"text",label:"Access Key ID",required:true},{name:"secretAccessKey",type:"password",label:"Secret Access Key",required:true},{name:"endpoint",type:"text",label:"Endpoint URL",admin:{placeholder:"https://s3.custom.com"}},{name:"cdnUrl",type:"text",label:"CDN URL",admin:{placeholder:"https://cdn.example.com"}},{name:"prefix",type:"text",label:"Path Prefix",admin:{placeholder:"uploads"}}]},r2:{type:"r2",configKey:"r2",displayName:"Cloudflare R2",configFields:[{name:"accountId",type:"text",label:"Account ID",required:true,admin:{placeholder:"Your Cloudflare Account ID"}},{name:"accessKeyId",type:"text",label:"Access Key ID",required:true},{name:"secretAccessKey",type:"password",label:"Secret Access Key",required:true},{name:"bucket",type:"text",label:"Bucket Name",required:true},{name:"publicDevUrl",type:"text",label:"Public Dev URL ID",admin:{placeholder:"pub-xxxxxxxxxxxxxxxx",description:"Enter ONLY the ID (e.g., pub-b8d8c4cc8bcf4d868ddd95efc1b305aa). Do NOT include https:// or the full URL. Found in R2 Dashboard \u2192 Public Dev URL."}},{name:"cdnUrl",type:"text",label:"Custom CDN URL",admin:{placeholder:"https://assets.example.com (optional)"}},{name:"prefix",type:"text",label:"Path Prefix",admin:{placeholder:"uploads (optional)",description:"Optional prefix for all object keys. Do not use '/' as prefix."}}]},gcs:{type:"gcs",configKey:"gcs",displayName:"Google Cloud Storage",configFields:[{name:"bucket",type:"text",label:"Bucket Name",required:true},{name:"projectId",type:"text",label:"Project ID"},{name:"clientEmail",type:"text",label:"Client Email"},{name:"privateKey",type:"password",label:"Private Key"},{name:"cdnUrl",type:"text",label:"CDN URL"},{name:"prefix",type:"text",label:"Path Prefix"}]},digitalocean:{type:"digitalocean",configKey:"digitalocean",displayName:"DigitalOcean Spaces",configFields:[{name:"bucket",type:"text",label:"Bucket Name",required:true},{name:"region",type:"text",label:"Region",defaultValue:"nyc3"},{name:"accessKeyId",type:"text",label:"Access Key ID",required:true},{name:"secretAccessKey",type:"password",label:"Secret Access Key",required:true},{name:"cdnUrl",type:"text",label:"CDN URL"},{name:"prefix",type:"text",label:"Path Prefix"}]},backblaze:{type:"backblaze",configKey:"backblaze",displayName:"Backblaze B2",configFields:[{name:"bucket",type:"text",label:"Bucket Name",required:true},{name:"accountId",type:"text",label:"Account ID"},{name:"applicationKeyId",type:"text",label:"Application Key ID",required:true},{name:"applicationKey",type:"password",label:"Application Key",required:true},{name:"cdnUrl",type:"text",label:"CDN URL"},{name:"prefix",type:"text",label:"Path Prefix"}]},wasabi:{type:"wasabi",configKey:"wasabi",displayName:"Wasabi",configFields:[{name:"bucket",type:"text",label:"Bucket Name",required:true},{name:"region",type:"text",label:"Region",defaultValue:"us-east-1"},{name:"accessKeyId",type:"text",label:"Access Key ID",required:true},{name:"secretAccessKey",type:"password",label:"Secret Access Key",required:true},{name:"cdnUrl",type:"text",label:"CDN URL"},{name:"prefix",type:"text",label:"Path Prefix"}]}};function st(s,e){switch(s){case "r2":return e?.endpoint||`https://${e?.accountId||""}.r2.cloudflarestorage.com`;case "digitalocean":return e?.endpoint||`https://${e?.region||"nyc3"}.digitaloceanspaces.com`;case "backblaze":return e?.endpoint||"https://s3.backblazeb2.com";case "wasabi":return e?.endpoint||`https://s3.${e?.region||"us-east-1"}.wasabisys.com`;default:return e?.endpoint}}function Se(s,e){return {provider:s,bucket:e?.bucket||"",region:e?.region||"us-east-1",accessKeyId:e?.accessKeyId||e?.clientEmail||e?.applicationKeyId||"",secretAccessKey:e?.secretAccessKey||e?.privateKey||e?.applicationKey||"",endpoint:st(s,e),cdnUrl:e?.cdnUrl,prefix:e?.prefix,accountId:e?.accountId,publicDevUrl:e?.publicDevUrl}}function nt(s,e,t){let n=t[e.configKey]||{};return Se(s,n)}function at(s,e,t){let n=t?.[e.configKey]||t;return Se(s,n)}var Ee={name:"@kyro-cms/storage-s3",version:"1.0.0",description:"S3-compatible storage (AWS R2 GCS DigitalOcean Backblaze Wasabi)",init:s=>{let e=s.registry?.storageProviders;if(!e)return;let t="@kyro-cms/storage-s3";for(let n of Object.values(tt))e.register({type:n.type,displayName:n.displayName,pluginName:t,configKey:n.configKey,configFields:n.configFields,extractConfig:a=>nt(n.type,n,a),extractRawConfig:a=>at(n.type,n,a),factory:a=>a$5(a)});}};var xe={name:"@kyro-cms/storage-cloudinary",version:"1.0.0",description:"Cloudinary image and video storage",init:s=>{let e=s.registry?.storageProviders;e&&e.register({type:"cloudinary",displayName:"Cloudinary",pluginName:"@kyro-cms/storage-cloudinary",configKey:"cloudinary",configFields:[{name:"cloudName",type:"text",label:"Cloud Name",required:true},{name:"apiKey",type:"text",label:"API Key",required:true},{name:"apiSecret",type:"password",label:"API Secret",required:true},{name:"folder",type:"text",label:"Folder",admin:{placeholder:"Optional folder path"}},{name:"uploadPreset",type:"text",label:"Upload Preset (optional)",admin:{placeholder:"Leave empty for signed uploads",description:"If not set, uploads will be signed with API Secret"}}],extractConfig:t=>({cloudName:t.cloudinary?.cloudName||"",apiKey:t.cloudinary?.apiKey||"",apiSecret:t.cloudinary?.apiSecret||"",folder:t.cloudinary?.folder,uploadPreset:t.cloudinary?.uploadPreset}),extractRawConfig:t=>{let n=t?.cloudinary||t;return {cloudName:n?.cloudName||"",apiKey:n?.apiKey||"",apiSecret:n?.apiSecret||"",folder:n?.folder,uploadPreset:n?.uploadPreset}},factory:t=>b$2(t)});}};var Ne={name:"@kyro-cms/storage-ftp",version:"1.0.0",description:"FTP/SFTP storage provider",init:s=>{let e=s.registry?.storageProviders;e&&e.register({type:"ftp",displayName:"FTP",pluginName:"@kyro-cms/storage-ftp",configKey:"ftp",configFields:[{name:"host",type:"text",label:"Host",required:true,admin:{placeholder:"ftp.example.com"}},{name:"port",type:"number",label:"Port",defaultValue:21,admin:{placeholder:"21 for FTP"}},{name:"user",type:"text",label:"Username",required:true},{name:"password",type:"password",label:"Password",required:true},{name:"secure",type:"checkbox",label:"Use TLS/SSL",defaultValue:false,admin:{description:"Enable TLS/SSL for secure connections (FTP only)"}},{name:"baseUrl",type:"text",label:"Base URL",required:true,admin:{placeholder:"https://files.example.com"}},{name:"prefix",type:"text",label:"Path Prefix",admin:{placeholder:"uploads"}}],extractConfig:t=>({host:t.ftp?.host||"",port:t.ftp?.port||21,user:t.ftp?.user||"",password:t.ftp?.password||"",secure:t.ftp?.secure||false,baseUrl:t.ftp?.baseUrl||"",prefix:t.ftp?.prefix,type:"ftp"}),extractRawConfig:t=>{let n=t?.ftp||t;return {host:n?.host||"",port:n?.port||21,user:n?.user||"",password:n?.password||"",secure:n?.secure||false,baseUrl:n?.baseUrl||"",prefix:n?.prefix,type:"ftp"}},factory:t=>c$3(t)});}};var ot=[Ee,xe,Ne];function z(s,e,t){let n=e.split(".");if(n.length===0)return false;let a=n[0],i=n.slice(1).join(".");for(let o of s)if(o.name===a)return i?o.fields&&Array.isArray(o.fields)||o.type==="array"&&o.fields&&Array.isArray(o.fields)?z(o.fields,i,t):false:(Object.assign(o,t),true);return false}function rt(s,e){if(e)for(let t of s){let n=e[t.slug];if(n){let{fields:a,...i}=n;if(t.admin={...t.admin,...i},a&&t.fields&&Array.isArray(t.fields))for(let[o,r]of Object.entries(a))z(t.fields,o,r);}}}var W=class{registry;db;pubsub;webhookService;settings;wsServer;config;constructor(e){this.config=e,this.registry=M(),this.db=e.adapter,this.pubsub=new b(this.registry),this.webhookService=o(this.db);for(let t of ot)this.registry.addPlugin(t);if(e.plugins)for(let t of e.plugins)this.registry.addPlugin(t);e.collections&&e.admin?.collectionOverrides&&rt(e.collections,e.admin.collectionOverrides),e.collections&&this.registry.addCollections(e.collections),e.globals&&this.registry.addGlobals(e.globals);}async init(){await this.registry.init(this),this.registry.addGlobalPostInit(a$1);let e={slug:"plugin-settings",admin:{hidden:true},fields:[{name:"states",type:"json"}]};if(this.registry.addGlobalPostInit(e),!this.db)throw new Error("Database adapter is null \u2014 failed to load at startup. Check the server console for the exact error.");let t={slug:d,fields:[{name:"userId",type:"text",required:true},{name:"name",type:"text",required:true},{name:"key",type:"text",required:true},{name:"keyPrefix",type:"text",required:true},{name:"permissions",type:"json"},{name:"lastUsedAt",type:"date"},{name:"expiresAt",type:"date"}]},n={slug:f$1,fields:[{name:"name",type:"text",required:true},{name:"url",type:"text",required:true},{name:"events",type:"json",required:true},{name:"collections",type:"json"},{name:"status",type:"text",required:true},{name:"secret",type:"text"},{name:"headers",type:"json"},{name:"action",type:"text"},{name:"config",type:"json"},{name:"lastTriggered",type:"date"},{name:"lastError",type:"text"}]},a={slug:g$1,fields:[{name:"webhookId",type:"text",required:true},{name:"event",type:"text",required:true},{name:"payload",type:"json",required:true},{name:"attempt",type:"number",required:true},{name:"status",type:"text",required:true},{name:"responseStatus",type:"number"},{name:"responseBody",type:"text"},{name:"error",type:"text"},{name:"duration",type:"number"},{name:"deliveredAt",type:"date"},{name:"nextRetryAt",type:"date"}]},i=this.registry.getGlobals();if(this.db instanceof c&&this.db.dialect==="postgres"){let o=this.db,r=d.replace(/-/g,"_");o.schema[r]||(o.schema[r]=g);}await this.db.init([...this.registry.getCollections(),t,n,a],i),await this.loadPluginState(),this.pubsub.autoRegisterHooks();}async loadSettings(){if(this.settings)return this.settings;try{let e=await this.db.findOne({collection:"_globals_access-settings",where:{},draft:!0});e&&(this.settings={access:e});}catch{}return this.settings||{}}async loadPluginState(){let e=this.registry.storageProviders,t=e.getAllPluginNames(),n={};try{let a=await this.db.findOne({collection:"_globals_plugin-settings",where:{},draft:!0});a&&a.states&&(n=a.states);}catch{}for(let a of t)n[a]!==void 0&&e.setPluginEnabled(a,n[a]);}getREST(e){let t=typeof this.config.auth=="object"?this.config.auth:null,n=t?.secret,a=t?.checkSession!==false;return s({registry:this.registry,db:this.db,authSecret:n,authAdapter:this.config.authAdapter,checkSession:a,...e,cors:this.config.cors,webhookService:this.webhookService,settings:this.settings})}getGraphQL(e$1){let t=c$1({registry:this.registry,db:this.db,settings:this.settings});return {fetch:createYoga({schema:t,context:async({request:a})=>{let i=f$2(a),o,r;if(i&&this.db){let d=await e(i,this.db);d.user&&(o=d.user,r=g$2(d));}let c=e$1?.tenantId;return {db:this.db,registry:this.registry,user:o,req:a,tenantId:c,apiKey:r,relationLoader:new a$2({db:this.db,tenantId:c,user:o})}},graphiql:this.config.graphQL?.disablePlayground!==true,plugins:[]}).fetch,schema:t}}getTRPC(e){return {fetch:async(t,n)=>{let i$1=new URL(t.url).pathname.replace(/^\/api\/trpc\//,""),[o,...r]=i$1.split("."),c=r.join(".");if(c=c.replace(/\.(query|mutate|subscribe)$/,""),!o||!c)return new Response(JSON.stringify({error:{message:"Invalid tRPC path",code:-32600,data:{code:"BAD_REQUEST",httpStatus:400}}}),{status:400,headers:{"Content-Type":"application/json"}});let d=await a$3({db:this.db,registry:this.registry,req:t,user:e?.user,tenantId:e?.tenantId,settings:this.settings}),p=i(d)[o];if(!p)return new Response(JSON.stringify({error:{message:`Collection '${o}' not found`,code:-32601,data:{code:"NOT_FOUND",httpStatus:404}}}),{status:404,headers:{"Content-Type":"application/json"}});let m=p[c];if(typeof m!="function")return new Response(JSON.stringify({error:{message:`Procedure '${c}' not found`,code:-32601,data:{code:"NOT_FOUND",httpStatus:404}}}),{status:404,headers:{"Content-Type":"application/json"}});try{let y={};if(t.method==="POST"||t.method==="PATCH")y=await t.json().catch(()=>({}));else {let A=new URL(t.url).searchParams.get("input");if(A)try{y=JSON.parse(decodeURIComponent(A));}catch{}}let h=y?.["0"]??y,f=await m({...h,collection:o});return new Response(JSON.stringify({result:{data:f}}),{status:200,headers:{"Content-Type":"application/json"}})}catch(y){let h=y.message||"Internal error",f=h.includes("not found")?404:h.includes("denied")||h.includes("authentication required")?403:h.includes("conflict")?409:500,A=f===404?-32601:f===403?-32001:f===409?-32002:-32603;return new Response(JSON.stringify({error:{message:h,code:A,data:{code:"INTERNAL_SERVER_ERROR",httpStatus:f}}}),{status:f,headers:{"Content-Type":"application/json"}})}},router:null}}getWS(){return this.wsServer}async startWebSocket(e$1){let t=this.settings?.access?.apiAccess;if(t?.wsEnabled===false)return null;let n=async a=>{let i=await e(a,this.db);if(!i.valid)throw new Error(i.error||"Invalid API key");if(!i.user)throw new Error("API key has no associated user");return i.user};return this.wsServer=d$1({pubsub:this.pubsub,port:e$1?.port||8080,requireAuth:e$1?.requireAuth??t?.requireAuth,verifyToken:e$1?.verifyToken||n}),this.wsServer}async shutdown(){this.wsServer&&await this.wsServer.close(),await this.db.disconnect();}};function Ht(s){return new W(s)}var ct=createRequire(import.meta.url),dt="node:sqlite",{DatabaseSync:ut}=ct(dt);function x(s){let e=[];for(let t of s)if(t.type==="tabs"&&"tabs"in t)for(let n of t.tabs)e.push(...x(n.fields));else t.type==="row"&&"fields"in t?e.push(...x(t.fields)):t.type==="collapsible"&&"fields"in t?e.push(...x(t.fields)):e.push(t);return e}function ft(s,e){let t=e,n=s[t.name];if(t.type==="json"||t.type==="richtext"||t.type==="array"||t.type==="group"||t.type==="blocks"||t.type==="list"||t.type==="relationship-block")try{n=n?JSON.parse(n):null;}catch{n=null;}if(t.type==="checkbox"&&(n=!!n),t.type==="date"&&n)try{let a=new Date(n);isNaN(a.getTime())?n=null:n=a.toISOString();}catch{n=null;}if((t.type==="upload"||t.type==="image")&&n)try{let a=JSON.parse(n);Array.isArray(a)?n=a.map(i=>typeof i=="object"&&i!==null?i:{id:i}):n=typeof a=="object"?a:{id:a};}catch{n={id:n};}if(t.type==="relationship"&&n)try{let a=JSON.parse(n);Array.isArray(a),n=a;}catch{n={relationTo:Array.isArray(t.relationTo)?t.relationTo[0]:t.relationTo,value:n};}if(t.type==="list"&&n)try{let a=JSON.parse(n);n=Array.isArray(a)?a:[];}catch{n=[];}if(t.type==="relationship-block"&&n)try{let a=JSON.parse(n);n=Array.isArray(a)?a:[];}catch{n=[];}return n}function Re(s,e){return Array.isArray(s)?s.map(t=>{if(!t||typeof t!="object")return t;let n=t.data?{...t.data}:void 0;if(!n)return t;let a=e.find(i=>i.slug===t.type||i.slug===t.slug);if(!a||!Array.isArray(a.fields))return t;for(let i of a.fields){if(i.name&&(i.type==="upload"||i.type==="image")&&n[i.name]){let o=n[i.name];Array.isArray(o)?n[i.name]=o.map(r=>typeof r=="string"?{id:r}:r):typeof o=="string"&&(n[i.name]={id:o});}if(i.type==="blocks"&&i.name&&n[i.name]){let o=i.blocks||[];n[i.name]=Re(n[i.name],o);}}return {...t,data:n}}):s}function X(s,e){try{return s.prepare(`PRAGMA table_info(${e})`).all().map(n=>n.name)}catch{return []}}var J=class extends a$4{db;path;migrations=new Map;versionsTableName="kyro_versions";constructor(e){super(),this.path=e.path,e.db?this.db=e.db:this.db=null;}async connect(){if(this.db||(this.db=new ut(this.path||":memory:")),this.db&&typeof this.db.prepare=="function"&&!this.db.prepare.__wrapped){let e=this.db.prepare.bind(this.db),t=n=>{let a=e(n),i=o=>typeof o=="boolean"?o?1:0:o===void 0?null:o;return new Proxy(a,{get(o,r,c){if(r==="all")return (...u)=>o.all(...u.map(i));if(r==="get")return (...u)=>o.get(...u.map(i));if(r==="run")return (...u)=>o.run(...u.map(i));let d=Reflect.get(o,r,c);return typeof d=="function"?d.bind(o):d}})};t.__wrapped=true,this.db.prepare=t;}this.db.exec("PRAGMA journal_mode = WAL"),this.db.exec("PRAGMA foreign_keys = ON"),this.connected=true;}async disconnect(){this.db&&this.db.close(),this.connected=false;}ensureTable(e,t){let n=t||this.getTableNameFor(e.slug),a=["id TEXT PRIMARY KEY"];for(let r of x(e.fields)){if(!r.name||r.name==="id")continue;let c=this.fieldToSQL(r);c&&a.push(c);}let i=x(e.fields);i.some(r=>r.name==="createdAt")||a.push(`${this.col("createdAt")} TEXT DEFAULT (datetime('now'))`),i.some(r=>r.name==="updatedAt")||a.push(`${this.col("updatedAt")} TEXT DEFAULT (datetime('now'))`),i.some(r=>r.name==="status")||a.push("status TEXT DEFAULT 'draft'"),i.some(r=>r.name==="hasDraft")||a.push("hasDraft INTEGER DEFAULT 0"),e.tenantScoped&&a.push("tenant_id TEXT NOT NULL");let o=X(this.db,n);if(o.length===0){let r=`CREATE TABLE IF NOT EXISTS ${n} (${a.join(", ")})`;this.db.exec(r),this.db.exec(`CREATE INDEX IF NOT EXISTS idx_${n}_status ON ${n}(status)`);for(let c of x(e.fields))c.name&&c.indexed&&this.db.exec(`CREATE INDEX IF NOT EXISTS idx_${n}_${c.name} ON ${n}(${this.col(c.name)})`),c.name&&c.unique&&this.db.exec(`CREATE UNIQUE INDEX IF NOT EXISTS idx_${n}_${c.name}_unique ON ${n}(${this.col(c.name)})`);}else {let r=new Set(o);for(let c of a){let d=c.split(" ")[0].replace(/^"/,"").replace(/"$/,"");if(!r.has(d)&&d!=="id")try{d==="status"?this.db.exec(`ALTER TABLE ${n} ADD COLUMN ${this.col(d)} TEXT DEFAULT 'published'`):d==="hasDraft"?this.db.exec(`ALTER TABLE ${n} ADD COLUMN ${this.col(d)} INTEGER DEFAULT 0`):this.db.exec(`ALTER TABLE ${n} ADD COLUMN ${this.col(d)} TEXT`);}catch{}}}this.migrations.set(n,true);}ensureVersionsTable(){this.db.exec(`
|
|
4
4
|
CREATE TABLE IF NOT EXISTS ${this.versionsTableName} (
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkW7OSRADF_cjs=require('./chunk-W7OSRADF.cjs'),chunkUJNSOOYZ_cjs=require('./chunk-UJNSOOYZ.cjs'),chunkET6NN2V2_cjs=require('./chunk-ET6NN2V2.cjs'),chunkZ7CNY2UV_cjs=require('./chunk-Z7CNY2UV.cjs'),chunkGYQMNXXW_cjs=require('./chunk-GYQMNXXW.cjs'),chunkUCCFT5OO_cjs=require('./chunk-UCCFT5OO.cjs'),chunkATLSIYRH_cjs=require('./chunk-ATLSIYRH.cjs'),A=require('kyro:config');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var A__default=/*#__PURE__*/_interopDefault(A);exports.a=null;var n=null;async function g(){if(!exports.a)try{let e=A__default.default.default||A__default.default;exports.a=chunkW7OSRADF_cjs.q(e),await exports.a.init(),await exports.a.loadSettings();let a=exports.a.db,r;if(a instanceof chunkZ7CNY2UV_cjs.c){if(a.dialect==="postgres")r=new chunkGYQMNXXW_cjs.a({db:a.client});else if(a.dialect==="sqlite"){let s=process.env.KYRO_AUTH_DB_PATH||"./data/auth.db";r=new chunkET6NN2V2_cjs.a({path:s});}}else if(a instanceof chunkW7OSRADF_cjs.r){let s=process.env.KYRO_AUTH_DB_PATH||"./data/auth.db";r=new chunkET6NN2V2_cjs.a({path:s});}else a instanceof chunkUCCFT5OO_cjs.a&&(r=new chunkATLSIYRH_cjs.a({db:a.db}));r?.connect&&await r.connect(),(await chunkUJNSOOYZ_cjs.d(r))?.success,typeof exports.a.startWebSocket=="function"&&exports.a.startWebSocket().catch(s=>{console.error("[Kyro] WebSocket auto-start failed:",s);}),globalThis.__KYRO_INSTANCE__=exports.a;}catch(e){throw exports.a=null,n=null,console.error("[Kyro API] Init failed, will retry:",e),e}}async function q(){n||(n=g()),await n;}var w={graphqlEnabled:false,trpcEnabled:false,wsEnabled:false,requireAuth:false};async function b(e){try{return (await exports.a.db.findOne({collection:"_globals_access-settings",where:{},draft:!0}))?.apiAccess?.[e]??w[e]??!0}catch{return true}}var v=async e=>{if(!exports.a){n||(n=g());try{await Promise.race([n,new Promise((l,o)=>setTimeout(()=>o(new Error("Initialization timeout")),3e4))]);}catch{return new Response(JSON.stringify({error:"Service Unavailable",message:"Kyro CMS is still starting up. Please try again in a moment."}),{status:503,headers:{"Content-Type":"application/json","Retry-After":"5"}})}}let r=new URL(e.request.url).pathname,i=__KYRO_API_PATH__;if(r===`${i}/graphql`&&typeof exports.a.getGraphQL=="function"){if(!await b("graphqlEnabled"))return new Response(JSON.stringify({error:"GraphQL is disabled"}),{status:503,headers:{"Content-Type":"application/json"}});let o=await exports.a.getGraphQL().fetch(e.request,e.locals);return new Response(o.body,o)}if(r.startsWith(`${i}/trpc/`)&&typeof exports.a.getTRPC=="function"){if(!await b("trpcEnabled"))return new Response(JSON.stringify({error:"tRPC is disabled"}),{status:503,headers:{"Content-Type":"application/json"}});let o=await exports.a.getTRPC().fetch(e.request,e.locals);return new Response(o.body,o)}return exports.a.getREST().fetch(e.request,e.locals)};exports.b=q;exports.c=v;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a,h as h$1}from'./chunk-HLSB2MCK.js';import {a as a$1}from'./chunk-KDNYHLD2.js';import {createHmac,randomBytes,randomUUID}from'crypto';var S={COLLECTION_CREATE:"collection.create",COLLECTION_UPDATE:"collection.update",COLLECTION_DELETE:"collection.delete",MEDIA_UPLOAD:"media.upload",MEDIA_DELETE:"media.delete",AUTH_LOGIN:"auth.login",AUTH_REGISTER:"auth.register",AUTH_LOGOUT:"auth.logout",ORDER_CREATED:"order.created",ORDER_PAID:"order.paid",ORDER_SHIPPED:"order.shipped",ORDER_DELIVERED:"order.delivered"},j=Object.values(S);var h="_webhooks",k="_webhook_deliveries";async function x(r,o,s,e={}){let t=e.timeout||3e4,a=Date.now(),c=new AbortController,i=setTimeout(()=>c.abort(),t);try{let n=await fetch(r,{method:"POST",headers:o,body:s,signal:c.signal});clearTimeout(i);let l=Date.now()-a,u;try{u=(await n.text()).slice(0,1e3);}catch{}let d={success:n.ok,status:n.status,statusText:n.statusText,body:u,duration:l};return d.success&&e.onSuccess?e.onSuccess(d):!d.success&&e.onFailure&&e.onFailure(`HTTP ${n.status}: ${n.statusText}`),d}catch(n){clearTimeout(i);let l=Date.now()-a,u=n.name==="AbortError"?`Request timed out after ${t}ms`:n.message||"Unknown error";return e.onFailure&&e.onFailure(u),{success:false,status:0,duration:l,error:u}}}async function I(r,o,s={}){let e=JSON.stringify(o),t={"Content-Type":"application/json","User-Agent":"Kyro-CMS-Webhook/1.0","X-Webhook-Event":o.event,"X-Webhook-Delivery":o.id,"X-Webhook-Timestamp":o.timestamp,...r.headers||{}};return r.secret&&(t["X-Webhook-Signature"]=O(e,r.secret)),x(r.url,t,e,s)}async function H(r,o,s={}){let e=r.config||{},t=process.env.GITHUB_TOKEN;if(!t)return {success:false,status:0,duration:0,error:"GITHUB_TOKEN environment variable is not set"};if(!e.githubOwner||!e.githubRepo)return {success:false,status:0,duration:0,error:"GitHub owner and repo are required"};let a=e.githubBranch||"main",c=Date.now(),i=async(n,l,u)=>{let d=await fetch(n,{method:l,headers:{"Content-Type":"application/json",Accept:"application/vnd.github+json",Authorization:`Bearer ${t}`,"X-GitHub-Api-Version":"2022-11-28","User-Agent":"Kyro-CMS-Webhook/1.0"},body:u?JSON.stringify(u):void 0});if(!d.ok){let y=await d.text();throw new Error(`GitHub API HTTP ${d.status}: ${y}`)}return d.json()};try{let n=`https://api.github.com/repos/${e.githubOwner}/${e.githubRepo}/git/refs/heads/${a}`,u=(await i(n,"GET")).object.sha,d=`https://api.github.com/repos/${e.githubOwner}/${e.githubRepo}/git/commits/${u}`,g=(await i(d,"GET")).tree.sha,f=`https://api.github.com/repos/${e.githubOwner}/${e.githubRepo}/git/commits`,p=(await i(f,"POST",{message:`Content updated via Kyro CMS (${o.event})`,tree:g,parents:[u]})).sha;return await i(n,"PATCH",{sha:p,force:!1}),{success:!0,status:201,duration:Date.now()-c,body:`Successfully pushed empty commit ${p} to branch ${a}`}}catch(n){return {success:false,status:0,duration:Date.now()-c,error:n.message||"Failed to push empty commit to GitHub"}}}var B={generic:I,"github-push":H};function R(r){return B[r||"generic"]||B.generic}function O(r,o){return `sha256=${createHmac("sha256",o).update(r).digest("hex")}`}function E(){return randomBytes(32).toString("hex")}async function _(r,o,s={}){return R(r.action)(r,o,s)}async function C(r,o,s,e={}){let t=e.maxRetries??5,a=e.retryDelay??1e3,c=null;for(let i=0;i<=t;i++){if(i>0){let n=Math.min(a*Math.pow(2,i-1),3e4);e.onRetry&&e.onRetry(i,`Retrying in ${n}ms...`),await N(n);}if(e.onRetry&&i>0&&e.onRetry(i,`Attempt ${i+1}/${t+1}`),c=await _(r,o,{...e,onRetry:void 0,onSuccess:void 0,onFailure:void 0}),c.success)return c;if(!(c.error?.includes("timed out")&&i<t)&&c.status>=400&&c.status<500)return c}return c||{success:false,status:0,duration:0,error:"All delivery attempts failed"}}function P(r,o,s,e,t,a){return {id:r,webhookId:o,event:s,payload:e,attempt:t,status:a.success?"success":"failed",responseStatus:a.status||void 0,responseBody:a.body,duration:a.duration,error:a.error,createdAt:new Date().toISOString(),deliveredAt:a.success?new Date().toISOString():void 0}}function N(r){return new Promise(o=>setTimeout(o,r))}function M(){return {id:`test_${Date.now()}`,event:"collection.create",timestamp:new Date().toISOString(),collection:"test",operation:"create",data:{message:"This is a test webhook delivery"},user:{id:"system",email:"system@kyro.dev",role:"super_admin"}}}function L(r){let o=new Set,s=[];for(let e of r){let t=e==="create"||e==="update"||e==="delete"?`collection.${e}`:e;o.has(t)||(o.add(t),s.push(t));}return s}var w=class{db;constructor(o){this.db=o;}async getWebhooks(o){let e=(await this.db.find({collection:h,where:o?.status?{status:{equals:o.status}}:{},limit:100,page:1,draft:true})).docs;return o?.event?e.filter(t=>t.events.includes(o.event)):e}async getWebhookById(o){return this.db.findByID({collection:h,id:o,draft:true})}async createWebhook(o){let s=new Date().toISOString(),e=o.secret||E(),t={id:randomUUID(),name:o.name,url:o.url,events:L(o.events),collections:o.collections||[],status:o.status||"active",secret:e,headers:o.headers||{},action:o.action||"generic",config:o.config||{},createdAt:s,updatedAt:s};return await this.db.create({collection:h,data:t}),t}async updateWebhook(o,s){let e=await this.getWebhookById(o);if(!e)return null;let t={...e,...s,events:s.events?L(s.events):e.events,collections:s.collections!==void 0?s.collections:e.collections,action:s.action!==void 0?s.action:e.action,config:s.config!==void 0?{...e.config,...s.config}:e.config,updatedAt:new Date().toISOString()};return s.secret===""&&"secret"in s&&delete t.secret,await this.db.update({collection:h,id:o,data:t}),t}async deleteWebhook(o){await this.db.delete({collection:h,id:o});}async trigger(o,s){let e=await this.getWebhooks({status:"active",event:o}),t=s.collection,a=e.filter(n=>!n.collections||n.collections.length===0||!t?true:n.collections.includes(t));if(a.length===0)return [];let c={id:randomUUID(),event:o,timestamp:new Date().toISOString(),...s},i=[];for(let n of a){let l=await this.triggerWebhook(n,c);i.push(l);}return i}async triggerWebhook(o,s){let e=randomUUID();try{let t=await C(o,s,e,{maxRetries:5,retryDelay:1e3}),a=P(e,o.id,o.events[0],s,1,t);try{await this.db.create({collection:k,data:a});}catch{console.warn("[WebhookService] Failed to save delivery record:",e);}return t.success?await this.updateWebhook(o.id,{lastTriggered:new Date().toISOString(),lastError:null}).catch(()=>{}):await this.updateWebhook(o.id,{lastError:t.error||`HTTP ${t.status}`}).catch(()=>{}),{deliveryId:e,webhookId:o.id,event:o.events[0],status:t.success?"success":"failed",responseStatus:t.status,duration:t.duration,error:t.error}}catch(t){return {deliveryId:e,webhookId:o.id,event:o.events[0],status:"failed",error:t.message}}}async testWebhook(o){let s=await this.getWebhookById(o);if(!s)return null;let e={id:randomUUID(),event:s.events[0]||"collection.create",timestamp:new Date().toISOString(),collection:"test",operation:"create",data:{message:"This is a test webhook delivery from Kyro CMS"},user:{id:"system",email:"system@kyro.dev",role:"super_admin"}};return this.triggerWebhook(s,e)}async getDeliveryHistory(o,s=50){return (await this.db.find({collection:k,where:{webhookId:{equals:o}},sort:"-createdAt",limit:s,page:1})).docs}async retryDelivery(o){let s=await this.db.findByID({collection:k,id:o});if(!s)return null;let e=await this.getWebhookById(s.webhookId);return e?this.triggerWebhook(e,s.payload):null}};function G(r){return new w(r)}function q(r){if(!r)return [];if(typeof r=="string")return [{id:r}];if(Array.isArray(r))return r.map(o=>typeof o=="object"?{id:o.value??o.id??o,relationTo:o.relationTo}:{id:o});if(typeof r=="object"){let o=r.value??r.id??r;if(typeof o=="string")return [{id:o,relationTo:r.relationTo}];if(Array.isArray(o))return o.map(s=>({id:s,relationTo:r.relationTo}))}return []}function W(r,o,s){if(!(!r||typeof r!="object")){for(let e of o)if(!(!e.name&&e.type!=="row"&&e.type!=="collapsible"&&e.type!=="tabs")){if(e.type==="relationship"||e.type==="upload"){let t=r[e.name];if(!t)continue;let a=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],c=q(t);for(let i of c){if(!i.id)continue;let n=i.relationTo?[i.relationTo]:a;for(let l of n)l!=="*"&&(s.has(l)||s.set(l,new Set),s.get(l).add(i.id));}}else if(e.type==="group"||e.type==="collapsible"||e.type==="row"){let t=e.name?r[e.name]:r;W(t,e.fields||[],s);}else if(e.type==="tabs"&&e.tabs){let t=e.name?r[e.name]:r;for(let a of e.tabs)W(t,a.fields||[],s);}else if(e.type==="array"&&e.name&&Array.isArray(r[e.name]))for(let t of r[e.name])W(t,e.fields||[],s);else if(e.type==="blocks"&&e.name&&Array.isArray(r[e.name]))for(let t of r[e.name]){if(!t||typeof t!="object")continue;let a=t.type||t.blockType;if(!a)continue;let c=e.blocks?.find(i=>i.slug===a);if(c&&Array.isArray(c.fields)){let i=t.data&&typeof t.data=="object"?t.data:t;W(i,c.fields,s);}}}}}function v(r,o,s){if(!(!r||typeof r!="object")){for(let e of o)if(!(!e.name&&e.type!=="row"&&e.type!=="collapsible"&&e.type!=="tabs")){if(e.type==="relationship"||e.type==="upload"){let t=r[e.name];if(!t)continue;let a=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],c=n=>{r[e.name]=n;},i=(n,l)=>{let u=l?[l]:a;for(let d of u){let y=s.get(d);if(y&&y.has(n))return y.get(n)}return null};if(typeof t=="string"){let n=i(t);c(n||{id:t});}else if(Array.isArray(t))c(t.map(n=>{let l=typeof n=="object"?n.value??n.id:n,u=typeof n=="object"?n.relationTo:void 0,d=i(l,u);return d||{id:l}}));else if(typeof t=="object"){let n=t.value??t.id,l=t.relationTo,u=i(n,l);c(u||{id:n});}}else if(e.type==="group"||e.type==="collapsible"||e.type==="row"){let t=e.name?r[e.name]:r;v(t,e.fields||[],s);}else if(e.type==="tabs"&&e.tabs){let t=e.name?r[e.name]:r;for(let a of e.tabs)v(t,a.fields||[],s);}else if(e.type==="array"&&e.name&&Array.isArray(r[e.name]))for(let t of r[e.name])v(t,e.fields||[],s);else if(e.type==="blocks"&&e.name&&Array.isArray(r[e.name]))for(let t of r[e.name]){if(!t||typeof t!="object")continue;let a=t.type||t.blockType;if(!a)continue;let c=e.blocks?.find(i=>i.slug===a);if(c&&Array.isArray(c.fields)){let i=t.data&&typeof t.data=="object"?t.data:t;v(i,c.fields,s);}}}}}async function V(r,o,s,e,t=1,a=0){if(!r||r.length===0||t>a)return;let c=new Map;for(let l of r)W(l,o,c);if(c.size===0)return;let i=new Map,n=new Map;for(let[l,u]of c.entries()){if(u.size===0||!e.getCollection(l))continue;let y=new Map,g=Array.from(u),f=[];for(let m of g)try{let p=await s.findByID({collection:l,id:m,draft:!0});p&&(y.set(m,p),f.push(p));}catch{}i.set(l,y),f.length>0&&n.set(l,f);}if(t<a)for(let[l,u]of n.entries()){let d=e.getCollection(l);d&&await V(u,d.fields,s,e,t+1,a);}for(let l of r)v(l,o,i);}function $(r){return r==="read"?"read":r==="create"?"create":r==="update"?"update":"delete"}function F(r,o){return {none:false,read:r==="read",create:r==="read"||r==="create",update:r==="read"||r==="create"||r==="update",delete:r==="read"||r==="create"||r==="update"||r==="delete",admin:true}[o]||false}async function We(r,o,s,e={}){let{user:t,req:a$2,tenantId:c,apiKey:i}=s,{enablePublicAccess:n=true,defaultAccess:l="none"}=e,u=r.access?.[o];if(u){let y=await a(u,{req:a$2,user:t,tenantId:c});return y===false?{allowed:false,error:"Access denied",status:403}:typeof y=="object"?{allowed:true,extraWhere:y}:{allowed:true}}if(i?.permissions?.length>0){let y=r.slug,g=$(o),f=`${y}:${g}`;return !h$1(i.permissions,f)&&!h$1(i.permissions,`${y}:admin`)?{allowed:false,error:"Access denied: insufficient permissions",status:403}:{allowed:true}}if(t){let y=r.slug,g=$(o),f=`${y}:${g}`,m=a$1({id:t.id,email:t.email,role:t.role},f),p=a$1({id:t.id,email:t.email,role:t.role},`${y}:admin`);return m||p?{allowed:true}:{allowed:false,error:"Access denied: missing RBAC permission",status:403}}let d=F(o,l);return n&&d?{allowed:true}:{allowed:false,error:"Authentication required",status:401}}async function ve(r,o,s,e={}){let{user:t,req:a$2,tenantId:c}=s,{enablePublicAccess:i=true}=e,n=r.access?.[o];if(n)return await a(n,{req:a$2,user:t,tenantId:c})===false?{allowed:false,error:"Access denied",status:403}:{allowed:true};if(t){let l=`globals:${o}`,u=a$1({id:t.id,email:t.email,role:t.role},l),d=a$1({id:t.id,email:t.email,role:t.role},"globals:admin");return u||d?{allowed:true}:{allowed:false,error:"Access denied: missing RBAC permission",status:403}}return i?{allowed:true}:{allowed:false,error:"Authentication required",status:401}}
|
|
2
|
+
export{V as a,We as b,ve as c,S as d,j as e,h as f,k as g,O as h,E as i,_ as j,C as k,P as l,M as m,w as n,G as o};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {d,o,a,b,c}from'./chunk-
|
|
1
|
+
import {d,o,a,b,c}from'./chunk-I67R6MR5.js';import {f,e,g}from'./chunk-HLSB2MCK.js';async function T(e$1){let a=o(e$1.db),t={db:e$1.db,registry:e$1.registry,req:e$1.req,user:e$1.user,tenantId:e$1.tenantId,webhookService:a,settings:e$1.settings},n=f(e$1.req);if(n){let r=await e(n,e$1.db,async o=>{try{return await e$1.db.findByID({collection:"users",id:o})||null}catch{return null}});r.valid&&(t.user=r.user||e$1.user,t.tenantId=r.tenantId||e$1.tenantId,t.apiKey=g(r));}return t}var W={_media:{create:d.MEDIA_UPLOAD,update:d.MEDIA_UPLOAD,delete:d.MEDIA_DELETE}};function A(e,a){let t=W[e];return t?t[a]:`collection.${a}`}async function C(e,a,t){if(e.webhookService)try{await e.webhookService.trigger(a,{collection:t.collection,operation:t.operation,data:t.data,previousData:t.previousData,user:e.user?{id:e.user.id,email:e.user.email,role:e.user.role}:void 0,tenantId:e.tenantId});}catch(n){console.error(`[Webhook] Failed to trigger ${a}:`,n);}}function m(e,a){if(!(!e||typeof e!="object"))for(let t of a){if(!t.name||!(t.name in e))continue;if(e[t.name]===""&&(t.type==="text"||t.type==="textarea"||t.type==="code"||t.type==="markdown"||t.type==="email"||t.type==="password"||t.type==="color"||(e[t.name]=null)),t.type==="tabs"&&t.name&&Array.isArray(t.tabs)&&e[t.name]&&typeof e[t.name]=="object")for(let r of t.tabs)Array.isArray(r.fields)&&m(e[t.name],r.fields);else if((t.type==="group"||t.type==="collapsible")&&t.name&&Array.isArray(t.fields)&&e[t.name]&&typeof e[t.name]=="object")m(e[t.name],t.fields);else if(t.type==="array"&&t.name&&Array.isArray(t.fields)&&Array.isArray(e[t.name]))for(let r of e[t.name])r&&typeof r=="object"&&m(r,t.fields);else if(t.type==="blocks"&&t.name&&Array.isArray(t.blocks)&&Array.isArray(e[t.name]))for(let r of e[t.name]){if(!r||typeof r!="object")continue;let o=r.type||r.blockType;if(!o)continue;let s=t.blocks.find(i=>i.slug===o);if(!s||!Array.isArray(s.fields))continue;let c=r.data&&typeof r.data=="object"?r.data:r;m(c,s.fields);}}}async function p(e,a,t){let n=await b(e,a,{user:t.user,req:t.req,tenantId:t.tenantId,apiKey:t.apiKey});if(!n.allowed)throw new Error(n.error||"Access denied");t.tenantId&&t.db.setTenantContext({tenantId:t.tenantId,userId:t.user?.id??"",role:t.user?.role,isSuperAdmin:t.user?.role==="super_admin"});}function D(e){return async a$1=>{let{collection:t,where:n,sort:r,limit:o,page:s,depth:c,select:i,draft:d}=a$1,u=e.registry.getCollection(t);if(await p(u,"read",e),u.hooks?.beforeRead)for(let f of u.hooks.beforeRead)await f({collection:t,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read",where:n});let l=d??!!e.user,g=await e.db.find({collection:t,where:n||{},sort:r,limit:o||10,page:s||1,depth:c||0,tenantId:e.tenantId,select:i,draft:l});if(u.hooks?.afterRead)for(let f of g.docs)for(let w of u.hooks.afterRead)await w({collection:t,doc:f,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read"});return await a(g.docs,u.fields,e.db,e.registry,1,c||0),g}}function R(e){return async a$1=>{let{collection:t,id:n,depth:r,select:o,draft:s}=a$1,c=e.registry.getCollection(t);await p(c,"read",e);let i=s??!!e.user,d=await e.db.findByID({collection:t,id:n,depth:r||0,tenantId:e.tenantId,select:o,draft:i});if(!d)throw new Error(`Document not found: ${t}/${n}`);if(c.hooks?.afterRead)for(let u of c.hooks.afterRead)await u({collection:t,doc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read",id:n});return await a([d],c.fields,e.db,e.registry,1,r||0),d}}function q(e){return async a=>{let{collection:t,data:n,depth:r,select:o}=a,s=e.registry.getCollection(t);await p(s,"create",e);let i=e.registry.getCreateZodSchema(t).parse(n);if(s.tenantScoped&&e.tenantId&&(i.tenantId=e.tenantId),s.hooks?.beforeValidate)for(let u of s.hooks.beforeValidate){let l=await u({collection:t,data:i,req:e.req,user:e.user,tenantId:e.tenantId,operation:"create"});l&&Object.assign(i,l);}if(s.hooks?.beforeChange)for(let u of s.hooks.beforeChange){let l=await u({collection:t,data:i,req:e.req,user:e.user,tenantId:e.tenantId,operation:"create"});l&&Object.assign(i,l);}let d=await e.db.create({collection:t,data:i,depth:r||0,tenantId:e.tenantId,select:o});if(s.hooks?.afterChange)for(let u of s.hooks.afterChange)await u({collection:t,doc:d,data:i,req:e.req,user:e.user,tenantId:e.tenantId,operation:"create"});return await C(e,A(t,"create"),{collection:t,data:d,operation:"create"}),{doc:d}}}function P(e){return async a=>{let{collection:t,id:n,data:r,depth:o,select:s,baseUpdatedAt:c}=a,i=e.registry.getCollection(t);await p(i,"update",e);let d=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true});if(!d)throw new Error(`Document not found: ${t}/${n}`);if(c&&d.updatedAt&&c!==d.updatedAt)throw new Error(`Revision conflict: document has changed since ${c}. Current updatedAt: ${d.updatedAt}`);m(r,i.fields);let l=e.registry.getUpdateZodSchema(t).parse(r);if(i.tenantScoped&&e.tenantId&&(l.tenantId=e.tenantId),i.hooks?.beforeValidate)for(let b of i.hooks.beforeValidate){let h=await b({collection:t,data:l,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});h&&Object.assign(l,h);}if(i.hooks?.beforeChange)for(let b of i.hooks.beforeChange){let h=await b({collection:t,data:l,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});h&&Object.assign(l,h);}let g=e.req&&typeof e.req.headers?.get=="function"&&e.req.headers.get("x-draft")==="true"||a.draft===true,f=i.versions?.drafts===true,w=e.req?.query?.autosave==="true"||e.req?.url?.includes("autosave=true")||a.autosave===true,y;if(f&&g?(await e.db.createVersion({collection:t,documentId:n,data:l,status:"draft",autosave:w,createdBy:e.user?.id,tenantId:e.tenantId}),y=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true})):f?(y=await e.db.update({collection:t,id:n,data:{...l,status:"published"},depth:o||0,tenantId:e.tenantId,select:s}),await e.db.createVersion({collection:t,documentId:n,data:l,status:"published",createdBy:e.user?.id,tenantId:e.tenantId})):y=await e.db.update({collection:t,id:n,data:l,depth:o||0,tenantId:e.tenantId,select:s}),i.hooks?.afterChange)for(let b of i.hooks.afterChange)await b({collection:t,doc:y,data:l,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});return await C(e,A(t,"update"),{collection:t,data:y,previousData:d,operation:"update"}),{doc:y}}}function v(e){return async a=>{let{collection:t,id:n}=a,r=e.registry.getCollection(t);await p(r,"delete",e);let o=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true});if(!o)throw new Error(`Document not found: ${t}/${n}`);if(r.hooks?.beforeDelete)for(let c of r.hooks.beforeDelete)await c({collection:t,doc:o,req:e.req,user:e.user,tenantId:e.tenantId,operation:"delete",id:n});let s=await e.db.delete({collection:t,id:n,tenantId:e.tenantId});if(r.hooks?.afterDelete)for(let c of r.hooks.afterDelete)await c({collection:t,doc:s,req:e.req,user:e.user,tenantId:e.tenantId,operation:"delete",id:n});return await C(e,A(t,"delete"),{collection:t,data:s,previousData:o,operation:"delete"}),{doc:s,message:"Deleted successfully"}}}function K(e){return async a=>{let{collection:t,where:n}=a,r=e.registry.getCollection(t);return await p(r,"read",e),{totalDocs:await e.db.count({collection:t,where:n||{},tenantId:e.tenantId})}}}async function U(e,a,t){let n=await c(e,a,{user:t.user,req:t.req,tenantId:t.tenantId});if(!n.allowed)throw new Error(n.error||"Access denied");t.tenantId&&t.db.setTenantContext({tenantId:t.tenantId,userId:t.user?.id??"",role:t.user?.role,isSuperAdmin:t.user?.role==="super_admin"});}function $(e){let a={},t=e.registry.getCollections();for(let r of t){let o=r.slug;a[o]={find:D(e),findByID:R(e),create:q(e),update:P(e),delete:v(e),count:K(e)};}let n=e.registry.getGlobals();for(let r of n){let o=r.slug;a[`_globals_${o}`]={get:async()=>(await U(r,"read",e),await e.db.findOne({collection:`_globals_${o}`,where:{},tenantId:e.tenantId})),update:async s=>{await U(r,"update",e);let i=e.registry.getZodSchema(o).parse(s.data),d=await e.db.findOne({collection:`_globals_${o}`,where:{},tenantId:e.tenantId,draft:true}),u;return d?u=await e.db.update({collection:`_globals_${o}`,id:d.id,data:i,tenantId:e.tenantId}):u=await e.db.create({collection:`_globals_${o}`,data:{...i,id:o},tenantId:e.tenantId}),u}};}return a}function O(e){if(e.settings?.access?.apiAccess?.trpcEnabled===false)throw new Error("tRPC API is disabled");return $(e)}export{T as a,D as b,R as c,q as d,P as e,v as f,K as g,$ as h,O as i};
|