@kyro-cms/core 0.9.7 → 0.9.9
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-BKszZlG0.d.cts → WebhookService-Dj8pJ3sp.d.cts} +1 -1
- package/dist/{WebhookService-Ccf1j-IN.d.ts → WebhookService-DpRB940h.d.ts} +1 -1
- package/dist/api-handler-graphql.cjs +18 -13
- package/dist/api-handler-graphql.cjs.map +1 -1
- package/dist/api-handler-graphql.js +14 -9
- package/dist/api-handler-graphql.js.map +1 -1
- package/dist/api-handler-trpc.cjs +9 -9
- package/dist/api-handler-trpc.js +7 -7
- package/dist/api-handler.cjs +10 -10
- package/dist/api-handler.js +7 -7
- package/dist/{base-CIuXkrH4.d.cts → base-BjyoF6da.d.cts} +2 -2
- package/dist/{base-fFo4lqER.d.ts → base-C2YR8lWt.d.ts} +2 -2
- package/dist/{chunk-NZEUU7QB.js → chunk-3AKCVYDB.js} +4 -109
- package/dist/chunk-3AKCVYDB.js.map +1 -0
- package/dist/{chunk-FKKQUMXR.cjs → chunk-4OCMVGEY.cjs} +4 -110
- package/dist/chunk-4OCMVGEY.cjs.map +1 -0
- package/dist/{chunk-VLK5SJRI.js → chunk-5RFGYEQ3.js} +133 -46
- package/dist/chunk-5RFGYEQ3.js.map +1 -0
- package/dist/chunk-5RPRLTTN.js +861 -0
- package/dist/chunk-5RPRLTTN.js.map +1 -0
- package/dist/{chunk-AX2TZRQJ.js → chunk-BVUDFKKS.js} +16 -3
- package/dist/chunk-BVUDFKKS.js.map +1 -0
- package/dist/{chunk-DRVOUQMT.cjs → chunk-E4JZ73FY.cjs} +54 -79
- package/dist/chunk-E4JZ73FY.cjs.map +1 -0
- package/dist/{chunk-E5UJBLQ7.js → chunk-FIAMXNTH.js} +2 -2
- package/dist/chunk-FIAMXNTH.js.map +1 -0
- package/dist/{chunk-QVJNSAQL.cjs → chunk-IEIHABVR.cjs} +152 -65
- package/dist/chunk-IEIHABVR.cjs.map +1 -0
- package/dist/{chunk-QFLB4EIJ.cjs → chunk-LNTFRAHF.cjs} +118 -9
- package/dist/chunk-LNTFRAHF.cjs.map +1 -0
- package/dist/chunk-N4GN6Q3V.cjs +869 -0
- package/dist/chunk-N4GN6Q3V.cjs.map +1 -0
- package/dist/{chunk-FSKONGCX.cjs → chunk-OJ2AM75W.cjs} +2 -2
- package/dist/chunk-OJ2AM75W.cjs.map +1 -0
- package/dist/{chunk-QX3WNQ7V.js → chunk-OX6GOIPH.js} +4 -4
- package/dist/{chunk-QX3WNQ7V.js.map → chunk-OX6GOIPH.js.map} +1 -1
- package/dist/{chunk-OZ3CCTTA.cjs → chunk-OXYSOU6Z.cjs} +18 -5
- package/dist/chunk-OXYSOU6Z.cjs.map +1 -0
- package/dist/{chunk-CMXVTUYV.js → chunk-OYCICW4B.js} +38 -63
- package/dist/chunk-OYCICW4B.js.map +1 -0
- package/dist/{chunk-HVCUIII2.cjs → chunk-TQG7G7YI.cjs} +13 -13
- package/dist/{chunk-HVCUIII2.cjs.map → chunk-TQG7G7YI.cjs.map} +1 -1
- package/dist/{chunk-3UK5XBVJ.js → chunk-WDTTHKDS.js} +117 -10
- package/dist/chunk-WDTTHKDS.js.map +1 -0
- package/dist/cli/index.cjs +148 -14
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +148 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/client.cjs +3 -3
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/drizzle/index.d.cts +3 -3
- package/dist/drizzle/index.d.ts +3 -3
- package/dist/fields/index.cjs +21 -21
- package/dist/fields/index.d.cts +1 -1
- package/dist/fields/index.d.ts +1 -1
- package/dist/fields/index.js +1 -1
- package/dist/graphql/index.cjs +13 -5
- package/dist/graphql/index.d.cts +37 -7
- package/dist/graphql/index.d.ts +37 -7
- package/dist/graphql/index.js +2 -2
- package/dist/{index-BKta3cBH.d.cts → index-DHbywDs-.d.cts} +2 -2
- package/dist/{index-ClOqnkTO.d.ts → index-jLs0zlft.d.ts} +2 -2
- package/dist/index.cjs +90 -90
- package/dist/index.d.cts +15 -14
- package/dist/index.d.ts +15 -14
- package/dist/index.js +8 -8
- package/dist/mongodb/index.d.cts +3 -3
- package/dist/mongodb/index.d.ts +3 -3
- package/dist/rest/index.cjs +5 -5
- package/dist/rest/index.d.cts +4 -4
- package/dist/rest/index.d.ts +4 -4
- package/dist/rest/index.js +3 -3
- package/dist/templates/index.d.cts +2 -2
- package/dist/templates/index.d.ts +2 -2
- package/dist/trpc/index.cjs +12 -12
- package/dist/trpc/index.d.cts +3 -3
- package/dist/trpc/index.d.ts +3 -3
- package/dist/trpc/index.js +3 -3
- package/dist/{types-Dgzlftb7.d.ts → types-BzH3_rtP.d.ts} +7 -7
- package/dist/{types-Ds0tCA3L.d.cts → types-CY_iNunL.d.cts} +7 -7
- package/dist/{types-DeSApf9T.d.ts → types-C_rVxU2T.d.cts} +4 -4
- package/dist/{types-DeSApf9T.d.cts → types-C_rVxU2T.d.ts} +4 -4
- package/package.json +2 -1
- package/dist/chunk-3UK5XBVJ.js.map +0 -1
- package/dist/chunk-AX2TZRQJ.js.map +0 -1
- package/dist/chunk-CMXVTUYV.js.map +0 -1
- package/dist/chunk-DRVOUQMT.cjs.map +0 -1
- package/dist/chunk-E5UJBLQ7.js.map +0 -1
- package/dist/chunk-FKKQUMXR.cjs.map +0 -1
- package/dist/chunk-FSKONGCX.cjs.map +0 -1
- package/dist/chunk-NZEUU7QB.js.map +0 -1
- package/dist/chunk-OZ3CCTTA.cjs.map +0 -1
- package/dist/chunk-PONTBXR5.js +0 -842
- package/dist/chunk-PONTBXR5.js.map +0 -1
- package/dist/chunk-QFLB4EIJ.cjs.map +0 -1
- package/dist/chunk-QVJNSAQL.cjs.map +0 -1
- package/dist/chunk-RRKCIAPU.cjs +0 -848
- package/dist/chunk-RRKCIAPU.cjs.map +0 -1
- package/dist/chunk-VLK5SJRI.js.map +0 -1
|
@@ -2,15 +2,15 @@ import { PasswordPolicy, ConfigService, EmailTransport } from './chunk-6UNONDW7.
|
|
|
2
2
|
import { usersCollection } from './chunk-XEB7PH2E.js';
|
|
3
3
|
import { SQLiteAuthAdapter } from './chunk-Q72BOAPK.js';
|
|
4
4
|
import { createAuditContext } from './chunk-P2YW545G.js';
|
|
5
|
-
import { WEBHOOK_EVENTS } from './chunk-
|
|
6
|
-
import { API_KEY_COLLECTION, generateApiKey, generateApiKeyPrefix,
|
|
5
|
+
import { WEBHOOK_EVENTS, checkCollectionAccess, checkGlobalAccess } from './chunk-WDTTHKDS.js';
|
|
6
|
+
import { API_KEY_COLLECTION, generateApiKey, generateApiKeyPrefix, extractApiKeyFromRequest, validateApiKey, createApiKeyContext } from './chunk-3AKCVYDB.js';
|
|
7
7
|
import { genId, DrizzleAdapter } from './chunk-V7KZQIZ6.js';
|
|
8
8
|
import { PostgresAuthAdapter } from './chunk-CJX74IYK.js';
|
|
9
9
|
import { MongoDBAdapter } from './chunk-PQ72Z6WC.js';
|
|
10
10
|
import { MongoDBAuthAdapter } from './chunk-7OGPN7MP.js';
|
|
11
11
|
import { hasPermission } from './chunk-L4EZKIEX.js';
|
|
12
12
|
import { __esm, __export, __toCommonJS } from './chunk-4CV4JOE5.js';
|
|
13
|
-
import crypto, { randomBytes, createHash } from 'crypto';
|
|
13
|
+
import crypto, { randomBytes, createHash, createHmac } from 'crypto';
|
|
14
14
|
import { createStorage } from 'unstorage';
|
|
15
15
|
import fsDriver from 'unstorage/drivers/fs';
|
|
16
16
|
import { Hono } from 'hono';
|
|
@@ -1671,22 +1671,11 @@ function createLocalStorage(config) {
|
|
|
1671
1671
|
}
|
|
1672
1672
|
};
|
|
1673
1673
|
}
|
|
1674
|
-
|
|
1675
|
-
// src/storage/imgix.ts
|
|
1676
1674
|
function createImgixStorage(config) {
|
|
1677
1675
|
const signUrl = (path3, params) => {
|
|
1678
1676
|
if (!config.signKey) return path3;
|
|
1679
|
-
const
|
|
1680
|
-
|
|
1681
|
-
const data = signer.encode(path3 + params.toString());
|
|
1682
|
-
let hash = 0;
|
|
1683
|
-
const combined = new Uint8Array(key.length + data.length);
|
|
1684
|
-
combined.set(key);
|
|
1685
|
-
combined.set(data, key.length);
|
|
1686
|
-
for (let i = 0; i < combined.length; i++) {
|
|
1687
|
-
hash = (hash << 5) - hash + combined[i] | 0;
|
|
1688
|
-
}
|
|
1689
|
-
params.set("s", Math.abs(hash).toString(16));
|
|
1677
|
+
const signature = createHmac("sha256", config.signKey).update(path3 + params.toString()).digest("hex");
|
|
1678
|
+
params.set("s", signature);
|
|
1690
1679
|
return path3;
|
|
1691
1680
|
};
|
|
1692
1681
|
return {
|
|
@@ -2959,7 +2948,7 @@ var MediaService = class _MediaService {
|
|
|
2959
2948
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
2960
2949
|
return { where, params: p, orderBy: sortDir, sortCol };
|
|
2961
2950
|
}
|
|
2962
|
-
rowToMedia(row) {
|
|
2951
|
+
rowToMedia(row, origin) {
|
|
2963
2952
|
return {
|
|
2964
2953
|
id: row.id,
|
|
2965
2954
|
filename: row.filename,
|
|
@@ -2969,8 +2958,8 @@ var MediaService = class _MediaService {
|
|
|
2969
2958
|
fileSize: row.file_size ?? row.fileSize,
|
|
2970
2959
|
width: row.width ?? null,
|
|
2971
2960
|
height: row.height ?? null,
|
|
2972
|
-
url: row.url,
|
|
2973
|
-
thumbnailUrl: row.thumbnail_url ?? row.thumbnailUrl ?? null,
|
|
2961
|
+
url: _MediaService.resolveMediaUrl(row.url, origin),
|
|
2962
|
+
thumbnailUrl: _MediaService.resolveMediaUrl(row.thumbnail_url ?? row.thumbnailUrl ?? null, origin),
|
|
2974
2963
|
folder: row.folder ?? null,
|
|
2975
2964
|
provider: row.provider,
|
|
2976
2965
|
alt: row.alt ?? null,
|
|
@@ -2980,6 +2969,12 @@ var MediaService = class _MediaService {
|
|
|
2980
2969
|
updatedAt: row.updated_at ?? row.updatedAt
|
|
2981
2970
|
};
|
|
2982
2971
|
}
|
|
2972
|
+
static resolveMediaUrl(url, origin) {
|
|
2973
|
+
if (!url) return null;
|
|
2974
|
+
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("blob:") || url.startsWith("data:")) return url;
|
|
2975
|
+
const base = (process.env.KYRO_BASE_URL || origin || "http://localhost:4321").replace(/\/+$/, "");
|
|
2976
|
+
return `${base}${url.startsWith("/") ? "" : "/"}${url}`;
|
|
2977
|
+
}
|
|
2983
2978
|
async sqliteRun(sql, params = []) {
|
|
2984
2979
|
const stmt = this.db.prepare(sql);
|
|
2985
2980
|
const sqlLower = sql.trim().toLowerCase();
|
|
@@ -3107,17 +3102,19 @@ var MediaService = class _MediaService {
|
|
|
3107
3102
|
const file = new File([blob], originalName, { type: mimeType });
|
|
3108
3103
|
return this.upload(file, folder);
|
|
3109
3104
|
}
|
|
3110
|
-
async delete(id) {
|
|
3105
|
+
async delete(id, origin) {
|
|
3111
3106
|
let item = null;
|
|
3112
3107
|
if (this.dialect === "sqlite") {
|
|
3113
|
-
|
|
3114
|
-
id
|
|
3115
|
-
|
|
3108
|
+
const row = this.sqliteGet(
|
|
3109
|
+
`SELECT * FROM ${this.mediaTable} WHERE id = ?`,
|
|
3110
|
+
[id]
|
|
3111
|
+
);
|
|
3112
|
+
if (row) item = this.rowToMedia(row, origin);
|
|
3116
3113
|
} else {
|
|
3117
3114
|
const { media: mediaSchema } = await import('./media-7WDX4BDJ.js');
|
|
3118
3115
|
const { eq } = await import('drizzle-orm');
|
|
3119
3116
|
const [row] = await this.db.select().from(mediaSchema).where(eq(mediaSchema.id, id));
|
|
3120
|
-
if (row) item = this.rowToMedia(row);
|
|
3117
|
+
if (row) item = this.rowToMedia(row, origin);
|
|
3121
3118
|
}
|
|
3122
3119
|
if (!item) return;
|
|
3123
3120
|
await this.deleteFile(item.url);
|
|
@@ -3138,7 +3135,7 @@ var MediaService = class _MediaService {
|
|
|
3138
3135
|
async deleteFile(url) {
|
|
3139
3136
|
await this.storage.delete(url);
|
|
3140
3137
|
}
|
|
3141
|
-
async rename(id, newKey) {
|
|
3138
|
+
async rename(id, newKey, origin) {
|
|
3142
3139
|
let item = null;
|
|
3143
3140
|
if (this.dialect === "sqlite") {
|
|
3144
3141
|
item = this.sqliteGet(`SELECT * FROM ${this.mediaTable} WHERE id = ?`, [
|
|
@@ -3148,7 +3145,7 @@ var MediaService = class _MediaService {
|
|
|
3148
3145
|
const { media: mediaSchema } = await import('./media-7WDX4BDJ.js');
|
|
3149
3146
|
const { eq } = await import('drizzle-orm');
|
|
3150
3147
|
const [row] = await this.db.select().from(mediaSchema).where(eq(mediaSchema.id, id));
|
|
3151
|
-
if (row) item = this.rowToMedia(row);
|
|
3148
|
+
if (row) item = this.rowToMedia(row, origin);
|
|
3152
3149
|
}
|
|
3153
3150
|
if (!item) return null;
|
|
3154
3151
|
const newUrl = await this.storage.rename(item.url, newKey);
|
|
@@ -3191,20 +3188,20 @@ var MediaService = class _MediaService {
|
|
|
3191
3188
|
thumbnailUrl: updateData.thumbnailUrl ?? null
|
|
3192
3189
|
};
|
|
3193
3190
|
}
|
|
3194
|
-
async findById(id) {
|
|
3191
|
+
async findById(id, origin) {
|
|
3195
3192
|
if (this.dialect === "sqlite") {
|
|
3196
3193
|
const row2 = this.sqliteGet(
|
|
3197
3194
|
`SELECT * FROM ${this.mediaTable} WHERE id = ?`,
|
|
3198
3195
|
[id]
|
|
3199
3196
|
);
|
|
3200
|
-
return row2 ? this.rowToMedia(row2) : null;
|
|
3197
|
+
return row2 ? this.rowToMedia(row2, origin) : null;
|
|
3201
3198
|
}
|
|
3202
3199
|
const { media: mediaSchema } = await import('./media-7WDX4BDJ.js');
|
|
3203
3200
|
const { eq } = await import('drizzle-orm');
|
|
3204
3201
|
const [row] = await this.db.select().from(mediaSchema).where(eq(mediaSchema.id, id));
|
|
3205
|
-
return row ? this.rowToMedia(row) : null;
|
|
3202
|
+
return row ? this.rowToMedia(row, origin) : null;
|
|
3206
3203
|
}
|
|
3207
|
-
async find(params = {}) {
|
|
3204
|
+
async find(params = {}, origin) {
|
|
3208
3205
|
const {
|
|
3209
3206
|
page = 1,
|
|
3210
3207
|
limit = 30,
|
|
@@ -3240,7 +3237,7 @@ var MediaService = class _MediaService {
|
|
|
3240
3237
|
[...p, limit, offset]
|
|
3241
3238
|
);
|
|
3242
3239
|
return {
|
|
3243
|
-
docs: rows.map((r) => this.rowToMedia(r)),
|
|
3240
|
+
docs: rows.map((r) => this.rowToMedia(r, origin)),
|
|
3244
3241
|
totalDocs: totalDocs2,
|
|
3245
3242
|
page,
|
|
3246
3243
|
limit,
|
|
@@ -3287,14 +3284,14 @@ var MediaService = class _MediaService {
|
|
|
3287
3284
|
const [{ count }] = await this.db.select({ count: sql`count(*)` }).from(mediaSchema).where(whereClause);
|
|
3288
3285
|
const totalDocs = Number(count);
|
|
3289
3286
|
return {
|
|
3290
|
-
docs: docs.map((r) => this.rowToMedia(r)),
|
|
3287
|
+
docs: docs.map((r) => this.rowToMedia(r, origin)),
|
|
3291
3288
|
totalDocs,
|
|
3292
3289
|
page,
|
|
3293
3290
|
limit,
|
|
3294
3291
|
totalPages: Math.ceil(totalDocs / limit)
|
|
3295
3292
|
};
|
|
3296
3293
|
}
|
|
3297
|
-
async update(id, data) {
|
|
3294
|
+
async update(id, data, origin) {
|
|
3298
3295
|
const now = this.now();
|
|
3299
3296
|
if (this.dialect === "sqlite") {
|
|
3300
3297
|
const sets = ["updated_at = ?"];
|
|
@@ -3313,7 +3310,7 @@ var MediaService = class _MediaService {
|
|
|
3313
3310
|
}
|
|
3314
3311
|
if (data.folder !== void 0) {
|
|
3315
3312
|
sets.push("folder = ?");
|
|
3316
|
-
p.push(data.folder
|
|
3313
|
+
p.push(data.folder);
|
|
3317
3314
|
}
|
|
3318
3315
|
p.push(id);
|
|
3319
3316
|
await this.sqliteRun(
|
|
@@ -3324,12 +3321,12 @@ var MediaService = class _MediaService {
|
|
|
3324
3321
|
`SELECT * FROM ${this.mediaTable} WHERE id = ?`,
|
|
3325
3322
|
[id]
|
|
3326
3323
|
);
|
|
3327
|
-
return row ? this.rowToMedia(row) : null;
|
|
3324
|
+
return row ? this.rowToMedia(row, origin) : null;
|
|
3328
3325
|
}
|
|
3329
3326
|
const { media: mediaSchema } = await import('./media-7WDX4BDJ.js');
|
|
3330
3327
|
const { eq } = await import('drizzle-orm');
|
|
3331
3328
|
const [updated] = await this.db.update(mediaSchema).set({ ...data, updatedAt: /* @__PURE__ */ new Date() }).where(eq(mediaSchema.id, id)).returning();
|
|
3332
|
-
return updated ? this.rowToMedia(updated) : null;
|
|
3329
|
+
return updated ? this.rowToMedia(updated, origin) : null;
|
|
3333
3330
|
}
|
|
3334
3331
|
async updateMany(ids, data) {
|
|
3335
3332
|
const now = this.now();
|
|
@@ -4116,12 +4113,13 @@ function createHonoApp(options) {
|
|
|
4116
4113
|
const { user: ctxUser } = await resolveAuthContext(c.req.raw, authMw, user, tenantID);
|
|
4117
4114
|
if (!ctxUser) return c.json({ error: "Authentication required" }, 401);
|
|
4118
4115
|
const service = await getMedia();
|
|
4116
|
+
const origin = new URL(c.req.url).origin;
|
|
4119
4117
|
const page = parseInt(c.req.query("page") || "1");
|
|
4120
4118
|
const limit = parseInt(c.req.query("limit") || "30");
|
|
4121
4119
|
const search = c.req.query("search") || "";
|
|
4122
4120
|
const type = c.req.query("type") || "";
|
|
4123
4121
|
const folder = c.req.query("folder") || "";
|
|
4124
|
-
const result = await service.find({ page, limit, search, type, folder });
|
|
4122
|
+
const result = await service.find({ page, limit, search, type, folder }, origin);
|
|
4125
4123
|
return c.json(result);
|
|
4126
4124
|
} catch (error) {
|
|
4127
4125
|
console.error("[Media] find error:", error);
|
|
@@ -4205,7 +4203,8 @@ function createHonoApp(options) {
|
|
|
4205
4203
|
if (!ctxUser) return c.json({ error: "Authentication required" }, 401);
|
|
4206
4204
|
const service = await getMedia();
|
|
4207
4205
|
const id = c.req.param("id");
|
|
4208
|
-
|
|
4206
|
+
const origin = new URL(c.req.url).origin;
|
|
4207
|
+
await service.delete(id, origin);
|
|
4209
4208
|
return c.json({ success: true });
|
|
4210
4209
|
} catch (error) {
|
|
4211
4210
|
console.error("[Media] delete error:", error);
|
|
@@ -4261,7 +4260,8 @@ function createHonoApp(options) {
|
|
|
4261
4260
|
if (!ctxUser) return c.json({ error: "Authentication required" }, 401);
|
|
4262
4261
|
const service = await getMedia();
|
|
4263
4262
|
const id = c.req.param("id");
|
|
4264
|
-
const
|
|
4263
|
+
const origin = new URL(c.req.url).origin;
|
|
4264
|
+
const doc = await service.findById(id, origin);
|
|
4265
4265
|
if (!doc) return c.json({ error: "Media not found" }, 404);
|
|
4266
4266
|
return c.json(doc);
|
|
4267
4267
|
} catch (error) {
|
|
@@ -4276,8 +4276,9 @@ function createHonoApp(options) {
|
|
|
4276
4276
|
const service = await getMedia();
|
|
4277
4277
|
const id = c.req.param("id");
|
|
4278
4278
|
const body = await c.req.json();
|
|
4279
|
+
const origin = new URL(c.req.url).origin;
|
|
4279
4280
|
if (body.folder !== void 0) {
|
|
4280
|
-
const updated = await service.update(id, { folder: body.folder });
|
|
4281
|
+
const updated = await service.update(id, { folder: body.folder }, origin);
|
|
4281
4282
|
return c.json({ doc: updated });
|
|
4282
4283
|
}
|
|
4283
4284
|
return c.json({ error: "No valid fields to update" }, 400);
|
|
@@ -5058,6 +5059,75 @@ function createHonoApp(options) {
|
|
|
5058
5059
|
return c.json({ error: error.message }, 500);
|
|
5059
5060
|
}
|
|
5060
5061
|
});
|
|
5062
|
+
function serializeField(field) {
|
|
5063
|
+
const safe = {};
|
|
5064
|
+
const keys = [
|
|
5065
|
+
"name",
|
|
5066
|
+
"type",
|
|
5067
|
+
"required",
|
|
5068
|
+
"hasMany",
|
|
5069
|
+
"relationTo",
|
|
5070
|
+
"options",
|
|
5071
|
+
"min",
|
|
5072
|
+
"max",
|
|
5073
|
+
"minLength",
|
|
5074
|
+
"maxLength",
|
|
5075
|
+
"defaultValue",
|
|
5076
|
+
"label",
|
|
5077
|
+
"localized",
|
|
5078
|
+
"admin",
|
|
5079
|
+
"unique",
|
|
5080
|
+
"index",
|
|
5081
|
+
"hidden",
|
|
5082
|
+
"readOnly",
|
|
5083
|
+
"deprecated"
|
|
5084
|
+
];
|
|
5085
|
+
for (const k of keys) {
|
|
5086
|
+
if (k in field) safe[k] = field[k];
|
|
5087
|
+
}
|
|
5088
|
+
if (field.fields) {
|
|
5089
|
+
safe.fields = field.fields.map(serializeField);
|
|
5090
|
+
}
|
|
5091
|
+
if (field.tabs) {
|
|
5092
|
+
safe.tabs = field.tabs.map((t) => ({
|
|
5093
|
+
label: t.label,
|
|
5094
|
+
name: t.name,
|
|
5095
|
+
fields: t.fields.map(serializeField)
|
|
5096
|
+
}));
|
|
5097
|
+
}
|
|
5098
|
+
return safe;
|
|
5099
|
+
}
|
|
5100
|
+
app.get("/api/__schema", async (c) => {
|
|
5101
|
+
try {
|
|
5102
|
+
const { user: ctxUser, apiKeyContext } = await resolveAuthContext(
|
|
5103
|
+
c.req.raw,
|
|
5104
|
+
authMw,
|
|
5105
|
+
user,
|
|
5106
|
+
tenantID
|
|
5107
|
+
);
|
|
5108
|
+
if (!ctxUser && !apiKeyContext) {
|
|
5109
|
+
return c.json({ error: "Unauthorized" }, 401);
|
|
5110
|
+
}
|
|
5111
|
+
const cols = registry.getCollections().filter(
|
|
5112
|
+
(col) => col.slug !== "users" && col.slug !== "audit_logs"
|
|
5113
|
+
);
|
|
5114
|
+
const serialized = cols.map((col) => ({
|
|
5115
|
+
slug: col.slug,
|
|
5116
|
+
label: col.label,
|
|
5117
|
+
labelPlural: col.labelPlural,
|
|
5118
|
+
singularLabel: col.singularLabel,
|
|
5119
|
+
timestamps: col.timestamps,
|
|
5120
|
+
auth: !!col.auth,
|
|
5121
|
+
tenantScoped: !!col.tenantScoped,
|
|
5122
|
+
upload: col.upload ? { staticDir: col.upload.staticDir, imageSizes: col.upload.imageSizes, mimeTypes: col.upload.mimeTypes } : void 0,
|
|
5123
|
+
fields: col.fields.map(serializeField)
|
|
5124
|
+
}));
|
|
5125
|
+
return c.json(serialized);
|
|
5126
|
+
} catch (error) {
|
|
5127
|
+
console.error("[Schema] error:", error);
|
|
5128
|
+
return c.json({ error: error.message }, 500);
|
|
5129
|
+
}
|
|
5130
|
+
});
|
|
5061
5131
|
const collections = registry.getCollections();
|
|
5062
5132
|
for (const collection of collections) {
|
|
5063
5133
|
let computeDiff2 = function(a, b) {
|
|
@@ -5103,10 +5173,20 @@ function createHonoApp(options) {
|
|
|
5103
5173
|
const sort = url.searchParams.get("sort") || void 0;
|
|
5104
5174
|
const depth = parseInt(url.searchParams.get("depth") || "0");
|
|
5105
5175
|
const select = url.searchParams.get("select")?.split(",") || void 0;
|
|
5106
|
-
const
|
|
5176
|
+
const draftParam = url.searchParams.get("draft");
|
|
5177
|
+
const isDraftRequest = draftParam === "true" ? true : draftParam === "false" ? false : !!ctxUser;
|
|
5178
|
+
let where = {};
|
|
5179
|
+
const whereRaw = url.searchParams.get("where");
|
|
5180
|
+
if (whereRaw) {
|
|
5181
|
+
try {
|
|
5182
|
+
where = JSON.parse(whereRaw);
|
|
5183
|
+
} catch {
|
|
5184
|
+
return c.json({ error: "Invalid JSON in where parameter" }, 400);
|
|
5185
|
+
}
|
|
5186
|
+
}
|
|
5107
5187
|
const result = await db.find({
|
|
5108
5188
|
collection: slug,
|
|
5109
|
-
where
|
|
5189
|
+
where,
|
|
5110
5190
|
sort,
|
|
5111
5191
|
limit,
|
|
5112
5192
|
page,
|
|
@@ -5295,7 +5375,8 @@ function createHonoApp(options) {
|
|
|
5295
5375
|
const url = new URL(c.req.url);
|
|
5296
5376
|
const depth = parseInt(url.searchParams.get("depth") || "0");
|
|
5297
5377
|
const select = url.searchParams.get("select")?.split(",") || void 0;
|
|
5298
|
-
const
|
|
5378
|
+
const draftParam = url.searchParams.get("draft");
|
|
5379
|
+
const isDraftRequest = draftParam === "true" ? true : draftParam === "false" ? false : !!ctxUser;
|
|
5299
5380
|
let doc = await db.findByID({
|
|
5300
5381
|
collection: slug,
|
|
5301
5382
|
id,
|
|
@@ -6282,7 +6363,6 @@ function createHonoApp(options) {
|
|
|
6282
6363
|
data: doc,
|
|
6283
6364
|
message: "Version restored successfully"
|
|
6284
6365
|
});
|
|
6285
|
-
return c.json({ data: doc, message: "Restored successfully" });
|
|
6286
6366
|
} catch (error) {
|
|
6287
6367
|
return c.json({ error: error.message }, 500);
|
|
6288
6368
|
}
|
|
@@ -6368,6 +6448,13 @@ Sent at: ${(/* @__PURE__ */ new Date()).toLocaleString()}`
|
|
|
6368
6448
|
});
|
|
6369
6449
|
}
|
|
6370
6450
|
}
|
|
6451
|
+
app.onError((err, c) => {
|
|
6452
|
+
console.error(`[API Error] ${c.req.method} ${c.req.path}:`, err);
|
|
6453
|
+
return c.json(
|
|
6454
|
+
{ error: err.message || "Internal server error", code: "INTERNAL_ERROR" },
|
|
6455
|
+
500
|
|
6456
|
+
);
|
|
6457
|
+
});
|
|
6371
6458
|
return app;
|
|
6372
6459
|
}
|
|
6373
6460
|
function createRESTAPI(registry, db, options) {
|
|
@@ -6384,5 +6471,5 @@ function createRESTAPI(registry, db, options) {
|
|
|
6384
6471
|
}
|
|
6385
6472
|
|
|
6386
6473
|
export { AuditLogger, AuthRoutes, InMemoryAuditLogger, InMemoryRateLimiter, MediaService, createAuditContext2 as createAuditContext, createCloudinaryStorage, createFtpStorage, createHonoApp, createLocalStorage, createRESTAPI, createS3Storage, getAppSecret, getDefaultRegistry, getEncryptionKey, getSessionConfig, init_secret, loadSecrets, resolveProvider, setDbAdapter };
|
|
6387
|
-
//# sourceMappingURL=chunk-
|
|
6388
|
-
//# sourceMappingURL=chunk-
|
|
6474
|
+
//# sourceMappingURL=chunk-5RFGYEQ3.js.map
|
|
6475
|
+
//# sourceMappingURL=chunk-5RFGYEQ3.js.map
|