@infuro/cms-core 1.0.20 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.js CHANGED
@@ -477,6 +477,13 @@ async function queueErpProductUpsertIfEnabled(cms, dataSource, entityMap, produc
477
477
  }
478
478
 
479
479
  // src/api/crud.ts
480
+ var CRUD_LOG = "[cms-crud]";
481
+ function logCrudClientError(op, detail) {
482
+ console.warn(CRUD_LOG, op, detail);
483
+ }
484
+ function logCrudServerError(op, detail) {
485
+ console.error(CRUD_LOG, op, detail);
486
+ }
480
487
  var DATE_COLUMN_TYPES = /* @__PURE__ */ new Set([
481
488
  "date",
482
489
  "datetime",
@@ -588,6 +595,13 @@ function createCrudHandler(dataSource, entityMap, options) {
588
595
  if (authError) return authError;
589
596
  const entity = entityMap[resource];
590
597
  if (!resource || !entity) {
598
+ logCrudClientError("GET list", {
599
+ reason: "invalid_resource",
600
+ resource,
601
+ hasEntity: Boolean(entity),
602
+ entityMapHasLlmAgents: Boolean(entityMap.llm_agents),
603
+ entityMapKeyCount: Object.keys(entityMap).length
604
+ });
591
605
  return json({ error: "Invalid resource" }, { status: 400 });
592
606
  }
593
607
  const { searchParams } = new URL(req.url);
@@ -795,12 +809,22 @@ function createCrudHandler(dataSource, entityMap, options) {
795
809
  }
796
810
  }
797
811
  where = mergeDeletedFalseWhere(repo, where);
798
- const [data, total] = await repo.findAndCount({
799
- skip,
800
- take: limit,
801
- order: { [sortField]: sortOrder },
802
- where
803
- });
812
+ let data;
813
+ let total;
814
+ try {
815
+ const r = await repo.findAndCount({
816
+ skip,
817
+ take: limit,
818
+ order: { [sortField]: sortOrder },
819
+ where
820
+ });
821
+ data = r[0];
822
+ total = r[1];
823
+ } catch (err) {
824
+ const message = err instanceof Error ? err.message : String(err);
825
+ logCrudServerError("GET list query failed", { resource, sortField, sortOrder, message });
826
+ throw err;
827
+ }
804
828
  return json({ total, page, limit, totalPages: Math.ceil(total / limit), data });
805
829
  },
806
830
  async POST(req, resource) {
@@ -808,12 +832,25 @@ function createCrudHandler(dataSource, entityMap, options) {
808
832
  if (authError) return authError;
809
833
  const entity = entityMap[resource];
810
834
  if (!resource || !entity) {
835
+ logCrudClientError("POST create", {
836
+ reason: "invalid_resource",
837
+ resource,
838
+ hasEntity: Boolean(entity),
839
+ entityMapHasLlmAgents: Boolean(entityMap.llm_agents)
840
+ });
811
841
  return json({ error: "Invalid resource" }, { status: 400 });
812
842
  }
813
- const body = await req.json();
814
- if (!body || typeof body !== "object" || Object.keys(body).length === 0) {
843
+ const rawPostBody = await req.json();
844
+ if (!rawPostBody || typeof rawPostBody !== "object" || Object.keys(rawPostBody).length === 0) {
845
+ logCrudClientError("POST create", {
846
+ reason: "invalid_request_payload",
847
+ resource,
848
+ rawType: rawPostBody == null ? "nullish" : typeof rawPostBody,
849
+ keyCount: rawPostBody && typeof rawPostBody === "object" ? Object.keys(rawPostBody).length : 0
850
+ });
815
851
  return json({ error: "Invalid request payload" }, { status: 400 });
816
852
  }
853
+ const body = rawPostBody;
817
854
  if (resource === "media") {
818
855
  const b = body;
819
856
  const kind = b.kind === "folder" ? "folder" : "file";
@@ -847,8 +884,24 @@ function createCrudHandler(dataSource, entityMap, options) {
847
884
  }
848
885
  }
849
886
  const repo = dataSource.getRepository(entity);
850
- sanitizeBodyForEntity(repo, body);
851
- const created = await repo.save(repo.create(body));
887
+ const persistBody = resource === "media" ? body : pickColumnUpdates(repo, body);
888
+ if (resource !== "media" && Object.keys(persistBody).length === 0) {
889
+ logCrudClientError("POST create", {
890
+ reason: "no_scalar_columns_after_pick",
891
+ resource,
892
+ incomingKeys: Object.keys(body)
893
+ });
894
+ return json({ error: "Invalid request payload" }, { status: 400 });
895
+ }
896
+ sanitizeBodyForEntity(repo, persistBody);
897
+ let created;
898
+ try {
899
+ created = await repo.save(repo.create(persistBody));
900
+ } catch (err) {
901
+ const message = err instanceof Error ? err.message : String(err);
902
+ logCrudServerError("POST create save failed", { resource, message, persistKeys: Object.keys(persistBody) });
903
+ throw err;
904
+ }
852
905
  if (resource === "contacts") {
853
906
  await syncContactRowToErp(created);
854
907
  }
@@ -863,6 +916,7 @@ function createCrudHandler(dataSource, entityMap, options) {
863
916
  if (authError) return authError;
864
917
  const entity = entityMap[resource];
865
918
  if (!resource || !entity) {
919
+ logCrudClientError("GET_METADATA", { reason: "invalid_resource", resource });
866
920
  return json({ error: "Invalid resource" }, { status: 400 });
867
921
  }
868
922
  const repo = dataSource.getRepository(entity);
@@ -894,11 +948,18 @@ function createCrudHandler(dataSource, entityMap, options) {
894
948
  if (authError) return authError;
895
949
  const entity = entityMap[resource];
896
950
  if (!resource || !entity) {
951
+ logCrudClientError("BULK_POST", { reason: "invalid_resource", resource });
897
952
  return json({ error: "Invalid resource" }, { status: 400 });
898
953
  }
899
954
  const body = await req.json();
900
955
  const { records, upsertKey = "id" } = body;
901
956
  if (!Array.isArray(records) || records.length === 0) {
957
+ logCrudClientError("BULK_POST", {
958
+ reason: "records_required",
959
+ resource,
960
+ recordsIsArray: Array.isArray(records),
961
+ recordCount: Array.isArray(records) ? records.length : 0
962
+ });
902
963
  return json({ error: "Records array is required" }, { status: 400 });
903
964
  }
904
965
  const repo = dataSource.getRepository(entity);
@@ -917,6 +978,7 @@ function createCrudHandler(dataSource, entityMap, options) {
917
978
  });
918
979
  } catch (error) {
919
980
  const message = error instanceof Error ? error.message : "Bulk import failed";
981
+ logCrudClientError("BULK_POST upsert failed", { resource, upsertKey, message });
920
982
  return json({ error: message }, { status: 400 });
921
983
  }
922
984
  },
@@ -925,6 +987,7 @@ function createCrudHandler(dataSource, entityMap, options) {
925
987
  if (authError) return authError;
926
988
  const entity = entityMap[resource];
927
989
  if (!resource || !entity) {
990
+ logCrudClientError("GET_EXPORT", { reason: "invalid_resource", resource });
928
991
  return json({ error: "Invalid resource" }, { status: 400 });
929
992
  }
930
993
  const { searchParams } = new URL(req.url);
@@ -979,7 +1042,10 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
979
1042
  const authError = await authz(req, resource, "read");
980
1043
  if (authError) return authError;
981
1044
  const entity = entityMap[resource];
982
- if (!entity) return json({ error: "Invalid resource" }, { status: 400 });
1045
+ if (!entity) {
1046
+ logCrudClientError("GET by id", { reason: "invalid_resource", resource, id });
1047
+ return json({ error: "Invalid resource" }, { status: 400 });
1048
+ }
983
1049
  const repo = dataSource.getRepository(entity);
984
1050
  if (resource === "orders") {
985
1051
  const order = await repo.findOne({
@@ -1038,7 +1104,10 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
1038
1104
  const authError = await authz(req, resource, "update");
1039
1105
  if (authError) return authError;
1040
1106
  const entity = entityMap[resource];
1041
- if (!entity) return json({ error: "Invalid resource" }, { status: 400 });
1107
+ if (!entity) {
1108
+ logCrudClientError("PUT by id", { reason: "invalid_resource", resource, id });
1109
+ return json({ error: "Invalid resource" }, { status: 400 });
1110
+ }
1042
1111
  const rawBody = await req.json();
1043
1112
  const repo = dataSource.getRepository(entity);
1044
1113
  const numericId = Number(id);
@@ -1151,7 +1220,10 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
1151
1220
  const authError = await authz(req, resource, "delete");
1152
1221
  if (authError) return authError;
1153
1222
  const entity = entityMap[resource];
1154
- if (!entity) return json({ error: "Invalid resource" }, { status: 400 });
1223
+ if (!entity) {
1224
+ logCrudClientError("DELETE by id", { reason: "invalid_resource", resource, id });
1225
+ return json({ error: "Invalid resource" }, { status: 400 });
1226
+ }
1155
1227
  const repo = dataSource.getRepository(entity);
1156
1228
  const numericId = Number(id);
1157
1229
  if (entityHasSoftDelete(repo)) {
@@ -3051,6 +3123,9 @@ var EMBED_CONCURRENCY = 5;
3051
3123
  var MAX_PDF_BYTES = 25 * 1024 * 1024;
3052
3124
  var TEXT_FILE_TYPES = /* @__PURE__ */ new Set(["text/plain", "text/markdown", "application/json"]);
3053
3125
  var KB_LOG = "[llm-agent-knowledge]";
3126
+ function logKbPipeline(step, meta) {
3127
+ console.info(`${KB_LOG} pipeline`, { step, ...meta });
3128
+ }
3054
3129
  function llmEmbedDebug() {
3055
3130
  const v = process.env.LLM_EMBED_DEBUG?.toLowerCase();
3056
3131
  return v === "1" || v === "true" || v === "yes";
@@ -3065,11 +3140,29 @@ async function extractTextFromPdf(buffer) {
3065
3140
  const data = await pdfParse(buffer);
3066
3141
  return (data?.text ?? "").trim();
3067
3142
  }
3068
- async function writeEmbeddingsConcurrent(dataSource, embed, chunks, concurrency) {
3143
+ async function loadChunksMissingEmbeddings(dataSource, documentId, slug) {
3144
+ const rows = await dataSource.query(
3145
+ `SELECT id, content FROM knowledge_base_chunks WHERE "documentId" = $1 AND embedding IS NULL ORDER BY "chunkIndex" ASC`,
3146
+ [documentId]
3147
+ );
3148
+ const list = rows ?? [];
3149
+ logKbPipeline("07_query_chunks_missing_embedding", {
3150
+ slug,
3151
+ documentId,
3152
+ missingEmbeddingCount: list.length
3153
+ });
3154
+ return list;
3155
+ }
3156
+ async function writeEmbeddingsConcurrent(dataSource, embed, chunks, concurrency, slug) {
3069
3157
  let next = 0;
3070
3158
  let written = 0;
3071
3159
  let failed = 0;
3072
3160
  let skippedEmpty = 0;
3161
+ logKbPipeline("09_embedding_workers_start", {
3162
+ slug,
3163
+ chunkCount: chunks.length,
3164
+ concurrency: Math.max(1, Math.min(concurrency, chunks.length))
3165
+ });
3073
3166
  async function worker() {
3074
3167
  for (; ; ) {
3075
3168
  const i = next++;
@@ -3108,9 +3201,12 @@ async function writeEmbeddingsConcurrent(dataSource, embed, chunks, concurrency)
3108
3201
  skippedEmpty
3109
3202
  };
3110
3203
  if (skippedEmpty > 0 && written === 0) {
3111
- summary.hint = "embed() returned empty vectors \u2014 see [LLM embed] logs (often HTTP 404 on /v1/embeddings, or wrong response shape).";
3204
+ summary.hint = "embed() returned empty vectors \u2014 see [LLM embed] / [LLM embed HF] logs (OpenAI gateway vs @huggingface/inference + legacy HTTP).";
3205
+ }
3206
+ logKbPipeline("10_embedding_workers_finished", { slug, ...summary });
3207
+ if (failed > 0 || skippedEmpty > 0 && written === 0) {
3208
+ console.error(`${KB_LOG} embedding pass finished with issues`, summary);
3112
3209
  }
3113
- console.error(`${KB_LOG} embedding pass finished`, summary);
3114
3210
  return { written, failed };
3115
3211
  }
3116
3212
  function splitIntoChunks(text, maxLen) {
@@ -3146,6 +3242,58 @@ function createLlmAgentKnowledgeHandlers(config) {
3146
3242
  }
3147
3243
  return null;
3148
3244
  }
3245
+ async function runEmbeddingPass(slug, savedChunks) {
3246
+ let embeddingsWritten = 0;
3247
+ let embeddingsFailed = 0;
3248
+ try {
3249
+ logKbPipeline("08_resolve_llm_plugin", { slug, chunkCount: savedChunks.length });
3250
+ const cms = await getCms();
3251
+ const llm = cms.getPlugin("llm");
3252
+ if (llm?.embed && savedChunks.length > 0) {
3253
+ logKbPipeline("08b_embed_fn_available", {
3254
+ slug,
3255
+ chunkCount: savedChunks.length,
3256
+ firstChunkId: savedChunks[0]?.id,
3257
+ lastChunkId: savedChunks[savedChunks.length - 1]?.id
3258
+ });
3259
+ const embedBound = (text) => llm.embed(text);
3260
+ const { written, failed } = await writeEmbeddingsConcurrent(
3261
+ dataSource,
3262
+ embedBound,
3263
+ savedChunks,
3264
+ EMBED_CONCURRENCY,
3265
+ slug
3266
+ );
3267
+ embeddingsWritten = written;
3268
+ embeddingsFailed = failed;
3269
+ } else {
3270
+ logKbPipeline("08c_embed_skipped", {
3271
+ slug,
3272
+ hasLlmPlugin: !!llm,
3273
+ hasEmbed: typeof llm?.embed === "function",
3274
+ chunkCount: savedChunks.length,
3275
+ reason: savedChunks.length === 0 ? "no_chunks" : !llm ? "no_llm_plugin" : "no_embed_method"
3276
+ });
3277
+ console.error(`${KB_LOG} embeddings skipped`, {
3278
+ slug,
3279
+ hasLlmPlugin: !!llm,
3280
+ hasEmbed: typeof llm?.embed === "function",
3281
+ chunkCount: savedChunks.length,
3282
+ hint: !llm || typeof llm.embed !== "function" ? "LLM plugin missing or no embed(); check LLM_GATEWAY_URL + LLM_API_KEY so llm plugin initializes." : void 0
3283
+ });
3284
+ }
3285
+ } catch (embErr) {
3286
+ const detail = embErr instanceof Error ? embErr.message : String(embErr);
3287
+ logKbPipeline("08d_embed_pass_exception", { slug, detail });
3288
+ console.error(`${KB_LOG} embedding step threw before/during batch`, { slug, detail, embErr });
3289
+ return {
3290
+ embeddingsWritten: 0,
3291
+ embeddingsFailed: savedChunks.length,
3292
+ embedError: detail
3293
+ };
3294
+ }
3295
+ return { embeddingsWritten, embeddingsFailed };
3296
+ }
3149
3297
  return {
3150
3298
  async list(req, slug) {
3151
3299
  const denied = await gate(req, "read");
@@ -3174,8 +3322,11 @@ function createLlmAgentKnowledgeHandlers(config) {
3174
3322
  const denied = await gate(req, "update");
3175
3323
  if (denied) return denied;
3176
3324
  try {
3325
+ const ct0 = req.headers.get("content-type") || "";
3326
+ logKbPipeline("01_request", { slug, contentType: ct0.slice(0, 80) });
3177
3327
  const agent = await findAgentBySlug(dataSource, llmAgents, slug);
3178
3328
  if (!agent) return json({ error: "Agent not found" }, { status: 404 });
3329
+ logKbPipeline("02_agent_loaded", { slug, agentId: agent.id });
3179
3330
  let name = "";
3180
3331
  let text = "";
3181
3332
  let sourceUrl = null;
@@ -3187,6 +3338,14 @@ function createLlmAgentKnowledgeHandlers(config) {
3187
3338
  name = (body?.name ?? "").trim();
3188
3339
  text = (body?.text ?? "").trim();
3189
3340
  sourceUrl = typeof body?.sourceUrl === "string" && body.sourceUrl.trim() ? body.sourceUrl.trim() : null;
3341
+ logKbPipeline("03_body_parsed", {
3342
+ slug,
3343
+ mode: "json",
3344
+ existingDocumentId,
3345
+ nameLen: name.length,
3346
+ textChars: text.length,
3347
+ hasSourceUrl: !!sourceUrl
3348
+ });
3190
3349
  } else if (ct.includes("multipart/form-data")) {
3191
3350
  const form = await req.formData();
3192
3351
  name = form.get("name")?.trim() ?? "";
@@ -3196,9 +3355,17 @@ function createLlmAgentKnowledgeHandlers(config) {
3196
3355
  const f = file;
3197
3356
  const mime = (f.type || "").split(";")[0].trim().toLowerCase();
3198
3357
  const buf = Buffer.from(await f.arrayBuffer());
3358
+ logKbPipeline("03_body_parsed", {
3359
+ slug,
3360
+ mode: "multipart",
3361
+ fileName: f.name || "(no name)",
3362
+ mime,
3363
+ fileBytes: buf.length
3364
+ });
3199
3365
  if (TEXT_FILE_TYPES.has(mime)) {
3200
3366
  const decoded = buf.toString("utf8");
3201
3367
  if (!text) text = decoded;
3368
+ logKbPipeline("04_file_decoded_text", { slug, mime, textChars: text.length });
3202
3369
  } else if (isPdfUpload(mime, f.name || "")) {
3203
3370
  if (buf.length > MAX_PDF_BYTES) {
3204
3371
  return json(
@@ -3207,8 +3374,10 @@ function createLlmAgentKnowledgeHandlers(config) {
3207
3374
  );
3208
3375
  }
3209
3376
  try {
3377
+ logKbPipeline("04_pdf_extract_start", { slug, fileBytes: buf.length });
3210
3378
  const extracted = await extractTextFromPdf(buf);
3211
3379
  if (!text) text = extracted;
3380
+ logKbPipeline("04_pdf_extract_done", { slug, textChars: text.length });
3212
3381
  } catch {
3213
3382
  return json(
3214
3383
  { error: "Could not read PDF text (file may be encrypted, corrupt, or image-only)" },
@@ -3224,12 +3393,15 @@ function createLlmAgentKnowledgeHandlers(config) {
3224
3393
  );
3225
3394
  }
3226
3395
  if (!name && f.name) name = f.name.replace(/\.[^/.]+$/, "") || f.name;
3396
+ } else {
3397
+ logKbPipeline("03_body_parsed", { slug, mode: "multipart", hasFile: false, textChars: text.length });
3227
3398
  }
3228
3399
  } else {
3229
3400
  return json({ error: "Use application/json or multipart/form-data" }, { status: 400 });
3230
3401
  }
3231
3402
  const linkRepo = dataSource.getRepository(junction);
3232
3403
  if (existingDocumentId != null) {
3404
+ logKbPipeline("05_branch", { slug, branch: "link_existing_document", documentId: existingDocumentId });
3233
3405
  const docRepo2 = dataSource.getRepository(kbDoc);
3234
3406
  const existing = await docRepo2.findOne({ where: { id: existingDocumentId } });
3235
3407
  if (!existing) return json({ error: "documentId not found" }, { status: 404 });
@@ -3238,9 +3410,137 @@ function createLlmAgentKnowledgeHandlers(config) {
3238
3410
  });
3239
3411
  if (!dup2) {
3240
3412
  await linkRepo.save(linkRepo.create({ agentId: agent.id, documentId: existingDocumentId }));
3413
+ logKbPipeline("06_junction_link_created", {
3414
+ slug,
3415
+ agentId: agent.id,
3416
+ documentId: existingDocumentId
3417
+ });
3418
+ } else {
3419
+ logKbPipeline("06_junction_link_exists", {
3420
+ slug,
3421
+ agentId: agent.id,
3422
+ documentId: existingDocumentId
3423
+ });
3424
+ }
3425
+ const chunkRepo2 = dataSource.getRepository(kbChunk);
3426
+ const docRow = existing;
3427
+ const chunkCount = await chunkRepo2.count({ where: { documentId: existingDocumentId } });
3428
+ logKbPipeline("06b_chunks_existing_count", {
3429
+ slug,
3430
+ documentId: existingDocumentId,
3431
+ chunkCount
3432
+ });
3433
+ let chunksToEmbed = [];
3434
+ let chunksCreated = 0;
3435
+ if (chunkCount === 0) {
3436
+ const text2 = (docRow.content ?? "").trim();
3437
+ if (!text2) {
3438
+ logKbPipeline("07_ingest_aborted_empty_document", { slug, documentId: existingDocumentId });
3439
+ return json({
3440
+ documentId: existingDocumentId,
3441
+ linked: true,
3442
+ created: false,
3443
+ chunkCount: 0,
3444
+ embeddingsWritten: 0,
3445
+ embeddingsFailed: 0,
3446
+ warning: "Document has no text content; add content then attach again to build chunks and embeddings."
3447
+ });
3448
+ }
3449
+ const parts2 = splitIntoChunks(text2, INGEST_CHUNK_CHARS);
3450
+ if (parts2.length > MAX_CHUNKS_PER_UPLOAD) {
3451
+ return json(
3452
+ {
3453
+ error: `Document is too large for one ingest (${parts2.length} chunks; max ${MAX_CHUNKS_PER_UPLOAD}). Split into smaller files.`
3454
+ },
3455
+ { status: 413 }
3456
+ );
3457
+ }
3458
+ logKbPipeline("07_chunk_split", {
3459
+ slug,
3460
+ documentId: existingDocumentId,
3461
+ partCount: parts2.length,
3462
+ maxChunkChars: INGEST_CHUNK_CHARS,
3463
+ totalChars: text2.length
3464
+ });
3465
+ const now2 = /* @__PURE__ */ new Date();
3466
+ const chunkRows2 = parts2.map(
3467
+ (content, i) => chunkRepo2.create({
3468
+ documentId: existingDocumentId,
3469
+ content,
3470
+ chunkIndex: i,
3471
+ createdAt: now2
3472
+ })
3473
+ );
3474
+ const savedList2 = await chunkRepo2.save(chunkRows2);
3475
+ chunksCreated = savedList2.length;
3476
+ chunksToEmbed = savedList2.map((row, i) => ({
3477
+ id: row.id,
3478
+ content: parts2[i]
3479
+ }));
3480
+ logKbPipeline("07b_chunks_persisted", {
3481
+ slug,
3482
+ documentId: existingDocumentId,
3483
+ rowsInserted: chunksCreated
3484
+ });
3485
+ } else {
3486
+ chunksToEmbed = await loadChunksMissingEmbeddings(dataSource, existingDocumentId, slug);
3487
+ if (chunksToEmbed.length === 0) {
3488
+ logKbPipeline("08_skip_embed_all_chunks_have_vectors", {
3489
+ slug,
3490
+ documentId: existingDocumentId,
3491
+ existingChunkCount: chunkCount
3492
+ });
3493
+ }
3241
3494
  }
3242
- return json({ documentId: existingDocumentId, linked: true, created: false });
3495
+ const embedResult2 = chunksToEmbed.length > 0 ? await runEmbeddingPass(slug, chunksToEmbed) : { embeddingsWritten: 0, embeddingsFailed: 0 };
3496
+ if (embedResult2.embedError) {
3497
+ logKbPipeline("11_response", {
3498
+ slug,
3499
+ branch: "link",
3500
+ documentId: existingDocumentId,
3501
+ ok: false,
3502
+ embeddingError: true
3503
+ });
3504
+ return json(
3505
+ {
3506
+ documentId: existingDocumentId,
3507
+ linked: true,
3508
+ created: false,
3509
+ chunkCount: chunkCount + chunksCreated,
3510
+ chunksCreated,
3511
+ embeddingAttempted: true,
3512
+ embeddingsWritten: 0,
3513
+ embeddingsFailed: chunksToEmbed.length,
3514
+ warning: "Document linked; embedding step failed. Fix LLM/embed config and attach again (or unlink and re-attach) to retry NULL embeddings.",
3515
+ detail: embedResult2.embedError
3516
+ },
3517
+ { status: 201 }
3518
+ );
3519
+ }
3520
+ logKbPipeline("11_response", {
3521
+ slug,
3522
+ branch: "link",
3523
+ documentId: existingDocumentId,
3524
+ ok: true,
3525
+ chunkCount: chunkCount + chunksCreated,
3526
+ chunksCreated,
3527
+ chunksQueuedForEmbedding: chunksToEmbed.length,
3528
+ embeddingsWritten: embedResult2.embeddingsWritten,
3529
+ embeddingsFailed: embedResult2.embeddingsFailed
3530
+ });
3531
+ return json({
3532
+ documentId: existingDocumentId,
3533
+ linked: true,
3534
+ created: false,
3535
+ chunkCount: chunkCount + chunksCreated,
3536
+ chunksCreated: chunksCreated || void 0,
3537
+ chunksQueuedForEmbedding: chunksToEmbed.length,
3538
+ embeddingAttempted: chunksToEmbed.length > 0,
3539
+ embeddingsWritten: embedResult2.embeddingsWritten,
3540
+ embeddingsFailed: embedResult2.embeddingsFailed
3541
+ });
3243
3542
  }
3543
+ logKbPipeline("05_branch", { slug, branch: "new_upload_ingest" });
3244
3544
  if (!text) return json({ error: "text or file with text content is required" }, { status: 400 });
3245
3545
  if (!name) name = "Untitled";
3246
3546
  const parts = splitIntoChunks(text, INGEST_CHUNK_CHARS);
@@ -3255,6 +3555,13 @@ function createLlmAgentKnowledgeHandlers(config) {
3255
3555
  { status: 413 }
3256
3556
  );
3257
3557
  }
3558
+ logKbPipeline("07_chunk_split", {
3559
+ slug,
3560
+ partCount: parts.length,
3561
+ maxChunkChars: INGEST_CHUNK_CHARS,
3562
+ totalChars: text.length,
3563
+ documentName: name
3564
+ });
3258
3565
  const docRepo = dataSource.getRepository(kbDoc);
3259
3566
  const chunkRepo = dataSource.getRepository(kbChunk);
3260
3567
  const now = /* @__PURE__ */ new Date();
@@ -3262,6 +3569,13 @@ function createLlmAgentKnowledgeHandlers(config) {
3262
3569
  docRepo.create({ name, content: text, sourceUrl, createdAt: now, updatedAt: now })
3263
3570
  );
3264
3571
  const docId = doc.id;
3572
+ logKbPipeline("06_knowledge_document_saved", {
3573
+ slug,
3574
+ documentId: docId,
3575
+ name,
3576
+ contentChars: text.length,
3577
+ hasSourceUrl: !!sourceUrl
3578
+ });
3265
3579
  const chunkRows = parts.map(
3266
3580
  (content, i) => chunkRepo.create({ documentId: docId, content, chunkIndex: i, createdAt: now })
3267
3581
  );
@@ -3272,63 +3586,66 @@ function createLlmAgentKnowledgeHandlers(config) {
3272
3586
  content: parts[i]
3273
3587
  })
3274
3588
  );
3589
+ logKbPipeline("07b_chunks_persisted", {
3590
+ slug,
3591
+ documentId: docId,
3592
+ rowsInserted: savedChunks.length,
3593
+ firstChunkId: savedChunks[0]?.id,
3594
+ lastChunkId: savedChunks[savedChunks.length - 1]?.id
3595
+ });
3275
3596
  const dup = await linkRepo.findOne({ where: { agentId: agent.id, documentId: docId } });
3276
3597
  if (!dup) {
3277
3598
  await linkRepo.save(linkRepo.create({ agentId: agent.id, documentId: docId }));
3599
+ logKbPipeline("06c_junction_link_created", { slug, agentId: agent.id, documentId: docId });
3600
+ } else {
3601
+ logKbPipeline("06c_junction_link_exists", { slug, agentId: agent.id, documentId: docId });
3278
3602
  }
3279
- let embeddingsWritten = 0;
3280
- let embeddingsFailed = 0;
3281
- try {
3282
- const cms = await getCms();
3283
- const llm = cms.getPlugin("llm");
3284
- if (llm?.embed && savedChunks.length > 0) {
3285
- console.info(`${KB_LOG} starting embedding pass`, { slug, chunkCount: savedChunks.length });
3286
- const embedBound = (text2) => llm.embed(text2);
3287
- const { written, failed } = await writeEmbeddingsConcurrent(
3288
- dataSource,
3289
- embedBound,
3290
- savedChunks,
3291
- EMBED_CONCURRENCY
3292
- );
3293
- embeddingsWritten = written;
3294
- embeddingsFailed = failed;
3295
- } else {
3296
- console.error(`${KB_LOG} embeddings skipped`, {
3297
- slug,
3298
- hasLlmPlugin: !!llm,
3299
- hasEmbed: typeof llm?.embed === "function",
3300
- chunkCount: savedChunks.length,
3301
- hint: !llm || typeof llm.embed !== "function" ? "LLM plugin missing or no embed(); check LLM_GATEWAY_URL + LLM_API_KEY so llm plugin initializes." : void 0
3302
- });
3303
- }
3304
- } catch (embErr) {
3305
- const detail = embErr instanceof Error ? embErr.message : String(embErr);
3306
- console.error(`${KB_LOG} embedding step threw before/during batch`, { slug, detail, embErr });
3603
+ const embedResult = await runEmbeddingPass(slug, savedChunks);
3604
+ if (embedResult.embedError) {
3605
+ logKbPipeline("11_response", {
3606
+ slug,
3607
+ branch: "ingest",
3608
+ documentId: docId,
3609
+ ok: false,
3610
+ embeddingError: true
3611
+ });
3307
3612
  return json(
3308
3613
  {
3309
3614
  documentId: docId,
3310
3615
  chunkCount: savedChunks.length,
3616
+ embeddingAttempted: true,
3311
3617
  created: true,
3312
3618
  linked: true,
3313
3619
  embeddingsWritten: 0,
3314
3620
  embeddingsFailed: savedChunks.length,
3315
3621
  warning: "Document saved and linked; embedding step failed.",
3316
- detail
3622
+ detail: embedResult.embedError
3317
3623
  },
3318
3624
  { status: 201 }
3319
3625
  );
3320
3626
  }
3627
+ logKbPipeline("11_response", {
3628
+ slug,
3629
+ branch: "ingest",
3630
+ documentId: docId,
3631
+ ok: true,
3632
+ chunkCount: savedChunks.length,
3633
+ embeddingsWritten: embedResult.embeddingsWritten,
3634
+ embeddingsFailed: embedResult.embeddingsFailed
3635
+ });
3321
3636
  return json({
3322
3637
  documentId: docId,
3323
3638
  chunkCount: savedChunks.length,
3639
+ embeddingAttempted: savedChunks.length > 0,
3324
3640
  created: true,
3325
3641
  linked: true,
3326
- embeddingsWritten,
3327
- embeddingsFailed
3642
+ embeddingsWritten: embedResult.embeddingsWritten,
3643
+ embeddingsFailed: embedResult.embeddingsFailed
3328
3644
  });
3329
3645
  } catch (err) {
3330
3646
  const msg = err instanceof Error ? err.message : "Failed to ingest knowledge";
3331
3647
  const name = err instanceof Error ? err.name : "";
3648
+ logKbPipeline("99_pipeline_error", { slug, errorName: name, message: msg });
3332
3649
  return json({ error: msg, errorName: name || void 0 }, { status: 500 });
3333
3650
  }
3334
3651
  },
@@ -3340,6 +3657,7 @@ function createLlmAgentKnowledgeHandlers(config) {
3340
3657
  try {
3341
3658
  const agent = await findAgentBySlug(dataSource, llmAgents, slug);
3342
3659
  if (!agent) return json({ error: "Agent not found" }, { status: 404 });
3660
+ logKbPipeline("unlink_junction", { slug, agentId: agent.id, documentId });
3343
3661
  const linkRepo = dataSource.getRepository(junction);
3344
3662
  await linkRepo.delete({ agentId: agent.id, documentId });
3345
3663
  return json({ ok: true });
@@ -3658,155 +3976,2763 @@ function createAdminRolesHandlers(config) {
3658
3976
  };
3659
3977
  }
3660
3978
 
3661
- // src/api/cms-api-handler.ts
3662
- var KNOWLEDGE_SUFFIX = "knowledge";
3663
- function matchLlmAgentKnowledgeRoute(path) {
3664
- const p = path[0] === "api" ? path.slice(1) : path;
3665
- if (p[0] !== "llm_agents" || p.length < 2) return null;
3666
- const seg1 = p[1];
3667
- if (!seg1) return null;
3668
- if (p[2] === KNOWLEDGE_SUFFIX) {
3669
- return {
3670
- slug: seg1,
3671
- documentId: p.length >= 4 ? p[3] : void 0
3672
- };
3673
- }
3674
- if (seg1.endsWith(KNOWLEDGE_SUFFIX) && seg1.length > KNOWLEDGE_SUFFIX.length) {
3675
- const slug = seg1.slice(0, -KNOWLEDGE_SUFFIX.length);
3676
- if (!slug) return null;
3677
- if (p.length === 2) return { slug, documentId: void 0 };
3678
- if (p.length === 3) return { slug, documentId: p[2] };
3679
- }
3680
- return null;
3681
- }
3682
- var DEFAULT_EXCLUDE = /* @__PURE__ */ new Set([
3683
- "users",
3684
- "password_reset_tokens",
3685
- "user_groups",
3686
- "permissions",
3687
- "comments",
3688
- "form_fields",
3689
- "configs",
3690
- "carts",
3691
- "cart_items",
3692
- "wishlists",
3693
- "wishlist_items",
3694
- "message_templates",
3695
- "llm_agent_knowledge_documents"
3696
- ]);
3697
- function createCmsApiHandler(config) {
3698
- const {
3699
- dataSource,
3700
- entityMap,
3701
- pathToModel = (s) => s,
3702
- crudResources = Object.keys(entityMap).filter((k) => !DEFAULT_EXCLUDE.has(k)),
3703
- getCms,
3704
- userAuth: userAuthConfig,
3705
- dashboard,
3706
- ecommerceAnalytics,
3707
- analytics: analyticsConfig,
3708
- upload,
3709
- blogBySlug,
3710
- formBySlug,
3711
- formSave: formSaveConfig,
3712
- formSubmission: formSubmissionConfig,
3713
- formSubmissionGetById: formSubmissionGetByIdConfig,
3714
- usersApi,
3715
- userAvatar,
3716
- userProfile,
3717
- settings: settingsConfig,
3718
- chat: chatConfig,
3719
- llmAgentKnowledge: llmAgentKnowledgeConfig,
3720
- requireEntityPermission: userRequireEntityPermission,
3721
- getSessionUser
3722
- } = config;
3723
- const requireEntityPermissionEffective = userRequireEntityPermission ?? (async (_req, entity, action) => config.json({ error: "Forbidden", reason: "entity_rbac_required", entity, action }, { status: 403 }));
3724
- const analytics = analyticsConfig ?? (getCms ? {
3725
- json: config.json,
3726
- requireAuth: async () => null,
3727
- getAnalyticsData: async (days) => {
3728
- const cms = await getCms();
3729
- const a = cms.getPlugin("analytics");
3730
- if (!a?.getAnalyticsData) throw new Error("Analytics not configured");
3731
- return a.getAnalyticsData(days);
3732
- },
3733
- getPropertyId: () => ({ currentViewId: process.env.GOOGLE_ANALYTICS_VIEW_ID }),
3734
- getPermissions: () => ({
3735
- serviceAccountEmail: process.env.GOOGLE_ANALYTICS_CLIENT_EMAIL,
3736
- currentViewId: process.env.GOOGLE_ANALYTICS_VIEW_ID
3737
- })
3738
- } : void 0);
3739
- const userAuth = userAuthConfig && getCms && userAuthConfig.sendEmail === void 0 ? {
3740
- ...userAuthConfig,
3741
- sendEmail: async (opts) => {
3742
- const cms = await getCms();
3743
- const queue = cms.getPlugin("queue");
3744
- const companyDetails = config.getCompanyDetails ? await config.getCompanyDetails() : {};
3745
- const resetLink = typeof opts.resetLink === "string" && opts.resetLink.trim() || typeof opts.text === "string" && opts.text.trim() || (typeof opts.html === "string" ? opts.html.match(/href\s*=\s*["']([^"']+)["']/)?.[1] ?? "" : "");
3746
- const ctx = { resetLink, companyDetails };
3747
- if (queue) {
3748
- const { queueEmail: queueEmail2 } = await Promise.resolve().then(() => (init_email_queue(), email_queue_exports));
3749
- await queueEmail2(cms, { to: opts.to, templateName: "passwordReset", ctx });
3750
- return;
3751
- }
3752
- const email = cms.getPlugin("email");
3753
- if (!email?.send) return;
3754
- const rendered = email.renderTemplate("passwordReset", ctx);
3755
- await email.send({ subject: rendered.subject, html: rendered.html, text: rendered.text, to: opts.to });
3756
- }
3757
- } : userAuthConfig;
3758
- const crudOpts = {
3759
- requireAuth: config.requireAuth,
3760
- json: config.json,
3761
- requireEntityPermission: requireEntityPermissionEffective,
3762
- getCms,
3763
- ...getSessionUser ? {
3764
- getDeletedByUserId: async () => {
3765
- const u = await getSessionUser();
3766
- if (!u?.id) return null;
3767
- const n = Number(u.id);
3768
- return Number.isFinite(n) ? n : null;
3769
- }
3770
- } : {}
3771
- };
3772
- const crud = createCrudHandler(dataSource, entityMap, crudOpts);
3773
- const crudById = createCrudByIdHandler(dataSource, entityMap, crudOpts);
3774
- const mergePerm = (c) => !c ? void 0 : { ...c, requireEntityPermission: requireEntityPermissionEffective };
3775
- const adminRoles = getSessionUser && createAdminRolesHandlers({
3776
- dataSource,
3777
- entityMap,
3778
- json: config.json,
3779
- getSessionUser
3780
- });
3781
- const userAuthRouter = userAuth ? createUserAuthApiRouter(userAuth) : null;
3782
- const dashboardGet = dashboard ? createDashboardStatsHandler(mergePerm(dashboard) ?? dashboard) : null;
3783
- const ecommerceAnalyticsResolved = mergePerm(
3784
- ecommerceAnalytics ?? {
3785
- dataSource,
3786
- entityMap,
3787
- json: config.json,
3788
- requireAuth: config.requireAuth
3789
- }
3790
- );
3791
- const ecommerceAnalyticsGet = createEcommerceAnalyticsHandler(ecommerceAnalyticsResolved);
3792
- const analyticsHandlers = analytics ? createAnalyticsHandlers(analytics) : null;
3793
- const uploadMerged = upload ? {
3794
- ...mergePerm(upload) ?? upload,
3795
- dataSource: upload.dataSource ?? dataSource,
3796
- entityMap: upload.entityMap ?? entityMap
3797
- } : null;
3798
- const uploadPost = uploadMerged ? createUploadHandler(uploadMerged) : null;
3799
- const zipExtractPost = uploadMerged ? createMediaZipExtractHandler(uploadMerged) : null;
3800
- const blogBySlugGet = blogBySlug ? createBlogBySlugHandler(blogBySlug) : null;
3801
- const formBySlugGet = formBySlug ? createFormBySlugHandler(formBySlug) : null;
3802
- const formSaveHandlers = formSaveConfig ? createFormSaveHandlers(mergePerm(formSaveConfig) ?? formSaveConfig) : null;
3803
- const formSubmissionPost = formSubmissionConfig ? createFormSubmissionHandler(formSubmissionConfig) : null;
3804
- const formSubmissionGetById = formSubmissionGetByIdConfig ? createFormSubmissionGetByIdHandler(mergePerm(formSubmissionGetByIdConfig) ?? formSubmissionGetByIdConfig) : null;
3805
- const formSubmissionList = formSubmissionGetByIdConfig ? createFormSubmissionListHandler(mergePerm(formSubmissionGetByIdConfig) ?? formSubmissionGetByIdConfig) : null;
3806
- const usersApiMerged = usersApi && getCms ? {
3807
- ...usersApi,
3808
- getCms: usersApi.getCms ?? getCms,
3809
- getCompanyDetails: usersApi.getCompanyDetails ?? config.getCompanyDetails,
3979
+ // src/entities/user.entity.ts
3980
+ import { Entity as Entity4, PrimaryGeneratedColumn as PrimaryGeneratedColumn4, Column as Column4, ManyToOne as ManyToOne2, JoinColumn as JoinColumn2 } from "typeorm";
3981
+
3982
+ // src/entities/user-group.entity.ts
3983
+ import { Entity as Entity3, PrimaryGeneratedColumn as PrimaryGeneratedColumn3, Column as Column3, OneToMany } from "typeorm";
3984
+
3985
+ // src/entities/permission.entity.ts
3986
+ import { Entity as Entity2, PrimaryGeneratedColumn as PrimaryGeneratedColumn2, Column as Column2, ManyToOne, JoinColumn } from "typeorm";
3987
+ var Permission = class {
3988
+ id;
3989
+ groupId;
3990
+ entity;
3991
+ canCreate;
3992
+ canRead;
3993
+ canUpdate;
3994
+ canDelete;
3995
+ createdAt;
3996
+ updatedAt;
3997
+ deletedAt;
3998
+ deleted;
3999
+ createdBy;
4000
+ updatedBy;
4001
+ deletedBy;
4002
+ group;
4003
+ };
4004
+ __decorateClass([
4005
+ PrimaryGeneratedColumn2()
4006
+ ], Permission.prototype, "id", 2);
4007
+ __decorateClass([
4008
+ Column2("int")
4009
+ ], Permission.prototype, "groupId", 2);
4010
+ __decorateClass([
4011
+ Column2("varchar")
4012
+ ], Permission.prototype, "entity", 2);
4013
+ __decorateClass([
4014
+ Column2("boolean", { default: false })
4015
+ ], Permission.prototype, "canCreate", 2);
4016
+ __decorateClass([
4017
+ Column2("boolean", { default: false })
4018
+ ], Permission.prototype, "canRead", 2);
4019
+ __decorateClass([
4020
+ Column2("boolean", { default: false })
4021
+ ], Permission.prototype, "canUpdate", 2);
4022
+ __decorateClass([
4023
+ Column2("boolean", { default: false })
4024
+ ], Permission.prototype, "canDelete", 2);
4025
+ __decorateClass([
4026
+ Column2({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4027
+ ], Permission.prototype, "createdAt", 2);
4028
+ __decorateClass([
4029
+ Column2({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4030
+ ], Permission.prototype, "updatedAt", 2);
4031
+ __decorateClass([
4032
+ Column2({ type: "timestamp", nullable: true })
4033
+ ], Permission.prototype, "deletedAt", 2);
4034
+ __decorateClass([
4035
+ Column2("boolean", { default: false })
4036
+ ], Permission.prototype, "deleted", 2);
4037
+ __decorateClass([
4038
+ Column2("int", { nullable: true })
4039
+ ], Permission.prototype, "createdBy", 2);
4040
+ __decorateClass([
4041
+ Column2("int", { nullable: true })
4042
+ ], Permission.prototype, "updatedBy", 2);
4043
+ __decorateClass([
4044
+ Column2("int", { nullable: true })
4045
+ ], Permission.prototype, "deletedBy", 2);
4046
+ __decorateClass([
4047
+ ManyToOne(() => UserGroup, (g) => g.permissions, { onDelete: "CASCADE" }),
4048
+ JoinColumn({ name: "groupId" })
4049
+ ], Permission.prototype, "group", 2);
4050
+ Permission = __decorateClass([
4051
+ Entity2("permissions")
4052
+ ], Permission);
4053
+
4054
+ // src/entities/user-group.entity.ts
4055
+ var UserGroup = class {
4056
+ id;
4057
+ name;
4058
+ createdAt;
4059
+ updatedAt;
4060
+ deletedAt;
4061
+ deleted;
4062
+ createdBy;
4063
+ updatedBy;
4064
+ deletedBy;
4065
+ permissions;
4066
+ users;
4067
+ };
4068
+ __decorateClass([
4069
+ PrimaryGeneratedColumn3()
4070
+ ], UserGroup.prototype, "id", 2);
4071
+ __decorateClass([
4072
+ Column3("varchar", { unique: true })
4073
+ ], UserGroup.prototype, "name", 2);
4074
+ __decorateClass([
4075
+ Column3({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4076
+ ], UserGroup.prototype, "createdAt", 2);
4077
+ __decorateClass([
4078
+ Column3({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4079
+ ], UserGroup.prototype, "updatedAt", 2);
4080
+ __decorateClass([
4081
+ Column3({ type: "timestamp", nullable: true })
4082
+ ], UserGroup.prototype, "deletedAt", 2);
4083
+ __decorateClass([
4084
+ Column3("boolean", { default: false })
4085
+ ], UserGroup.prototype, "deleted", 2);
4086
+ __decorateClass([
4087
+ Column3("int", { nullable: true })
4088
+ ], UserGroup.prototype, "createdBy", 2);
4089
+ __decorateClass([
4090
+ Column3("int", { nullable: true })
4091
+ ], UserGroup.prototype, "updatedBy", 2);
4092
+ __decorateClass([
4093
+ Column3("int", { nullable: true })
4094
+ ], UserGroup.prototype, "deletedBy", 2);
4095
+ __decorateClass([
4096
+ OneToMany(() => Permission, (p) => p.group)
4097
+ ], UserGroup.prototype, "permissions", 2);
4098
+ __decorateClass([
4099
+ OneToMany(() => User, (u) => u.group)
4100
+ ], UserGroup.prototype, "users", 2);
4101
+ UserGroup = __decorateClass([
4102
+ Entity3("user_groups")
4103
+ ], UserGroup);
4104
+
4105
+ // src/entities/user.entity.ts
4106
+ var User = class {
4107
+ id;
4108
+ name;
4109
+ email;
4110
+ phone;
4111
+ phoneVerifiedAt;
4112
+ emailVerifiedAt;
4113
+ password;
4114
+ blocked;
4115
+ adminAccess;
4116
+ groupId;
4117
+ createdAt;
4118
+ updatedAt;
4119
+ deletedAt;
4120
+ deleted;
4121
+ createdBy;
4122
+ updatedBy;
4123
+ deletedBy;
4124
+ group;
4125
+ };
4126
+ __decorateClass([
4127
+ PrimaryGeneratedColumn4()
4128
+ ], User.prototype, "id", 2);
4129
+ __decorateClass([
4130
+ Column4("varchar")
4131
+ ], User.prototype, "name", 2);
4132
+ __decorateClass([
4133
+ Column4("varchar", { unique: true })
4134
+ ], User.prototype, "email", 2);
4135
+ __decorateClass([
4136
+ Column4("varchar", { nullable: true })
4137
+ ], User.prototype, "phone", 2);
4138
+ __decorateClass([
4139
+ Column4({ type: "timestamp", nullable: true })
4140
+ ], User.prototype, "phoneVerifiedAt", 2);
4141
+ __decorateClass([
4142
+ Column4({ type: "timestamp", nullable: true })
4143
+ ], User.prototype, "emailVerifiedAt", 2);
4144
+ __decorateClass([
4145
+ Column4("varchar", { nullable: true })
4146
+ ], User.prototype, "password", 2);
4147
+ __decorateClass([
4148
+ Column4("boolean", { default: false })
4149
+ ], User.prototype, "blocked", 2);
4150
+ __decorateClass([
4151
+ Column4("boolean", { default: false })
4152
+ ], User.prototype, "adminAccess", 2);
4153
+ __decorateClass([
4154
+ Column4("int", { nullable: true })
4155
+ ], User.prototype, "groupId", 2);
4156
+ __decorateClass([
4157
+ Column4({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4158
+ ], User.prototype, "createdAt", 2);
4159
+ __decorateClass([
4160
+ Column4({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4161
+ ], User.prototype, "updatedAt", 2);
4162
+ __decorateClass([
4163
+ Column4({ type: "timestamp", nullable: true })
4164
+ ], User.prototype, "deletedAt", 2);
4165
+ __decorateClass([
4166
+ Column4("boolean", { default: false })
4167
+ ], User.prototype, "deleted", 2);
4168
+ __decorateClass([
4169
+ Column4("int", { nullable: true })
4170
+ ], User.prototype, "createdBy", 2);
4171
+ __decorateClass([
4172
+ Column4("int", { nullable: true })
4173
+ ], User.prototype, "updatedBy", 2);
4174
+ __decorateClass([
4175
+ Column4("int", { nullable: true })
4176
+ ], User.prototype, "deletedBy", 2);
4177
+ __decorateClass([
4178
+ ManyToOne2(() => UserGroup, (g) => g.users, { onDelete: "SET NULL" }),
4179
+ JoinColumn2({ name: "groupId" })
4180
+ ], User.prototype, "group", 2);
4181
+ User = __decorateClass([
4182
+ Entity4("users")
4183
+ ], User);
4184
+
4185
+ // src/entities/otp-challenge.entity.ts
4186
+ import { Entity as Entity5, PrimaryGeneratedColumn as PrimaryGeneratedColumn5, Column as Column5, Index } from "typeorm";
4187
+ var OtpChallenge = class {
4188
+ id;
4189
+ purpose;
4190
+ channel;
4191
+ identifier;
4192
+ codeHash;
4193
+ expiresAt;
4194
+ attempts;
4195
+ consumedAt;
4196
+ createdAt;
4197
+ };
4198
+ __decorateClass([
4199
+ PrimaryGeneratedColumn5()
4200
+ ], OtpChallenge.prototype, "id", 2);
4201
+ __decorateClass([
4202
+ Column5("varchar")
4203
+ ], OtpChallenge.prototype, "purpose", 2);
4204
+ __decorateClass([
4205
+ Column5("varchar")
4206
+ ], OtpChallenge.prototype, "channel", 2);
4207
+ __decorateClass([
4208
+ Column5("varchar")
4209
+ ], OtpChallenge.prototype, "identifier", 2);
4210
+ __decorateClass([
4211
+ Column5("varchar")
4212
+ ], OtpChallenge.prototype, "codeHash", 2);
4213
+ __decorateClass([
4214
+ Column5({ type: "timestamp" })
4215
+ ], OtpChallenge.prototype, "expiresAt", 2);
4216
+ __decorateClass([
4217
+ Column5("int", { default: 0 })
4218
+ ], OtpChallenge.prototype, "attempts", 2);
4219
+ __decorateClass([
4220
+ Column5({ type: "timestamp", nullable: true })
4221
+ ], OtpChallenge.prototype, "consumedAt", 2);
4222
+ __decorateClass([
4223
+ Column5({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4224
+ ], OtpChallenge.prototype, "createdAt", 2);
4225
+ OtpChallenge = __decorateClass([
4226
+ Entity5("otp_challenges"),
4227
+ Index(["purpose", "identifier"])
4228
+ ], OtpChallenge);
4229
+
4230
+ // src/entities/password-reset-token.entity.ts
4231
+ import { Entity as Entity6, PrimaryGeneratedColumn as PrimaryGeneratedColumn6, Column as Column6 } from "typeorm";
4232
+ var PasswordResetToken = class {
4233
+ id;
4234
+ email;
4235
+ token;
4236
+ expiresAt;
4237
+ createdAt;
4238
+ };
4239
+ __decorateClass([
4240
+ PrimaryGeneratedColumn6()
4241
+ ], PasswordResetToken.prototype, "id", 2);
4242
+ __decorateClass([
4243
+ Column6("varchar")
4244
+ ], PasswordResetToken.prototype, "email", 2);
4245
+ __decorateClass([
4246
+ Column6("varchar", { unique: true })
4247
+ ], PasswordResetToken.prototype, "token", 2);
4248
+ __decorateClass([
4249
+ Column6({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4250
+ ], PasswordResetToken.prototype, "expiresAt", 2);
4251
+ __decorateClass([
4252
+ Column6({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4253
+ ], PasswordResetToken.prototype, "createdAt", 2);
4254
+ PasswordResetToken = __decorateClass([
4255
+ Entity6("password_reset_tokens")
4256
+ ], PasswordResetToken);
4257
+
4258
+ // src/entities/blog.entity.ts
4259
+ import {
4260
+ Entity as Entity11,
4261
+ PrimaryGeneratedColumn as PrimaryGeneratedColumn11,
4262
+ Column as Column11,
4263
+ ManyToOne as ManyToOne4,
4264
+ OneToMany as OneToMany4,
4265
+ ManyToMany as ManyToMany2,
4266
+ JoinTable,
4267
+ JoinColumn as JoinColumn4
4268
+ } from "typeorm";
4269
+
4270
+ // src/entities/category.entity.ts
4271
+ import { Entity as Entity7, PrimaryGeneratedColumn as PrimaryGeneratedColumn7, Column as Column7, OneToMany as OneToMany2 } from "typeorm";
4272
+ var Category = class {
4273
+ id;
4274
+ name;
4275
+ createdAt;
4276
+ updatedAt;
4277
+ deletedAt;
4278
+ deleted;
4279
+ createdBy;
4280
+ updatedBy;
4281
+ deletedBy;
4282
+ blogs;
4283
+ };
4284
+ __decorateClass([
4285
+ PrimaryGeneratedColumn7()
4286
+ ], Category.prototype, "id", 2);
4287
+ __decorateClass([
4288
+ Column7("varchar", { unique: true })
4289
+ ], Category.prototype, "name", 2);
4290
+ __decorateClass([
4291
+ Column7({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4292
+ ], Category.prototype, "createdAt", 2);
4293
+ __decorateClass([
4294
+ Column7({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4295
+ ], Category.prototype, "updatedAt", 2);
4296
+ __decorateClass([
4297
+ Column7({ type: "timestamp", nullable: true })
4298
+ ], Category.prototype, "deletedAt", 2);
4299
+ __decorateClass([
4300
+ Column7("boolean", { default: false })
4301
+ ], Category.prototype, "deleted", 2);
4302
+ __decorateClass([
4303
+ Column7("int", { nullable: true })
4304
+ ], Category.prototype, "createdBy", 2);
4305
+ __decorateClass([
4306
+ Column7("int", { nullable: true })
4307
+ ], Category.prototype, "updatedBy", 2);
4308
+ __decorateClass([
4309
+ Column7("int", { nullable: true })
4310
+ ], Category.prototype, "deletedBy", 2);
4311
+ __decorateClass([
4312
+ OneToMany2("Blog", "category")
4313
+ ], Category.prototype, "blogs", 2);
4314
+ Category = __decorateClass([
4315
+ Entity7("categories")
4316
+ ], Category);
4317
+
4318
+ // src/entities/seo.entity.ts
4319
+ import { Entity as Entity8, PrimaryGeneratedColumn as PrimaryGeneratedColumn8, Column as Column8, OneToMany as OneToMany3 } from "typeorm";
4320
+ var Seo = class {
4321
+ id;
4322
+ title;
4323
+ description;
4324
+ keywords;
4325
+ ogTitle;
4326
+ ogDescription;
4327
+ ogImage;
4328
+ slug;
4329
+ createdAt;
4330
+ updatedAt;
4331
+ deletedAt;
4332
+ deleted;
4333
+ createdBy;
4334
+ updatedBy;
4335
+ deletedBy;
4336
+ blogs;
4337
+ };
4338
+ __decorateClass([
4339
+ PrimaryGeneratedColumn8()
4340
+ ], Seo.prototype, "id", 2);
4341
+ __decorateClass([
4342
+ Column8("varchar", { nullable: true })
4343
+ ], Seo.prototype, "title", 2);
4344
+ __decorateClass([
4345
+ Column8("varchar", { nullable: true })
4346
+ ], Seo.prototype, "description", 2);
4347
+ __decorateClass([
4348
+ Column8("varchar", { nullable: true })
4349
+ ], Seo.prototype, "keywords", 2);
4350
+ __decorateClass([
4351
+ Column8("varchar", { nullable: true })
4352
+ ], Seo.prototype, "ogTitle", 2);
4353
+ __decorateClass([
4354
+ Column8("varchar", { nullable: true })
4355
+ ], Seo.prototype, "ogDescription", 2);
4356
+ __decorateClass([
4357
+ Column8("varchar", { nullable: true })
4358
+ ], Seo.prototype, "ogImage", 2);
4359
+ __decorateClass([
4360
+ Column8("varchar", { unique: true })
4361
+ ], Seo.prototype, "slug", 2);
4362
+ __decorateClass([
4363
+ Column8({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4364
+ ], Seo.prototype, "createdAt", 2);
4365
+ __decorateClass([
4366
+ Column8({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4367
+ ], Seo.prototype, "updatedAt", 2);
4368
+ __decorateClass([
4369
+ Column8({ type: "timestamp", nullable: true })
4370
+ ], Seo.prototype, "deletedAt", 2);
4371
+ __decorateClass([
4372
+ Column8("boolean", { default: false })
4373
+ ], Seo.prototype, "deleted", 2);
4374
+ __decorateClass([
4375
+ Column8("int", { nullable: true })
4376
+ ], Seo.prototype, "createdBy", 2);
4377
+ __decorateClass([
4378
+ Column8("int", { nullable: true })
4379
+ ], Seo.prototype, "updatedBy", 2);
4380
+ __decorateClass([
4381
+ Column8("int", { nullable: true })
4382
+ ], Seo.prototype, "deletedBy", 2);
4383
+ __decorateClass([
4384
+ OneToMany3(() => Blog, (blog) => blog.seo)
4385
+ ], Seo.prototype, "blogs", 2);
4386
+ Seo = __decorateClass([
4387
+ Entity8("seos")
4388
+ ], Seo);
4389
+
4390
+ // src/entities/comment.entity.ts
4391
+ import { Entity as Entity9, PrimaryGeneratedColumn as PrimaryGeneratedColumn9, Column as Column9, ManyToOne as ManyToOne3, JoinColumn as JoinColumn3 } from "typeorm";
4392
+ var Comment = class {
4393
+ id;
4394
+ content;
4395
+ blogId;
4396
+ authorId;
4397
+ createdAt;
4398
+ updatedAt;
4399
+ deletedAt;
4400
+ deleted;
4401
+ createdBy;
4402
+ updatedBy;
4403
+ deletedBy;
4404
+ author;
4405
+ blog;
4406
+ };
4407
+ __decorateClass([
4408
+ PrimaryGeneratedColumn9()
4409
+ ], Comment.prototype, "id", 2);
4410
+ __decorateClass([
4411
+ Column9("text")
4412
+ ], Comment.prototype, "content", 2);
4413
+ __decorateClass([
4414
+ Column9("int")
4415
+ ], Comment.prototype, "blogId", 2);
4416
+ __decorateClass([
4417
+ Column9("int")
4418
+ ], Comment.prototype, "authorId", 2);
4419
+ __decorateClass([
4420
+ Column9({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4421
+ ], Comment.prototype, "createdAt", 2);
4422
+ __decorateClass([
4423
+ Column9({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4424
+ ], Comment.prototype, "updatedAt", 2);
4425
+ __decorateClass([
4426
+ Column9({ type: "timestamp", nullable: true })
4427
+ ], Comment.prototype, "deletedAt", 2);
4428
+ __decorateClass([
4429
+ Column9("boolean", { default: false })
4430
+ ], Comment.prototype, "deleted", 2);
4431
+ __decorateClass([
4432
+ Column9("int", { nullable: true })
4433
+ ], Comment.prototype, "createdBy", 2);
4434
+ __decorateClass([
4435
+ Column9("int", { nullable: true })
4436
+ ], Comment.prototype, "updatedBy", 2);
4437
+ __decorateClass([
4438
+ Column9("int", { nullable: true })
4439
+ ], Comment.prototype, "deletedBy", 2);
4440
+ __decorateClass([
4441
+ ManyToOne3(() => User, { onDelete: "CASCADE" }),
4442
+ JoinColumn3({ name: "authorId" })
4443
+ ], Comment.prototype, "author", 2);
4444
+ __decorateClass([
4445
+ ManyToOne3(() => Blog, (b) => b.comments, { onDelete: "CASCADE" }),
4446
+ JoinColumn3({ name: "blogId" })
4447
+ ], Comment.prototype, "blog", 2);
4448
+ Comment = __decorateClass([
4449
+ Entity9("comments")
4450
+ ], Comment);
4451
+
4452
+ // src/entities/tag.entity.ts
4453
+ import { Entity as Entity10, PrimaryGeneratedColumn as PrimaryGeneratedColumn10, Column as Column10, ManyToMany } from "typeorm";
4454
+ var Tag = class {
4455
+ id;
4456
+ name;
4457
+ createdAt;
4458
+ updatedAt;
4459
+ deletedAt;
4460
+ deleted;
4461
+ createdBy;
4462
+ updatedBy;
4463
+ deletedBy;
4464
+ blogs;
4465
+ };
4466
+ __decorateClass([
4467
+ PrimaryGeneratedColumn10()
4468
+ ], Tag.prototype, "id", 2);
4469
+ __decorateClass([
4470
+ Column10("varchar", { unique: true })
4471
+ ], Tag.prototype, "name", 2);
4472
+ __decorateClass([
4473
+ Column10({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4474
+ ], Tag.prototype, "createdAt", 2);
4475
+ __decorateClass([
4476
+ Column10({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4477
+ ], Tag.prototype, "updatedAt", 2);
4478
+ __decorateClass([
4479
+ Column10({ type: "timestamp", nullable: true })
4480
+ ], Tag.prototype, "deletedAt", 2);
4481
+ __decorateClass([
4482
+ Column10("boolean", { default: false })
4483
+ ], Tag.prototype, "deleted", 2);
4484
+ __decorateClass([
4485
+ Column10("int", { nullable: true })
4486
+ ], Tag.prototype, "createdBy", 2);
4487
+ __decorateClass([
4488
+ Column10("int", { nullable: true })
4489
+ ], Tag.prototype, "updatedBy", 2);
4490
+ __decorateClass([
4491
+ Column10("int", { nullable: true })
4492
+ ], Tag.prototype, "deletedBy", 2);
4493
+ __decorateClass([
4494
+ ManyToMany(() => Blog, (blog) => blog.tags)
4495
+ ], Tag.prototype, "blogs", 2);
4496
+ Tag = __decorateClass([
4497
+ Entity10("tags")
4498
+ ], Tag);
4499
+
4500
+ // src/entities/blog.entity.ts
4501
+ var Blog = class {
4502
+ id;
4503
+ title;
4504
+ content;
4505
+ coverImage;
4506
+ authorId;
4507
+ categoryId;
4508
+ seoId;
4509
+ published;
4510
+ createdAt;
4511
+ updatedAt;
4512
+ deletedAt;
4513
+ deleted;
4514
+ createdBy;
4515
+ updatedBy;
4516
+ deletedBy;
4517
+ slug;
4518
+ author;
4519
+ category;
4520
+ seo;
4521
+ comments;
4522
+ tags;
4523
+ };
4524
+ __decorateClass([
4525
+ PrimaryGeneratedColumn11()
4526
+ ], Blog.prototype, "id", 2);
4527
+ __decorateClass([
4528
+ Column11("varchar")
4529
+ ], Blog.prototype, "title", 2);
4530
+ __decorateClass([
4531
+ Column11("text")
4532
+ ], Blog.prototype, "content", 2);
4533
+ __decorateClass([
4534
+ Column11("varchar", { nullable: true })
4535
+ ], Blog.prototype, "coverImage", 2);
4536
+ __decorateClass([
4537
+ Column11("int")
4538
+ ], Blog.prototype, "authorId", 2);
4539
+ __decorateClass([
4540
+ Column11("int", { nullable: true })
4541
+ ], Blog.prototype, "categoryId", 2);
4542
+ __decorateClass([
4543
+ Column11("int", { nullable: true })
4544
+ ], Blog.prototype, "seoId", 2);
4545
+ __decorateClass([
4546
+ Column11("boolean", { default: false })
4547
+ ], Blog.prototype, "published", 2);
4548
+ __decorateClass([
4549
+ Column11({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4550
+ ], Blog.prototype, "createdAt", 2);
4551
+ __decorateClass([
4552
+ Column11({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4553
+ ], Blog.prototype, "updatedAt", 2);
4554
+ __decorateClass([
4555
+ Column11({ type: "timestamp", nullable: true })
4556
+ ], Blog.prototype, "deletedAt", 2);
4557
+ __decorateClass([
4558
+ Column11("boolean", { default: false })
4559
+ ], Blog.prototype, "deleted", 2);
4560
+ __decorateClass([
4561
+ Column11("int", { nullable: true })
4562
+ ], Blog.prototype, "createdBy", 2);
4563
+ __decorateClass([
4564
+ Column11("int", { nullable: true })
4565
+ ], Blog.prototype, "updatedBy", 2);
4566
+ __decorateClass([
4567
+ Column11("int", { nullable: true })
4568
+ ], Blog.prototype, "deletedBy", 2);
4569
+ __decorateClass([
4570
+ Column11("varchar", { unique: true })
4571
+ ], Blog.prototype, "slug", 2);
4572
+ __decorateClass([
4573
+ ManyToOne4(() => User, { onDelete: "CASCADE" }),
4574
+ JoinColumn4({ name: "authorId" })
4575
+ ], Blog.prototype, "author", 2);
4576
+ __decorateClass([
4577
+ ManyToOne4(() => Category, (c) => c.blogs, { onDelete: "SET NULL" }),
4578
+ JoinColumn4({ name: "categoryId" })
4579
+ ], Blog.prototype, "category", 2);
4580
+ __decorateClass([
4581
+ ManyToOne4(() => Seo, (s) => s.blogs, { onDelete: "SET NULL" }),
4582
+ JoinColumn4({ name: "seoId" })
4583
+ ], Blog.prototype, "seo", 2);
4584
+ __decorateClass([
4585
+ OneToMany4(() => Comment, (c) => c.blog)
4586
+ ], Blog.prototype, "comments", 2);
4587
+ __decorateClass([
4588
+ ManyToMany2(() => Tag, (t) => t.blogs),
4589
+ JoinTable({
4590
+ name: "blog_tags",
4591
+ joinColumn: { name: "blogId", referencedColumnName: "id" },
4592
+ inverseJoinColumn: { name: "tagId", referencedColumnName: "id" }
4593
+ })
4594
+ ], Blog.prototype, "tags", 2);
4595
+ Blog = __decorateClass([
4596
+ Entity11("blogs")
4597
+ ], Blog);
4598
+
4599
+ // src/entities/contact.entity.ts
4600
+ import { Entity as Entity20, PrimaryGeneratedColumn as PrimaryGeneratedColumn20, Column as Column20, OneToMany as OneToMany8, ManyToOne as ManyToOne12, JoinColumn as JoinColumn12 } from "typeorm";
4601
+
4602
+ // src/entities/form-submission.entity.ts
4603
+ import { Entity as Entity14, PrimaryGeneratedColumn as PrimaryGeneratedColumn14, Column as Column14, ManyToOne as ManyToOne6, JoinColumn as JoinColumn6 } from "typeorm";
4604
+
4605
+ // src/entities/form.entity.ts
4606
+ import { Entity as Entity13, PrimaryGeneratedColumn as PrimaryGeneratedColumn13, Column as Column13, OneToMany as OneToMany5 } from "typeorm";
4607
+
4608
+ // src/entities/form-field.entity.ts
4609
+ import { Entity as Entity12, PrimaryGeneratedColumn as PrimaryGeneratedColumn12, Column as Column12, ManyToOne as ManyToOne5, JoinColumn as JoinColumn5 } from "typeorm";
4610
+ var FormField = class {
4611
+ id;
4612
+ formId;
4613
+ label;
4614
+ type;
4615
+ placeholder;
4616
+ options;
4617
+ required;
4618
+ validation;
4619
+ order;
4620
+ groupId;
4621
+ columnWidth;
4622
+ createdAt;
4623
+ updatedAt;
4624
+ deletedAt;
4625
+ deleted;
4626
+ createdBy;
4627
+ updatedBy;
4628
+ deletedBy;
4629
+ form;
4630
+ };
4631
+ __decorateClass([
4632
+ PrimaryGeneratedColumn12()
4633
+ ], FormField.prototype, "id", 2);
4634
+ __decorateClass([
4635
+ Column12("int")
4636
+ ], FormField.prototype, "formId", 2);
4637
+ __decorateClass([
4638
+ Column12("varchar")
4639
+ ], FormField.prototype, "label", 2);
4640
+ __decorateClass([
4641
+ Column12("varchar")
4642
+ ], FormField.prototype, "type", 2);
4643
+ __decorateClass([
4644
+ Column12("varchar", { nullable: true })
4645
+ ], FormField.prototype, "placeholder", 2);
4646
+ __decorateClass([
4647
+ Column12("varchar", { nullable: true })
4648
+ ], FormField.prototype, "options", 2);
4649
+ __decorateClass([
4650
+ Column12("boolean", { default: false })
4651
+ ], FormField.prototype, "required", 2);
4652
+ __decorateClass([
4653
+ Column12("varchar", { nullable: true })
4654
+ ], FormField.prototype, "validation", 2);
4655
+ __decorateClass([
4656
+ Column12("int")
4657
+ ], FormField.prototype, "order", 2);
4658
+ __decorateClass([
4659
+ Column12("int", { default: 1 })
4660
+ ], FormField.prototype, "groupId", 2);
4661
+ __decorateClass([
4662
+ Column12("int", { default: 12 })
4663
+ ], FormField.prototype, "columnWidth", 2);
4664
+ __decorateClass([
4665
+ Column12({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4666
+ ], FormField.prototype, "createdAt", 2);
4667
+ __decorateClass([
4668
+ Column12({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4669
+ ], FormField.prototype, "updatedAt", 2);
4670
+ __decorateClass([
4671
+ Column12({ type: "timestamp", nullable: true })
4672
+ ], FormField.prototype, "deletedAt", 2);
4673
+ __decorateClass([
4674
+ Column12("boolean", { default: false })
4675
+ ], FormField.prototype, "deleted", 2);
4676
+ __decorateClass([
4677
+ Column12("int", { nullable: true })
4678
+ ], FormField.prototype, "createdBy", 2);
4679
+ __decorateClass([
4680
+ Column12("int", { nullable: true })
4681
+ ], FormField.prototype, "updatedBy", 2);
4682
+ __decorateClass([
4683
+ Column12("int", { nullable: true })
4684
+ ], FormField.prototype, "deletedBy", 2);
4685
+ __decorateClass([
4686
+ ManyToOne5(() => Form, (f) => f.fields, { onDelete: "CASCADE" }),
4687
+ JoinColumn5({ name: "formId" })
4688
+ ], FormField.prototype, "form", 2);
4689
+ FormField = __decorateClass([
4690
+ Entity12("form_fields")
4691
+ ], FormField);
4692
+
4693
+ // src/entities/form.entity.ts
4694
+ var Form = class {
4695
+ id;
4696
+ name;
4697
+ description;
4698
+ campaign;
4699
+ slug;
4700
+ published;
4701
+ createdAt;
4702
+ updatedAt;
4703
+ deletedAt;
4704
+ deleted;
4705
+ createdBy;
4706
+ updatedBy;
4707
+ deletedBy;
4708
+ fields;
4709
+ submissions;
4710
+ };
4711
+ __decorateClass([
4712
+ PrimaryGeneratedColumn13()
4713
+ ], Form.prototype, "id", 2);
4714
+ __decorateClass([
4715
+ Column13("varchar")
4716
+ ], Form.prototype, "name", 2);
4717
+ __decorateClass([
4718
+ Column13("text", { nullable: true })
4719
+ ], Form.prototype, "description", 2);
4720
+ __decorateClass([
4721
+ Column13("varchar", { nullable: true })
4722
+ ], Form.prototype, "campaign", 2);
4723
+ __decorateClass([
4724
+ Column13("varchar", { unique: true })
4725
+ ], Form.prototype, "slug", 2);
4726
+ __decorateClass([
4727
+ Column13("boolean", { default: false })
4728
+ ], Form.prototype, "published", 2);
4729
+ __decorateClass([
4730
+ Column13({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4731
+ ], Form.prototype, "createdAt", 2);
4732
+ __decorateClass([
4733
+ Column13({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4734
+ ], Form.prototype, "updatedAt", 2);
4735
+ __decorateClass([
4736
+ Column13({ type: "timestamp", nullable: true })
4737
+ ], Form.prototype, "deletedAt", 2);
4738
+ __decorateClass([
4739
+ Column13("boolean", { default: false })
4740
+ ], Form.prototype, "deleted", 2);
4741
+ __decorateClass([
4742
+ Column13("int", { nullable: true })
4743
+ ], Form.prototype, "createdBy", 2);
4744
+ __decorateClass([
4745
+ Column13("int", { nullable: true })
4746
+ ], Form.prototype, "updatedBy", 2);
4747
+ __decorateClass([
4748
+ Column13("int", { nullable: true })
4749
+ ], Form.prototype, "deletedBy", 2);
4750
+ __decorateClass([
4751
+ OneToMany5(() => FormField, (f) => f.form)
4752
+ ], Form.prototype, "fields", 2);
4753
+ __decorateClass([
4754
+ OneToMany5(() => FormSubmission, (s) => s.form)
4755
+ ], Form.prototype, "submissions", 2);
4756
+ Form = __decorateClass([
4757
+ Entity13("forms")
4758
+ ], Form);
4759
+
4760
+ // src/entities/form-submission.entity.ts
4761
+ var FormSubmission = class {
4762
+ id;
4763
+ formId;
4764
+ contactId;
4765
+ data;
4766
+ ipAddress;
4767
+ userAgent;
4768
+ createdAt;
4769
+ updatedAt;
4770
+ form;
4771
+ contact;
4772
+ };
4773
+ __decorateClass([
4774
+ PrimaryGeneratedColumn14()
4775
+ ], FormSubmission.prototype, "id", 2);
4776
+ __decorateClass([
4777
+ Column14("int")
4778
+ ], FormSubmission.prototype, "formId", 2);
4779
+ __decorateClass([
4780
+ Column14("int", { nullable: true })
4781
+ ], FormSubmission.prototype, "contactId", 2);
4782
+ __decorateClass([
4783
+ Column14("jsonb")
4784
+ ], FormSubmission.prototype, "data", 2);
4785
+ __decorateClass([
4786
+ Column14("varchar", { nullable: true })
4787
+ ], FormSubmission.prototype, "ipAddress", 2);
4788
+ __decorateClass([
4789
+ Column14("varchar", { nullable: true })
4790
+ ], FormSubmission.prototype, "userAgent", 2);
4791
+ __decorateClass([
4792
+ Column14({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4793
+ ], FormSubmission.prototype, "createdAt", 2);
4794
+ __decorateClass([
4795
+ Column14({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4796
+ ], FormSubmission.prototype, "updatedAt", 2);
4797
+ __decorateClass([
4798
+ ManyToOne6(() => Form, (f) => f.submissions, { onDelete: "CASCADE" }),
4799
+ JoinColumn6({ name: "formId" })
4800
+ ], FormSubmission.prototype, "form", 2);
4801
+ __decorateClass([
4802
+ ManyToOne6(() => Contact, (c) => c.form_submissions, { onDelete: "SET NULL" }),
4803
+ JoinColumn6({ name: "contactId" })
4804
+ ], FormSubmission.prototype, "contact", 2);
4805
+ FormSubmission = __decorateClass([
4806
+ Entity14("form_submissions")
4807
+ ], FormSubmission);
4808
+
4809
+ // src/entities/address.entity.ts
4810
+ import { Entity as Entity15, PrimaryGeneratedColumn as PrimaryGeneratedColumn15, Column as Column15, ManyToOne as ManyToOne7, JoinColumn as JoinColumn7 } from "typeorm";
4811
+ var Address = class {
4812
+ id;
4813
+ contactId;
4814
+ tag;
4815
+ line1;
4816
+ line2;
4817
+ city;
4818
+ state;
4819
+ postalCode;
4820
+ country;
4821
+ createdAt;
4822
+ updatedAt;
4823
+ contact;
4824
+ };
4825
+ __decorateClass([
4826
+ PrimaryGeneratedColumn15()
4827
+ ], Address.prototype, "id", 2);
4828
+ __decorateClass([
4829
+ Column15("int")
4830
+ ], Address.prototype, "contactId", 2);
4831
+ __decorateClass([
4832
+ Column15("varchar", { nullable: true })
4833
+ ], Address.prototype, "tag", 2);
4834
+ __decorateClass([
4835
+ Column15("varchar", { nullable: true })
4836
+ ], Address.prototype, "line1", 2);
4837
+ __decorateClass([
4838
+ Column15("varchar", { nullable: true })
4839
+ ], Address.prototype, "line2", 2);
4840
+ __decorateClass([
4841
+ Column15("varchar", { nullable: true })
4842
+ ], Address.prototype, "city", 2);
4843
+ __decorateClass([
4844
+ Column15("varchar", { nullable: true })
4845
+ ], Address.prototype, "state", 2);
4846
+ __decorateClass([
4847
+ Column15("varchar", { nullable: true })
4848
+ ], Address.prototype, "postalCode", 2);
4849
+ __decorateClass([
4850
+ Column15("varchar", { nullable: true })
4851
+ ], Address.prototype, "country", 2);
4852
+ __decorateClass([
4853
+ Column15({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4854
+ ], Address.prototype, "createdAt", 2);
4855
+ __decorateClass([
4856
+ Column15({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4857
+ ], Address.prototype, "updatedAt", 2);
4858
+ __decorateClass([
4859
+ ManyToOne7(() => Contact, (c) => c.addresses, { onDelete: "CASCADE" }),
4860
+ JoinColumn7({ name: "contactId" })
4861
+ ], Address.prototype, "contact", 2);
4862
+ Address = __decorateClass([
4863
+ Entity15("addresses")
4864
+ ], Address);
4865
+
4866
+ // src/entities/order.entity.ts
4867
+ import { Entity as Entity16, PrimaryGeneratedColumn as PrimaryGeneratedColumn16, Column as Column16, ManyToOne as ManyToOne8, OneToMany as OneToMany6, JoinColumn as JoinColumn8 } from "typeorm";
4868
+ var Order = class {
4869
+ id;
4870
+ orderNumber;
4871
+ orderKind;
4872
+ parentOrderId;
4873
+ contactId;
4874
+ billingAddressId;
4875
+ shippingAddressId;
4876
+ status;
4877
+ subtotal;
4878
+ tax;
4879
+ discount;
4880
+ total;
4881
+ currency;
4882
+ metadata;
4883
+ createdAt;
4884
+ updatedAt;
4885
+ deletedAt;
4886
+ deleted;
4887
+ createdBy;
4888
+ updatedBy;
4889
+ deletedBy;
4890
+ parentOrder;
4891
+ children;
4892
+ contact;
4893
+ billingAddress;
4894
+ shippingAddress;
4895
+ items;
4896
+ payments;
4897
+ };
4898
+ __decorateClass([
4899
+ PrimaryGeneratedColumn16()
4900
+ ], Order.prototype, "id", 2);
4901
+ __decorateClass([
4902
+ Column16("varchar", { unique: true })
4903
+ ], Order.prototype, "orderNumber", 2);
4904
+ __decorateClass([
4905
+ Column16("varchar", { default: "sale" })
4906
+ ], Order.prototype, "orderKind", 2);
4907
+ __decorateClass([
4908
+ Column16("int", { nullable: true })
4909
+ ], Order.prototype, "parentOrderId", 2);
4910
+ __decorateClass([
4911
+ Column16("int")
4912
+ ], Order.prototype, "contactId", 2);
4913
+ __decorateClass([
4914
+ Column16("int", { nullable: true })
4915
+ ], Order.prototype, "billingAddressId", 2);
4916
+ __decorateClass([
4917
+ Column16("int", { nullable: true })
4918
+ ], Order.prototype, "shippingAddressId", 2);
4919
+ __decorateClass([
4920
+ Column16("varchar", { default: "pending" })
4921
+ ], Order.prototype, "status", 2);
4922
+ __decorateClass([
4923
+ Column16("decimal", { precision: 12, scale: 2, default: 0 })
4924
+ ], Order.prototype, "subtotal", 2);
4925
+ __decorateClass([
4926
+ Column16("decimal", { precision: 12, scale: 2, default: 0 })
4927
+ ], Order.prototype, "tax", 2);
4928
+ __decorateClass([
4929
+ Column16("decimal", { precision: 12, scale: 2, default: 0 })
4930
+ ], Order.prototype, "discount", 2);
4931
+ __decorateClass([
4932
+ Column16("decimal", { precision: 12, scale: 2, default: 0 })
4933
+ ], Order.prototype, "total", 2);
4934
+ __decorateClass([
4935
+ Column16("varchar", { default: "INR" })
4936
+ ], Order.prototype, "currency", 2);
4937
+ __decorateClass([
4938
+ Column16("jsonb", { nullable: true })
4939
+ ], Order.prototype, "metadata", 2);
4940
+ __decorateClass([
4941
+ Column16({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4942
+ ], Order.prototype, "createdAt", 2);
4943
+ __decorateClass([
4944
+ Column16({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
4945
+ ], Order.prototype, "updatedAt", 2);
4946
+ __decorateClass([
4947
+ Column16({ type: "timestamp", nullable: true })
4948
+ ], Order.prototype, "deletedAt", 2);
4949
+ __decorateClass([
4950
+ Column16("boolean", { default: false })
4951
+ ], Order.prototype, "deleted", 2);
4952
+ __decorateClass([
4953
+ Column16("int", { nullable: true })
4954
+ ], Order.prototype, "createdBy", 2);
4955
+ __decorateClass([
4956
+ Column16("int", { nullable: true })
4957
+ ], Order.prototype, "updatedBy", 2);
4958
+ __decorateClass([
4959
+ Column16("int", { nullable: true })
4960
+ ], Order.prototype, "deletedBy", 2);
4961
+ __decorateClass([
4962
+ ManyToOne8(() => Order, (o) => o.children, { nullable: true, onDelete: "SET NULL" }),
4963
+ JoinColumn8({ name: "parentOrderId" })
4964
+ ], Order.prototype, "parentOrder", 2);
4965
+ __decorateClass([
4966
+ OneToMany6(() => Order, (o) => o.parentOrder)
4967
+ ], Order.prototype, "children", 2);
4968
+ __decorateClass([
4969
+ ManyToOne8(() => Contact, { onDelete: "CASCADE" }),
4970
+ JoinColumn8({ name: "contactId" })
4971
+ ], Order.prototype, "contact", 2);
4972
+ __decorateClass([
4973
+ ManyToOne8(() => Address, { onDelete: "SET NULL" }),
4974
+ JoinColumn8({ name: "billingAddressId" })
4975
+ ], Order.prototype, "billingAddress", 2);
4976
+ __decorateClass([
4977
+ ManyToOne8(() => Address, { onDelete: "SET NULL" }),
4978
+ JoinColumn8({ name: "shippingAddressId" })
4979
+ ], Order.prototype, "shippingAddress", 2);
4980
+ __decorateClass([
4981
+ OneToMany6("OrderItem", "order")
4982
+ ], Order.prototype, "items", 2);
4983
+ __decorateClass([
4984
+ OneToMany6("Payment", "order")
4985
+ ], Order.prototype, "payments", 2);
4986
+ Order = __decorateClass([
4987
+ Entity16("orders")
4988
+ ], Order);
4989
+
4990
+ // src/entities/payment.entity.ts
4991
+ import { Entity as Entity17, PrimaryGeneratedColumn as PrimaryGeneratedColumn17, Column as Column17, ManyToOne as ManyToOne9, JoinColumn as JoinColumn9 } from "typeorm";
4992
+ var Payment = class {
4993
+ id;
4994
+ orderId;
4995
+ contactId;
4996
+ amount;
4997
+ currency;
4998
+ status;
4999
+ method;
5000
+ externalReference;
5001
+ metadata;
5002
+ paidAt;
5003
+ createdAt;
5004
+ updatedAt;
5005
+ deletedAt;
5006
+ deleted;
5007
+ createdBy;
5008
+ updatedBy;
5009
+ deletedBy;
5010
+ order;
5011
+ contact;
5012
+ };
5013
+ __decorateClass([
5014
+ PrimaryGeneratedColumn17()
5015
+ ], Payment.prototype, "id", 2);
5016
+ __decorateClass([
5017
+ Column17("int")
5018
+ ], Payment.prototype, "orderId", 2);
5019
+ __decorateClass([
5020
+ Column17("int", { nullable: true })
5021
+ ], Payment.prototype, "contactId", 2);
5022
+ __decorateClass([
5023
+ Column17("decimal", { precision: 12, scale: 2 })
5024
+ ], Payment.prototype, "amount", 2);
5025
+ __decorateClass([
5026
+ Column17("varchar", { default: "INR" })
5027
+ ], Payment.prototype, "currency", 2);
5028
+ __decorateClass([
5029
+ Column17("varchar", { default: "pending" })
5030
+ ], Payment.prototype, "status", 2);
5031
+ __decorateClass([
5032
+ Column17("varchar", { nullable: true })
5033
+ ], Payment.prototype, "method", 2);
5034
+ __decorateClass([
5035
+ Column17("varchar", { nullable: true })
5036
+ ], Payment.prototype, "externalReference", 2);
5037
+ __decorateClass([
5038
+ Column17("jsonb", { nullable: true })
5039
+ ], Payment.prototype, "metadata", 2);
5040
+ __decorateClass([
5041
+ Column17({ type: "timestamp", nullable: true })
5042
+ ], Payment.prototype, "paidAt", 2);
5043
+ __decorateClass([
5044
+ Column17({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5045
+ ], Payment.prototype, "createdAt", 2);
5046
+ __decorateClass([
5047
+ Column17({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5048
+ ], Payment.prototype, "updatedAt", 2);
5049
+ __decorateClass([
5050
+ Column17({ type: "timestamp", nullable: true })
5051
+ ], Payment.prototype, "deletedAt", 2);
5052
+ __decorateClass([
5053
+ Column17("boolean", { default: false })
5054
+ ], Payment.prototype, "deleted", 2);
5055
+ __decorateClass([
5056
+ Column17("int", { nullable: true })
5057
+ ], Payment.prototype, "createdBy", 2);
5058
+ __decorateClass([
5059
+ Column17("int", { nullable: true })
5060
+ ], Payment.prototype, "updatedBy", 2);
5061
+ __decorateClass([
5062
+ Column17("int", { nullable: true })
5063
+ ], Payment.prototype, "deletedBy", 2);
5064
+ __decorateClass([
5065
+ ManyToOne9(() => Order, (o) => o.payments, { onDelete: "CASCADE" }),
5066
+ JoinColumn9({ name: "orderId" })
5067
+ ], Payment.prototype, "order", 2);
5068
+ __decorateClass([
5069
+ ManyToOne9(() => Contact, { onDelete: "SET NULL" }),
5070
+ JoinColumn9({ name: "contactId" })
5071
+ ], Payment.prototype, "contact", 2);
5072
+ Payment = __decorateClass([
5073
+ Entity17("payments")
5074
+ ], Payment);
5075
+
5076
+ // src/entities/chat-conversation.entity.ts
5077
+ import { Entity as Entity19, PrimaryGeneratedColumn as PrimaryGeneratedColumn19, Column as Column19, ManyToOne as ManyToOne11, OneToMany as OneToMany7, JoinColumn as JoinColumn11 } from "typeorm";
5078
+
5079
+ // src/entities/chat-message.entity.ts
5080
+ import { Entity as Entity18, PrimaryGeneratedColumn as PrimaryGeneratedColumn18, Column as Column18, ManyToOne as ManyToOne10, JoinColumn as JoinColumn10 } from "typeorm";
5081
+ var ChatMessage = class {
5082
+ id;
5083
+ conversationId;
5084
+ role;
5085
+ content;
5086
+ createdAt;
5087
+ conversation;
5088
+ };
5089
+ __decorateClass([
5090
+ PrimaryGeneratedColumn18()
5091
+ ], ChatMessage.prototype, "id", 2);
5092
+ __decorateClass([
5093
+ Column18("int")
5094
+ ], ChatMessage.prototype, "conversationId", 2);
5095
+ __decorateClass([
5096
+ Column18("varchar")
5097
+ ], ChatMessage.prototype, "role", 2);
5098
+ __decorateClass([
5099
+ Column18("text")
5100
+ ], ChatMessage.prototype, "content", 2);
5101
+ __decorateClass([
5102
+ Column18({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5103
+ ], ChatMessage.prototype, "createdAt", 2);
5104
+ __decorateClass([
5105
+ ManyToOne10(() => ChatConversation, (c) => c.messages, { onDelete: "CASCADE" }),
5106
+ JoinColumn10({ name: "conversationId" })
5107
+ ], ChatMessage.prototype, "conversation", 2);
5108
+ ChatMessage = __decorateClass([
5109
+ Entity18("chat_messages")
5110
+ ], ChatMessage);
5111
+
5112
+ // src/entities/chat-conversation.entity.ts
5113
+ var ChatConversation = class {
5114
+ id;
5115
+ contactId;
5116
+ createdAt;
5117
+ updatedAt;
5118
+ contact;
5119
+ messages;
5120
+ };
5121
+ __decorateClass([
5122
+ PrimaryGeneratedColumn19()
5123
+ ], ChatConversation.prototype, "id", 2);
5124
+ __decorateClass([
5125
+ Column19("int")
5126
+ ], ChatConversation.prototype, "contactId", 2);
5127
+ __decorateClass([
5128
+ Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5129
+ ], ChatConversation.prototype, "createdAt", 2);
5130
+ __decorateClass([
5131
+ Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5132
+ ], ChatConversation.prototype, "updatedAt", 2);
5133
+ __decorateClass([
5134
+ ManyToOne11(() => Contact, (c) => c.chatConversations, { onDelete: "CASCADE" }),
5135
+ JoinColumn11({ name: "contactId" })
5136
+ ], ChatConversation.prototype, "contact", 2);
5137
+ __decorateClass([
5138
+ OneToMany7(() => ChatMessage, (m) => m.conversation)
5139
+ ], ChatConversation.prototype, "messages", 2);
5140
+ ChatConversation = __decorateClass([
5141
+ Entity19("chat_conversations")
5142
+ ], ChatConversation);
5143
+
5144
+ // src/entities/contact.entity.ts
5145
+ var Contact = class {
5146
+ id;
5147
+ name;
5148
+ email;
5149
+ phone;
5150
+ type;
5151
+ company;
5152
+ taxId;
5153
+ notes;
5154
+ createdAt;
5155
+ updatedAt;
5156
+ deletedAt;
5157
+ deleted;
5158
+ createdBy;
5159
+ updatedBy;
5160
+ deletedBy;
5161
+ userId;
5162
+ user;
5163
+ form_submissions;
5164
+ addresses;
5165
+ orders;
5166
+ payments;
5167
+ chatConversations;
5168
+ };
5169
+ __decorateClass([
5170
+ PrimaryGeneratedColumn20()
5171
+ ], Contact.prototype, "id", 2);
5172
+ __decorateClass([
5173
+ Column20("varchar")
5174
+ ], Contact.prototype, "name", 2);
5175
+ __decorateClass([
5176
+ Column20("varchar", { unique: true })
5177
+ ], Contact.prototype, "email", 2);
5178
+ __decorateClass([
5179
+ Column20("varchar", { nullable: true })
5180
+ ], Contact.prototype, "phone", 2);
5181
+ __decorateClass([
5182
+ Column20("varchar", { nullable: true })
5183
+ ], Contact.prototype, "type", 2);
5184
+ __decorateClass([
5185
+ Column20("varchar", { nullable: true })
5186
+ ], Contact.prototype, "company", 2);
5187
+ __decorateClass([
5188
+ Column20("varchar", { nullable: true })
5189
+ ], Contact.prototype, "taxId", 2);
5190
+ __decorateClass([
5191
+ Column20("text", { nullable: true })
5192
+ ], Contact.prototype, "notes", 2);
5193
+ __decorateClass([
5194
+ Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5195
+ ], Contact.prototype, "createdAt", 2);
5196
+ __decorateClass([
5197
+ Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5198
+ ], Contact.prototype, "updatedAt", 2);
5199
+ __decorateClass([
5200
+ Column20({ type: "timestamp", nullable: true })
5201
+ ], Contact.prototype, "deletedAt", 2);
5202
+ __decorateClass([
5203
+ Column20("boolean", { default: false })
5204
+ ], Contact.prototype, "deleted", 2);
5205
+ __decorateClass([
5206
+ Column20("int", { nullable: true })
5207
+ ], Contact.prototype, "createdBy", 2);
5208
+ __decorateClass([
5209
+ Column20("int", { nullable: true })
5210
+ ], Contact.prototype, "updatedBy", 2);
5211
+ __decorateClass([
5212
+ Column20("int", { nullable: true })
5213
+ ], Contact.prototype, "deletedBy", 2);
5214
+ __decorateClass([
5215
+ Column20("int", { nullable: true })
5216
+ ], Contact.prototype, "userId", 2);
5217
+ __decorateClass([
5218
+ ManyToOne12(() => User, { onDelete: "SET NULL" }),
5219
+ JoinColumn12({ name: "userId" })
5220
+ ], Contact.prototype, "user", 2);
5221
+ __decorateClass([
5222
+ OneToMany8(() => FormSubmission, (fs) => fs.contact)
5223
+ ], Contact.prototype, "form_submissions", 2);
5224
+ __decorateClass([
5225
+ OneToMany8(() => Address, (a) => a.contact)
5226
+ ], Contact.prototype, "addresses", 2);
5227
+ __decorateClass([
5228
+ OneToMany8(() => Order, (o) => o.contact)
5229
+ ], Contact.prototype, "orders", 2);
5230
+ __decorateClass([
5231
+ OneToMany8(() => Payment, (p) => p.contact)
5232
+ ], Contact.prototype, "payments", 2);
5233
+ __decorateClass([
5234
+ OneToMany8(() => ChatConversation, (c) => c.contact)
5235
+ ], Contact.prototype, "chatConversations", 2);
5236
+ Contact = __decorateClass([
5237
+ Entity20("contacts")
5238
+ ], Contact);
5239
+
5240
+ // src/entities/config.entity.ts
5241
+ import { Entity as Entity21, PrimaryGeneratedColumn as PrimaryGeneratedColumn21, Column as Column21, Unique } from "typeorm";
5242
+ var Config = class {
5243
+ id;
5244
+ settings;
5245
+ key;
5246
+ value;
5247
+ type;
5248
+ encrypted;
5249
+ createdAt;
5250
+ updatedAt;
5251
+ deletedAt;
5252
+ deleted;
5253
+ createdBy;
5254
+ updatedBy;
5255
+ deletedBy;
5256
+ };
5257
+ __decorateClass([
5258
+ PrimaryGeneratedColumn21()
5259
+ ], Config.prototype, "id", 2);
5260
+ __decorateClass([
5261
+ Column21("varchar")
5262
+ ], Config.prototype, "settings", 2);
5263
+ __decorateClass([
5264
+ Column21("varchar")
5265
+ ], Config.prototype, "key", 2);
5266
+ __decorateClass([
5267
+ Column21("varchar")
5268
+ ], Config.prototype, "value", 2);
5269
+ __decorateClass([
5270
+ Column21("varchar", { default: "private" })
5271
+ ], Config.prototype, "type", 2);
5272
+ __decorateClass([
5273
+ Column21("boolean", { default: false })
5274
+ ], Config.prototype, "encrypted", 2);
5275
+ __decorateClass([
5276
+ Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5277
+ ], Config.prototype, "createdAt", 2);
5278
+ __decorateClass([
5279
+ Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5280
+ ], Config.prototype, "updatedAt", 2);
5281
+ __decorateClass([
5282
+ Column21({ type: "timestamp", nullable: true })
5283
+ ], Config.prototype, "deletedAt", 2);
5284
+ __decorateClass([
5285
+ Column21("boolean", { default: false })
5286
+ ], Config.prototype, "deleted", 2);
5287
+ __decorateClass([
5288
+ Column21("int", { nullable: true })
5289
+ ], Config.prototype, "createdBy", 2);
5290
+ __decorateClass([
5291
+ Column21("int", { nullable: true })
5292
+ ], Config.prototype, "updatedBy", 2);
5293
+ __decorateClass([
5294
+ Column21("int", { nullable: true })
5295
+ ], Config.prototype, "deletedBy", 2);
5296
+ Config = __decorateClass([
5297
+ Entity21("configs"),
5298
+ Unique(["settings", "key"])
5299
+ ], Config);
5300
+
5301
+ // src/entities/message-template.entity.ts
5302
+ import { Entity as Entity22, PrimaryGeneratedColumn as PrimaryGeneratedColumn22, Column as Column22 } from "typeorm";
5303
+ var MessageTemplate = class {
5304
+ id;
5305
+ channel;
5306
+ templateKey;
5307
+ name;
5308
+ subject;
5309
+ body;
5310
+ externalTemplateRef;
5311
+ providerMeta;
5312
+ enabled;
5313
+ createdAt;
5314
+ updatedAt;
5315
+ deletedAt;
5316
+ deleted;
5317
+ createdBy;
5318
+ updatedBy;
5319
+ deletedBy;
5320
+ };
5321
+ __decorateClass([
5322
+ PrimaryGeneratedColumn22()
5323
+ ], MessageTemplate.prototype, "id", 2);
5324
+ __decorateClass([
5325
+ Column22("varchar")
5326
+ ], MessageTemplate.prototype, "channel", 2);
5327
+ __decorateClass([
5328
+ Column22("varchar", { name: "template_key" })
5329
+ ], MessageTemplate.prototype, "templateKey", 2);
5330
+ __decorateClass([
5331
+ Column22("varchar", { nullable: true })
5332
+ ], MessageTemplate.prototype, "name", 2);
5333
+ __decorateClass([
5334
+ Column22("varchar", { nullable: true })
5335
+ ], MessageTemplate.prototype, "subject", 2);
5336
+ __decorateClass([
5337
+ Column22("text", { default: "" })
5338
+ ], MessageTemplate.prototype, "body", 2);
5339
+ __decorateClass([
5340
+ Column22("varchar", { name: "external_template_ref", nullable: true })
5341
+ ], MessageTemplate.prototype, "externalTemplateRef", 2);
5342
+ __decorateClass([
5343
+ Column22({ type: "jsonb", nullable: true })
5344
+ ], MessageTemplate.prototype, "providerMeta", 2);
5345
+ __decorateClass([
5346
+ Column22("boolean", { default: true })
5347
+ ], MessageTemplate.prototype, "enabled", 2);
5348
+ __decorateClass([
5349
+ Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5350
+ ], MessageTemplate.prototype, "createdAt", 2);
5351
+ __decorateClass([
5352
+ Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5353
+ ], MessageTemplate.prototype, "updatedAt", 2);
5354
+ __decorateClass([
5355
+ Column22({ type: "timestamp", nullable: true })
5356
+ ], MessageTemplate.prototype, "deletedAt", 2);
5357
+ __decorateClass([
5358
+ Column22("boolean", { default: false })
5359
+ ], MessageTemplate.prototype, "deleted", 2);
5360
+ __decorateClass([
5361
+ Column22("int", { nullable: true })
5362
+ ], MessageTemplate.prototype, "createdBy", 2);
5363
+ __decorateClass([
5364
+ Column22("int", { nullable: true })
5365
+ ], MessageTemplate.prototype, "updatedBy", 2);
5366
+ __decorateClass([
5367
+ Column22("int", { nullable: true })
5368
+ ], MessageTemplate.prototype, "deletedBy", 2);
5369
+ MessageTemplate = __decorateClass([
5370
+ Entity22("message_templates")
5371
+ ], MessageTemplate);
5372
+
5373
+ // src/entities/media.entity.ts
5374
+ import { Entity as Entity23, PrimaryGeneratedColumn as PrimaryGeneratedColumn23, Column as Column23, ManyToOne as ManyToOne13, OneToMany as OneToMany9, JoinColumn as JoinColumn13 } from "typeorm";
5375
+ var Media = class {
5376
+ id;
5377
+ kind;
5378
+ parentId;
5379
+ parent;
5380
+ children;
5381
+ filename;
5382
+ url;
5383
+ mimeType;
5384
+ size;
5385
+ alt;
5386
+ isPublic;
5387
+ createdAt;
5388
+ updatedAt;
5389
+ deletedAt;
5390
+ deleted;
5391
+ };
5392
+ __decorateClass([
5393
+ PrimaryGeneratedColumn23()
5394
+ ], Media.prototype, "id", 2);
5395
+ __decorateClass([
5396
+ Column23({ type: "varchar", length: 16, default: "file" })
5397
+ ], Media.prototype, "kind", 2);
5398
+ __decorateClass([
5399
+ Column23({ type: "int", nullable: true })
5400
+ ], Media.prototype, "parentId", 2);
5401
+ __decorateClass([
5402
+ ManyToOne13(() => Media, (m) => m.children, { onDelete: "CASCADE" }),
5403
+ JoinColumn13({ name: "parentId" })
5404
+ ], Media.prototype, "parent", 2);
5405
+ __decorateClass([
5406
+ OneToMany9(() => Media, (m) => m.parent)
5407
+ ], Media.prototype, "children", 2);
5408
+ __decorateClass([
5409
+ Column23("varchar")
5410
+ ], Media.prototype, "filename", 2);
5411
+ __decorateClass([
5412
+ Column23("varchar", { nullable: true })
5413
+ ], Media.prototype, "url", 2);
5414
+ __decorateClass([
5415
+ Column23("varchar", { nullable: true })
5416
+ ], Media.prototype, "mimeType", 2);
5417
+ __decorateClass([
5418
+ Column23("int", { default: 0 })
5419
+ ], Media.prototype, "size", 2);
5420
+ __decorateClass([
5421
+ Column23("varchar", { nullable: true })
5422
+ ], Media.prototype, "alt", 2);
5423
+ __decorateClass([
5424
+ Column23("boolean", { default: false })
5425
+ ], Media.prototype, "isPublic", 2);
5426
+ __decorateClass([
5427
+ Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5428
+ ], Media.prototype, "createdAt", 2);
5429
+ __decorateClass([
5430
+ Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5431
+ ], Media.prototype, "updatedAt", 2);
5432
+ __decorateClass([
5433
+ Column23({ type: "timestamp", nullable: true })
5434
+ ], Media.prototype, "deletedAt", 2);
5435
+ __decorateClass([
5436
+ Column23("boolean", { default: false })
5437
+ ], Media.prototype, "deleted", 2);
5438
+ Media = __decorateClass([
5439
+ Entity23("media")
5440
+ ], Media);
5441
+
5442
+ // src/entities/page.entity.ts
5443
+ import { Entity as Entity24, PrimaryGeneratedColumn as PrimaryGeneratedColumn24, Column as Column24, ManyToOne as ManyToOne14, JoinColumn as JoinColumn14 } from "typeorm";
5444
+ var Page = class {
5445
+ id;
5446
+ title;
5447
+ slug;
5448
+ content;
5449
+ published;
5450
+ theme;
5451
+ parentId;
5452
+ parent;
5453
+ seoId;
5454
+ seo;
5455
+ createdAt;
5456
+ updatedAt;
5457
+ deletedAt;
5458
+ deleted;
5459
+ createdBy;
5460
+ updatedBy;
5461
+ deletedBy;
5462
+ };
5463
+ __decorateClass([
5464
+ PrimaryGeneratedColumn24()
5465
+ ], Page.prototype, "id", 2);
5466
+ __decorateClass([
5467
+ Column24("varchar")
5468
+ ], Page.prototype, "title", 2);
5469
+ __decorateClass([
5470
+ Column24("varchar", { unique: true })
5471
+ ], Page.prototype, "slug", 2);
5472
+ __decorateClass([
5473
+ Column24({ type: "jsonb", default: {} })
5474
+ ], Page.prototype, "content", 2);
5475
+ __decorateClass([
5476
+ Column24("boolean", { default: false })
5477
+ ], Page.prototype, "published", 2);
5478
+ __decorateClass([
5479
+ Column24("varchar", { default: "default" })
5480
+ ], Page.prototype, "theme", 2);
5481
+ __decorateClass([
5482
+ Column24("int", { nullable: true })
5483
+ ], Page.prototype, "parentId", 2);
5484
+ __decorateClass([
5485
+ ManyToOne14(() => Page, { onDelete: "SET NULL" }),
5486
+ JoinColumn14({ name: "parentId" })
5487
+ ], Page.prototype, "parent", 2);
5488
+ __decorateClass([
5489
+ Column24("int", { nullable: true })
5490
+ ], Page.prototype, "seoId", 2);
5491
+ __decorateClass([
5492
+ ManyToOne14(() => Seo, { onDelete: "SET NULL" }),
5493
+ JoinColumn14({ name: "seoId" })
5494
+ ], Page.prototype, "seo", 2);
5495
+ __decorateClass([
5496
+ Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5497
+ ], Page.prototype, "createdAt", 2);
5498
+ __decorateClass([
5499
+ Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5500
+ ], Page.prototype, "updatedAt", 2);
5501
+ __decorateClass([
5502
+ Column24({ type: "timestamp", nullable: true })
5503
+ ], Page.prototype, "deletedAt", 2);
5504
+ __decorateClass([
5505
+ Column24("boolean", { default: false })
5506
+ ], Page.prototype, "deleted", 2);
5507
+ __decorateClass([
5508
+ Column24("int", { nullable: true })
5509
+ ], Page.prototype, "createdBy", 2);
5510
+ __decorateClass([
5511
+ Column24("int", { nullable: true })
5512
+ ], Page.prototype, "updatedBy", 2);
5513
+ __decorateClass([
5514
+ Column24("int", { nullable: true })
5515
+ ], Page.prototype, "deletedBy", 2);
5516
+ Page = __decorateClass([
5517
+ Entity24("pages")
5518
+ ], Page);
5519
+
5520
+ // src/entities/product-category.entity.ts
5521
+ import { Entity as Entity25, PrimaryGeneratedColumn as PrimaryGeneratedColumn25, Column as Column25, ManyToOne as ManyToOne15, OneToMany as OneToMany10, JoinColumn as JoinColumn15 } from "typeorm";
5522
+ var ProductCategory = class {
5523
+ id;
5524
+ name;
5525
+ slug;
5526
+ parentId;
5527
+ image;
5528
+ description;
5529
+ metadata;
5530
+ active;
5531
+ sortOrder;
5532
+ createdAt;
5533
+ updatedAt;
5534
+ deletedAt;
5535
+ deleted;
5536
+ createdBy;
5537
+ updatedBy;
5538
+ deletedBy;
5539
+ parent;
5540
+ children;
5541
+ products;
5542
+ collections;
5543
+ };
5544
+ __decorateClass([
5545
+ PrimaryGeneratedColumn25()
5546
+ ], ProductCategory.prototype, "id", 2);
5547
+ __decorateClass([
5548
+ Column25("varchar")
5549
+ ], ProductCategory.prototype, "name", 2);
5550
+ __decorateClass([
5551
+ Column25("varchar", { unique: true })
5552
+ ], ProductCategory.prototype, "slug", 2);
5553
+ __decorateClass([
5554
+ Column25("int", { nullable: true })
5555
+ ], ProductCategory.prototype, "parentId", 2);
5556
+ __decorateClass([
5557
+ Column25("varchar", { nullable: true })
5558
+ ], ProductCategory.prototype, "image", 2);
5559
+ __decorateClass([
5560
+ Column25("text", { nullable: true })
5561
+ ], ProductCategory.prototype, "description", 2);
5562
+ __decorateClass([
5563
+ Column25("jsonb", { nullable: true })
5564
+ ], ProductCategory.prototype, "metadata", 2);
5565
+ __decorateClass([
5566
+ Column25("boolean", { default: true })
5567
+ ], ProductCategory.prototype, "active", 2);
5568
+ __decorateClass([
5569
+ Column25("int", { default: 0 })
5570
+ ], ProductCategory.prototype, "sortOrder", 2);
5571
+ __decorateClass([
5572
+ Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5573
+ ], ProductCategory.prototype, "createdAt", 2);
5574
+ __decorateClass([
5575
+ Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5576
+ ], ProductCategory.prototype, "updatedAt", 2);
5577
+ __decorateClass([
5578
+ Column25({ type: "timestamp", nullable: true })
5579
+ ], ProductCategory.prototype, "deletedAt", 2);
5580
+ __decorateClass([
5581
+ Column25("boolean", { default: false })
5582
+ ], ProductCategory.prototype, "deleted", 2);
5583
+ __decorateClass([
5584
+ Column25("int", { nullable: true })
5585
+ ], ProductCategory.prototype, "createdBy", 2);
5586
+ __decorateClass([
5587
+ Column25("int", { nullable: true })
5588
+ ], ProductCategory.prototype, "updatedBy", 2);
5589
+ __decorateClass([
5590
+ Column25("int", { nullable: true })
5591
+ ], ProductCategory.prototype, "deletedBy", 2);
5592
+ __decorateClass([
5593
+ ManyToOne15(() => ProductCategory, (c) => c.children, { onDelete: "SET NULL" }),
5594
+ JoinColumn15({ name: "parentId" })
5595
+ ], ProductCategory.prototype, "parent", 2);
5596
+ __decorateClass([
5597
+ OneToMany10(() => ProductCategory, (c) => c.parent)
5598
+ ], ProductCategory.prototype, "children", 2);
5599
+ __decorateClass([
5600
+ OneToMany10("Product", "category")
5601
+ ], ProductCategory.prototype, "products", 2);
5602
+ __decorateClass([
5603
+ OneToMany10("Collection", "category")
5604
+ ], ProductCategory.prototype, "collections", 2);
5605
+ ProductCategory = __decorateClass([
5606
+ Entity25("product_categories")
5607
+ ], ProductCategory);
5608
+
5609
+ // src/entities/collection.entity.ts
5610
+ import { Entity as Entity27, PrimaryGeneratedColumn as PrimaryGeneratedColumn27, Column as Column27, ManyToOne as ManyToOne17, OneToMany as OneToMany12, JoinColumn as JoinColumn17 } from "typeorm";
5611
+
5612
+ // src/entities/brand.entity.ts
5613
+ import { Entity as Entity26, PrimaryGeneratedColumn as PrimaryGeneratedColumn26, Column as Column26, OneToMany as OneToMany11, ManyToOne as ManyToOne16, JoinColumn as JoinColumn16 } from "typeorm";
5614
+ var Brand = class {
5615
+ id;
5616
+ name;
5617
+ slug;
5618
+ logo;
5619
+ metadata;
5620
+ description;
5621
+ active;
5622
+ sortOrder;
5623
+ createdAt;
5624
+ updatedAt;
5625
+ deletedAt;
5626
+ deleted;
5627
+ createdBy;
5628
+ updatedBy;
5629
+ deletedBy;
5630
+ seoId;
5631
+ seo;
5632
+ products;
5633
+ collections;
5634
+ };
5635
+ __decorateClass([
5636
+ PrimaryGeneratedColumn26()
5637
+ ], Brand.prototype, "id", 2);
5638
+ __decorateClass([
5639
+ Column26("varchar")
5640
+ ], Brand.prototype, "name", 2);
5641
+ __decorateClass([
5642
+ Column26("varchar", { unique: true })
5643
+ ], Brand.prototype, "slug", 2);
5644
+ __decorateClass([
5645
+ Column26("varchar", { nullable: true })
5646
+ ], Brand.prototype, "logo", 2);
5647
+ __decorateClass([
5648
+ Column26("jsonb", { nullable: true })
5649
+ ], Brand.prototype, "metadata", 2);
5650
+ __decorateClass([
5651
+ Column26("text", { nullable: true })
5652
+ ], Brand.prototype, "description", 2);
5653
+ __decorateClass([
5654
+ Column26("boolean", { default: true })
5655
+ ], Brand.prototype, "active", 2);
5656
+ __decorateClass([
5657
+ Column26("int", { default: 0 })
5658
+ ], Brand.prototype, "sortOrder", 2);
5659
+ __decorateClass([
5660
+ Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5661
+ ], Brand.prototype, "createdAt", 2);
5662
+ __decorateClass([
5663
+ Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5664
+ ], Brand.prototype, "updatedAt", 2);
5665
+ __decorateClass([
5666
+ Column26({ type: "timestamp", nullable: true })
5667
+ ], Brand.prototype, "deletedAt", 2);
5668
+ __decorateClass([
5669
+ Column26("boolean", { default: false })
5670
+ ], Brand.prototype, "deleted", 2);
5671
+ __decorateClass([
5672
+ Column26("int", { nullable: true })
5673
+ ], Brand.prototype, "createdBy", 2);
5674
+ __decorateClass([
5675
+ Column26("int", { nullable: true })
5676
+ ], Brand.prototype, "updatedBy", 2);
5677
+ __decorateClass([
5678
+ Column26("int", { nullable: true })
5679
+ ], Brand.prototype, "deletedBy", 2);
5680
+ __decorateClass([
5681
+ Column26("int", { nullable: true })
5682
+ ], Brand.prototype, "seoId", 2);
5683
+ __decorateClass([
5684
+ ManyToOne16(() => Seo, { onDelete: "SET NULL" }),
5685
+ JoinColumn16({ name: "seoId" })
5686
+ ], Brand.prototype, "seo", 2);
5687
+ __decorateClass([
5688
+ OneToMany11("Product", "brand")
5689
+ ], Brand.prototype, "products", 2);
5690
+ __decorateClass([
5691
+ OneToMany11("Collection", "brand")
5692
+ ], Brand.prototype, "collections", 2);
5693
+ Brand = __decorateClass([
5694
+ Entity26("brands")
5695
+ ], Brand);
5696
+
5697
+ // src/entities/collection.entity.ts
5698
+ var Collection = class {
5699
+ id;
5700
+ categoryId;
5701
+ brandId;
5702
+ name;
5703
+ slug;
5704
+ hsn;
5705
+ description;
5706
+ image;
5707
+ metadata;
5708
+ variants;
5709
+ active;
5710
+ sortOrder;
5711
+ createdAt;
5712
+ updatedAt;
5713
+ deletedAt;
5714
+ deleted;
5715
+ createdBy;
5716
+ updatedBy;
5717
+ deletedBy;
5718
+ seoId;
5719
+ seo;
5720
+ category;
5721
+ brand;
5722
+ products;
5723
+ };
5724
+ __decorateClass([
5725
+ PrimaryGeneratedColumn27()
5726
+ ], Collection.prototype, "id", 2);
5727
+ __decorateClass([
5728
+ Column27("int", { nullable: true })
5729
+ ], Collection.prototype, "categoryId", 2);
5730
+ __decorateClass([
5731
+ Column27("int", { nullable: true })
5732
+ ], Collection.prototype, "brandId", 2);
5733
+ __decorateClass([
5734
+ Column27("varchar")
5735
+ ], Collection.prototype, "name", 2);
5736
+ __decorateClass([
5737
+ Column27("varchar", { unique: true })
5738
+ ], Collection.prototype, "slug", 2);
5739
+ __decorateClass([
5740
+ Column27("varchar", { nullable: true })
5741
+ ], Collection.prototype, "hsn", 2);
5742
+ __decorateClass([
5743
+ Column27("text", { nullable: true })
5744
+ ], Collection.prototype, "description", 2);
5745
+ __decorateClass([
5746
+ Column27("varchar", { nullable: true })
5747
+ ], Collection.prototype, "image", 2);
5748
+ __decorateClass([
5749
+ Column27("jsonb", { nullable: true })
5750
+ ], Collection.prototype, "metadata", 2);
5751
+ __decorateClass([
5752
+ Column27("jsonb", { nullable: true })
5753
+ ], Collection.prototype, "variants", 2);
5754
+ __decorateClass([
5755
+ Column27("boolean", { default: true })
5756
+ ], Collection.prototype, "active", 2);
5757
+ __decorateClass([
5758
+ Column27("int", { default: 0 })
5759
+ ], Collection.prototype, "sortOrder", 2);
5760
+ __decorateClass([
5761
+ Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5762
+ ], Collection.prototype, "createdAt", 2);
5763
+ __decorateClass([
5764
+ Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5765
+ ], Collection.prototype, "updatedAt", 2);
5766
+ __decorateClass([
5767
+ Column27({ type: "timestamp", nullable: true })
5768
+ ], Collection.prototype, "deletedAt", 2);
5769
+ __decorateClass([
5770
+ Column27("boolean", { default: false })
5771
+ ], Collection.prototype, "deleted", 2);
5772
+ __decorateClass([
5773
+ Column27("int", { nullable: true })
5774
+ ], Collection.prototype, "createdBy", 2);
5775
+ __decorateClass([
5776
+ Column27("int", { nullable: true })
5777
+ ], Collection.prototype, "updatedBy", 2);
5778
+ __decorateClass([
5779
+ Column27("int", { nullable: true })
5780
+ ], Collection.prototype, "deletedBy", 2);
5781
+ __decorateClass([
5782
+ Column27("int", { nullable: true })
5783
+ ], Collection.prototype, "seoId", 2);
5784
+ __decorateClass([
5785
+ ManyToOne17(() => Seo, { onDelete: "SET NULL" }),
5786
+ JoinColumn17({ name: "seoId" })
5787
+ ], Collection.prototype, "seo", 2);
5788
+ __decorateClass([
5789
+ ManyToOne17(() => ProductCategory, (c) => c.collections, { onDelete: "SET NULL" }),
5790
+ JoinColumn17({ name: "categoryId" })
5791
+ ], Collection.prototype, "category", 2);
5792
+ __decorateClass([
5793
+ ManyToOne17(() => Brand, (b) => b.collections, { onDelete: "SET NULL" }),
5794
+ JoinColumn17({ name: "brandId" })
5795
+ ], Collection.prototype, "brand", 2);
5796
+ __decorateClass([
5797
+ OneToMany12("Product", "collection")
5798
+ ], Collection.prototype, "products", 2);
5799
+ Collection = __decorateClass([
5800
+ Entity27("collections")
5801
+ ], Collection);
5802
+
5803
+ // src/entities/product.entity.ts
5804
+ import { Entity as Entity28, PrimaryGeneratedColumn as PrimaryGeneratedColumn28, Column as Column28, ManyToOne as ManyToOne18, OneToMany as OneToMany13, JoinColumn as JoinColumn18 } from "typeorm";
5805
+ var Product = class {
5806
+ id;
5807
+ collectionId;
5808
+ brandId;
5809
+ categoryId;
5810
+ sku;
5811
+ hsn;
5812
+ uom;
5813
+ type;
5814
+ slug;
5815
+ name;
5816
+ price;
5817
+ compareAtPrice;
5818
+ quantity;
5819
+ status;
5820
+ featured;
5821
+ metadata;
5822
+ createdAt;
5823
+ updatedAt;
5824
+ deletedAt;
5825
+ deleted;
5826
+ createdBy;
5827
+ updatedBy;
5828
+ deletedBy;
5829
+ seoId;
5830
+ seo;
5831
+ collection;
5832
+ brand;
5833
+ category;
5834
+ attributes;
5835
+ taxes;
5836
+ };
5837
+ __decorateClass([
5838
+ PrimaryGeneratedColumn28()
5839
+ ], Product.prototype, "id", 2);
5840
+ __decorateClass([
5841
+ Column28("int", { nullable: true })
5842
+ ], Product.prototype, "collectionId", 2);
5843
+ __decorateClass([
5844
+ Column28("int", { nullable: true })
5845
+ ], Product.prototype, "brandId", 2);
5846
+ __decorateClass([
5847
+ Column28("int", { nullable: true })
5848
+ ], Product.prototype, "categoryId", 2);
5849
+ __decorateClass([
5850
+ Column28("varchar", { nullable: true })
5851
+ ], Product.prototype, "sku", 2);
5852
+ __decorateClass([
5853
+ Column28("varchar", { nullable: true })
5854
+ ], Product.prototype, "hsn", 2);
5855
+ __decorateClass([
5856
+ Column28("varchar", { nullable: true })
5857
+ ], Product.prototype, "uom", 2);
5858
+ __decorateClass([
5859
+ Column28("varchar", { default: "product" })
5860
+ ], Product.prototype, "type", 2);
5861
+ __decorateClass([
5862
+ Column28("varchar", { unique: true, nullable: true })
5863
+ ], Product.prototype, "slug", 2);
5864
+ __decorateClass([
5865
+ Column28("varchar", { nullable: true })
5866
+ ], Product.prototype, "name", 2);
5867
+ __decorateClass([
5868
+ Column28("decimal", { precision: 12, scale: 2 })
5869
+ ], Product.prototype, "price", 2);
5870
+ __decorateClass([
5871
+ Column28("decimal", { precision: 12, scale: 2, nullable: true })
5872
+ ], Product.prototype, "compareAtPrice", 2);
5873
+ __decorateClass([
5874
+ Column28("int", { default: 0 })
5875
+ ], Product.prototype, "quantity", 2);
5876
+ __decorateClass([
5877
+ Column28("varchar", { default: "draft" })
5878
+ ], Product.prototype, "status", 2);
5879
+ __decorateClass([
5880
+ Column28("boolean", { default: false })
5881
+ ], Product.prototype, "featured", 2);
5882
+ __decorateClass([
5883
+ Column28("jsonb", { nullable: true })
5884
+ ], Product.prototype, "metadata", 2);
5885
+ __decorateClass([
5886
+ Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5887
+ ], Product.prototype, "createdAt", 2);
5888
+ __decorateClass([
5889
+ Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5890
+ ], Product.prototype, "updatedAt", 2);
5891
+ __decorateClass([
5892
+ Column28({ type: "timestamp", nullable: true })
5893
+ ], Product.prototype, "deletedAt", 2);
5894
+ __decorateClass([
5895
+ Column28("boolean", { default: false })
5896
+ ], Product.prototype, "deleted", 2);
5897
+ __decorateClass([
5898
+ Column28("int", { nullable: true })
5899
+ ], Product.prototype, "createdBy", 2);
5900
+ __decorateClass([
5901
+ Column28("int", { nullable: true })
5902
+ ], Product.prototype, "updatedBy", 2);
5903
+ __decorateClass([
5904
+ Column28("int", { nullable: true })
5905
+ ], Product.prototype, "deletedBy", 2);
5906
+ __decorateClass([
5907
+ Column28("int", { nullable: true })
5908
+ ], Product.prototype, "seoId", 2);
5909
+ __decorateClass([
5910
+ ManyToOne18(() => Seo, { onDelete: "SET NULL" }),
5911
+ JoinColumn18({ name: "seoId" })
5912
+ ], Product.prototype, "seo", 2);
5913
+ __decorateClass([
5914
+ ManyToOne18(() => Collection, (c) => c.products, { onDelete: "SET NULL" }),
5915
+ JoinColumn18({ name: "collectionId" })
5916
+ ], Product.prototype, "collection", 2);
5917
+ __decorateClass([
5918
+ ManyToOne18(() => Brand, (b) => b.products, { onDelete: "SET NULL" }),
5919
+ JoinColumn18({ name: "brandId" })
5920
+ ], Product.prototype, "brand", 2);
5921
+ __decorateClass([
5922
+ ManyToOne18(() => ProductCategory, (c) => c.products, { onDelete: "SET NULL" }),
5923
+ JoinColumn18({ name: "categoryId" })
5924
+ ], Product.prototype, "category", 2);
5925
+ __decorateClass([
5926
+ OneToMany13("ProductAttribute", "product")
5927
+ ], Product.prototype, "attributes", 2);
5928
+ __decorateClass([
5929
+ OneToMany13("ProductTax", "product")
5930
+ ], Product.prototype, "taxes", 2);
5931
+ Product = __decorateClass([
5932
+ Entity28("products")
5933
+ ], Product);
5934
+
5935
+ // src/entities/attribute.entity.ts
5936
+ import { Entity as Entity29, PrimaryGeneratedColumn as PrimaryGeneratedColumn29, Column as Column29 } from "typeorm";
5937
+ var Attribute = class {
5938
+ id;
5939
+ name;
5940
+ slug;
5941
+ type;
5942
+ options;
5943
+ metadata;
5944
+ active;
5945
+ sortOrder;
5946
+ createdAt;
5947
+ updatedAt;
5948
+ deletedAt;
5949
+ deleted;
5950
+ createdBy;
5951
+ updatedBy;
5952
+ deletedBy;
5953
+ };
5954
+ __decorateClass([
5955
+ PrimaryGeneratedColumn29()
5956
+ ], Attribute.prototype, "id", 2);
5957
+ __decorateClass([
5958
+ Column29("varchar")
5959
+ ], Attribute.prototype, "name", 2);
5960
+ __decorateClass([
5961
+ Column29("varchar", { unique: true })
5962
+ ], Attribute.prototype, "slug", 2);
5963
+ __decorateClass([
5964
+ Column29("varchar", { default: "text" })
5965
+ ], Attribute.prototype, "type", 2);
5966
+ __decorateClass([
5967
+ Column29("jsonb", { nullable: true })
5968
+ ], Attribute.prototype, "options", 2);
5969
+ __decorateClass([
5970
+ Column29("jsonb", { nullable: true })
5971
+ ], Attribute.prototype, "metadata", 2);
5972
+ __decorateClass([
5973
+ Column29("boolean", { default: true })
5974
+ ], Attribute.prototype, "active", 2);
5975
+ __decorateClass([
5976
+ Column29("int", { default: 0 })
5977
+ ], Attribute.prototype, "sortOrder", 2);
5978
+ __decorateClass([
5979
+ Column29({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5980
+ ], Attribute.prototype, "createdAt", 2);
5981
+ __decorateClass([
5982
+ Column29({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
5983
+ ], Attribute.prototype, "updatedAt", 2);
5984
+ __decorateClass([
5985
+ Column29({ type: "timestamp", nullable: true })
5986
+ ], Attribute.prototype, "deletedAt", 2);
5987
+ __decorateClass([
5988
+ Column29("boolean", { default: false })
5989
+ ], Attribute.prototype, "deleted", 2);
5990
+ __decorateClass([
5991
+ Column29("int", { nullable: true })
5992
+ ], Attribute.prototype, "createdBy", 2);
5993
+ __decorateClass([
5994
+ Column29("int", { nullable: true })
5995
+ ], Attribute.prototype, "updatedBy", 2);
5996
+ __decorateClass([
5997
+ Column29("int", { nullable: true })
5998
+ ], Attribute.prototype, "deletedBy", 2);
5999
+ Attribute = __decorateClass([
6000
+ Entity29("attributes")
6001
+ ], Attribute);
6002
+
6003
+ // src/entities/product-attribute.entity.ts
6004
+ import { Entity as Entity30, PrimaryGeneratedColumn as PrimaryGeneratedColumn30, Column as Column30, ManyToOne as ManyToOne19, JoinColumn as JoinColumn19 } from "typeorm";
6005
+ var ProductAttribute = class {
6006
+ id;
6007
+ productId;
6008
+ attributeId;
6009
+ value;
6010
+ metadata;
6011
+ createdAt;
6012
+ updatedAt;
6013
+ product;
6014
+ attribute;
6015
+ };
6016
+ __decorateClass([
6017
+ PrimaryGeneratedColumn30()
6018
+ ], ProductAttribute.prototype, "id", 2);
6019
+ __decorateClass([
6020
+ Column30("int")
6021
+ ], ProductAttribute.prototype, "productId", 2);
6022
+ __decorateClass([
6023
+ Column30("int")
6024
+ ], ProductAttribute.prototype, "attributeId", 2);
6025
+ __decorateClass([
6026
+ Column30("varchar")
6027
+ ], ProductAttribute.prototype, "value", 2);
6028
+ __decorateClass([
6029
+ Column30("jsonb", { nullable: true })
6030
+ ], ProductAttribute.prototype, "metadata", 2);
6031
+ __decorateClass([
6032
+ Column30({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6033
+ ], ProductAttribute.prototype, "createdAt", 2);
6034
+ __decorateClass([
6035
+ Column30({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6036
+ ], ProductAttribute.prototype, "updatedAt", 2);
6037
+ __decorateClass([
6038
+ ManyToOne19(() => Product, (p) => p.attributes, { onDelete: "CASCADE" }),
6039
+ JoinColumn19({ name: "productId" })
6040
+ ], ProductAttribute.prototype, "product", 2);
6041
+ __decorateClass([
6042
+ ManyToOne19(() => Attribute, { onDelete: "CASCADE" }),
6043
+ JoinColumn19({ name: "attributeId" })
6044
+ ], ProductAttribute.prototype, "attribute", 2);
6045
+ ProductAttribute = __decorateClass([
6046
+ Entity30("product_attributes")
6047
+ ], ProductAttribute);
6048
+
6049
+ // src/entities/tax.entity.ts
6050
+ import { Entity as Entity31, PrimaryGeneratedColumn as PrimaryGeneratedColumn31, Column as Column31 } from "typeorm";
6051
+ var Tax = class {
6052
+ id;
6053
+ name;
6054
+ slug;
6055
+ rate;
6056
+ isDefault;
6057
+ description;
6058
+ active;
6059
+ metadata;
6060
+ createdAt;
6061
+ updatedAt;
6062
+ deletedAt;
6063
+ deleted;
6064
+ createdBy;
6065
+ updatedBy;
6066
+ deletedBy;
6067
+ };
6068
+ __decorateClass([
6069
+ PrimaryGeneratedColumn31()
6070
+ ], Tax.prototype, "id", 2);
6071
+ __decorateClass([
6072
+ Column31("varchar")
6073
+ ], Tax.prototype, "name", 2);
6074
+ __decorateClass([
6075
+ Column31("varchar", { unique: true })
6076
+ ], Tax.prototype, "slug", 2);
6077
+ __decorateClass([
6078
+ Column31("decimal", { precision: 5, scale: 2 })
6079
+ ], Tax.prototype, "rate", 2);
6080
+ __decorateClass([
6081
+ Column31("boolean", { default: false })
6082
+ ], Tax.prototype, "isDefault", 2);
6083
+ __decorateClass([
6084
+ Column31("text", { nullable: true })
6085
+ ], Tax.prototype, "description", 2);
6086
+ __decorateClass([
6087
+ Column31("boolean", { default: true })
6088
+ ], Tax.prototype, "active", 2);
6089
+ __decorateClass([
6090
+ Column31("jsonb", { nullable: true })
6091
+ ], Tax.prototype, "metadata", 2);
6092
+ __decorateClass([
6093
+ Column31({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6094
+ ], Tax.prototype, "createdAt", 2);
6095
+ __decorateClass([
6096
+ Column31({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6097
+ ], Tax.prototype, "updatedAt", 2);
6098
+ __decorateClass([
6099
+ Column31({ type: "timestamp", nullable: true })
6100
+ ], Tax.prototype, "deletedAt", 2);
6101
+ __decorateClass([
6102
+ Column31("boolean", { default: false })
6103
+ ], Tax.prototype, "deleted", 2);
6104
+ __decorateClass([
6105
+ Column31("int", { nullable: true })
6106
+ ], Tax.prototype, "createdBy", 2);
6107
+ __decorateClass([
6108
+ Column31("int", { nullable: true })
6109
+ ], Tax.prototype, "updatedBy", 2);
6110
+ __decorateClass([
6111
+ Column31("int", { nullable: true })
6112
+ ], Tax.prototype, "deletedBy", 2);
6113
+ Tax = __decorateClass([
6114
+ Entity31("taxes")
6115
+ ], Tax);
6116
+
6117
+ // src/entities/product-tax.entity.ts
6118
+ import { Entity as Entity32, PrimaryGeneratedColumn as PrimaryGeneratedColumn32, Column as Column32, ManyToOne as ManyToOne20, JoinColumn as JoinColumn20 } from "typeorm";
6119
+ var ProductTax = class {
6120
+ id;
6121
+ productId;
6122
+ taxId;
6123
+ rate;
6124
+ createdAt;
6125
+ updatedAt;
6126
+ product;
6127
+ tax;
6128
+ };
6129
+ __decorateClass([
6130
+ PrimaryGeneratedColumn32()
6131
+ ], ProductTax.prototype, "id", 2);
6132
+ __decorateClass([
6133
+ Column32("int")
6134
+ ], ProductTax.prototype, "productId", 2);
6135
+ __decorateClass([
6136
+ Column32("int")
6137
+ ], ProductTax.prototype, "taxId", 2);
6138
+ __decorateClass([
6139
+ Column32("decimal", { precision: 5, scale: 2, nullable: true })
6140
+ ], ProductTax.prototype, "rate", 2);
6141
+ __decorateClass([
6142
+ Column32({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6143
+ ], ProductTax.prototype, "createdAt", 2);
6144
+ __decorateClass([
6145
+ Column32({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6146
+ ], ProductTax.prototype, "updatedAt", 2);
6147
+ __decorateClass([
6148
+ ManyToOne20(() => Product, (p) => p.taxes, { onDelete: "CASCADE" }),
6149
+ JoinColumn20({ name: "productId" })
6150
+ ], ProductTax.prototype, "product", 2);
6151
+ __decorateClass([
6152
+ ManyToOne20(() => Tax, { onDelete: "CASCADE" }),
6153
+ JoinColumn20({ name: "taxId" })
6154
+ ], ProductTax.prototype, "tax", 2);
6155
+ ProductTax = __decorateClass([
6156
+ Entity32("product_taxes")
6157
+ ], ProductTax);
6158
+
6159
+ // src/entities/order-item.entity.ts
6160
+ import { Entity as Entity33, PrimaryGeneratedColumn as PrimaryGeneratedColumn33, Column as Column33, ManyToOne as ManyToOne21, JoinColumn as JoinColumn21 } from "typeorm";
6161
+ var OrderItem = class {
6162
+ id;
6163
+ orderId;
6164
+ productId;
6165
+ quantity;
6166
+ unitPrice;
6167
+ tax;
6168
+ total;
6169
+ hsn;
6170
+ uom;
6171
+ productType;
6172
+ taxRate;
6173
+ taxCode;
6174
+ metadata;
6175
+ createdAt;
6176
+ updatedAt;
6177
+ order;
6178
+ product;
6179
+ };
6180
+ __decorateClass([
6181
+ PrimaryGeneratedColumn33()
6182
+ ], OrderItem.prototype, "id", 2);
6183
+ __decorateClass([
6184
+ Column33("int")
6185
+ ], OrderItem.prototype, "orderId", 2);
6186
+ __decorateClass([
6187
+ Column33("int")
6188
+ ], OrderItem.prototype, "productId", 2);
6189
+ __decorateClass([
6190
+ Column33("int", { default: 1 })
6191
+ ], OrderItem.prototype, "quantity", 2);
6192
+ __decorateClass([
6193
+ Column33("decimal", { precision: 12, scale: 2 })
6194
+ ], OrderItem.prototype, "unitPrice", 2);
6195
+ __decorateClass([
6196
+ Column33("decimal", { precision: 12, scale: 2, default: 0 })
6197
+ ], OrderItem.prototype, "tax", 2);
6198
+ __decorateClass([
6199
+ Column33("decimal", { precision: 12, scale: 2 })
6200
+ ], OrderItem.prototype, "total", 2);
6201
+ __decorateClass([
6202
+ Column33("varchar", { nullable: true })
6203
+ ], OrderItem.prototype, "hsn", 2);
6204
+ __decorateClass([
6205
+ Column33("varchar", { nullable: true })
6206
+ ], OrderItem.prototype, "uom", 2);
6207
+ __decorateClass([
6208
+ Column33("varchar", { nullable: true })
6209
+ ], OrderItem.prototype, "productType", 2);
6210
+ __decorateClass([
6211
+ Column33("decimal", { precision: 5, scale: 2, nullable: true })
6212
+ ], OrderItem.prototype, "taxRate", 2);
6213
+ __decorateClass([
6214
+ Column33("varchar", { nullable: true })
6215
+ ], OrderItem.prototype, "taxCode", 2);
6216
+ __decorateClass([
6217
+ Column33("jsonb", { nullable: true })
6218
+ ], OrderItem.prototype, "metadata", 2);
6219
+ __decorateClass([
6220
+ Column33({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6221
+ ], OrderItem.prototype, "createdAt", 2);
6222
+ __decorateClass([
6223
+ Column33({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6224
+ ], OrderItem.prototype, "updatedAt", 2);
6225
+ __decorateClass([
6226
+ ManyToOne21(() => Order, (o) => o.items, { onDelete: "CASCADE" }),
6227
+ JoinColumn21({ name: "orderId" })
6228
+ ], OrderItem.prototype, "order", 2);
6229
+ __decorateClass([
6230
+ ManyToOne21(() => Product, { onDelete: "CASCADE" }),
6231
+ JoinColumn21({ name: "productId" })
6232
+ ], OrderItem.prototype, "product", 2);
6233
+ OrderItem = __decorateClass([
6234
+ Entity33("order_items")
6235
+ ], OrderItem);
6236
+
6237
+ // src/entities/knowledge-base-document.entity.ts
6238
+ import { Entity as Entity35, PrimaryGeneratedColumn as PrimaryGeneratedColumn35, Column as Column35, OneToMany as OneToMany14 } from "typeorm";
6239
+
6240
+ // src/entities/knowledge-base-chunk.entity.ts
6241
+ import { Entity as Entity34, PrimaryGeneratedColumn as PrimaryGeneratedColumn34, Column as Column34, ManyToOne as ManyToOne22, JoinColumn as JoinColumn22 } from "typeorm";
6242
+ var KnowledgeBaseChunk = class {
6243
+ id;
6244
+ documentId;
6245
+ content;
6246
+ chunkIndex;
6247
+ createdAt;
6248
+ document;
6249
+ };
6250
+ __decorateClass([
6251
+ PrimaryGeneratedColumn34()
6252
+ ], KnowledgeBaseChunk.prototype, "id", 2);
6253
+ __decorateClass([
6254
+ Column34("int")
6255
+ ], KnowledgeBaseChunk.prototype, "documentId", 2);
6256
+ __decorateClass([
6257
+ Column34("text")
6258
+ ], KnowledgeBaseChunk.prototype, "content", 2);
6259
+ __decorateClass([
6260
+ Column34("int", { default: 0 })
6261
+ ], KnowledgeBaseChunk.prototype, "chunkIndex", 2);
6262
+ __decorateClass([
6263
+ Column34({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6264
+ ], KnowledgeBaseChunk.prototype, "createdAt", 2);
6265
+ __decorateClass([
6266
+ ManyToOne22(() => KnowledgeBaseDocument, (d) => d.chunks, { onDelete: "CASCADE" }),
6267
+ JoinColumn22({ name: "documentId" })
6268
+ ], KnowledgeBaseChunk.prototype, "document", 2);
6269
+ KnowledgeBaseChunk = __decorateClass([
6270
+ Entity34("knowledge_base_chunks")
6271
+ ], KnowledgeBaseChunk);
6272
+
6273
+ // src/entities/knowledge-base-document.entity.ts
6274
+ var KnowledgeBaseDocument = class {
6275
+ id;
6276
+ name;
6277
+ sourceUrl;
6278
+ content;
6279
+ createdAt;
6280
+ updatedAt;
6281
+ chunks;
6282
+ };
6283
+ __decorateClass([
6284
+ PrimaryGeneratedColumn35()
6285
+ ], KnowledgeBaseDocument.prototype, "id", 2);
6286
+ __decorateClass([
6287
+ Column35("varchar")
6288
+ ], KnowledgeBaseDocument.prototype, "name", 2);
6289
+ __decorateClass([
6290
+ Column35("varchar", { nullable: true })
6291
+ ], KnowledgeBaseDocument.prototype, "sourceUrl", 2);
6292
+ __decorateClass([
6293
+ Column35("text")
6294
+ ], KnowledgeBaseDocument.prototype, "content", 2);
6295
+ __decorateClass([
6296
+ Column35({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6297
+ ], KnowledgeBaseDocument.prototype, "createdAt", 2);
6298
+ __decorateClass([
6299
+ Column35({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6300
+ ], KnowledgeBaseDocument.prototype, "updatedAt", 2);
6301
+ __decorateClass([
6302
+ OneToMany14(() => KnowledgeBaseChunk, (c) => c.document)
6303
+ ], KnowledgeBaseDocument.prototype, "chunks", 2);
6304
+ KnowledgeBaseDocument = __decorateClass([
6305
+ Entity35("knowledge_base_documents")
6306
+ ], KnowledgeBaseDocument);
6307
+
6308
+ // src/entities/cart.entity.ts
6309
+ import { Entity as Entity36, PrimaryGeneratedColumn as PrimaryGeneratedColumn36, Column as Column36, ManyToOne as ManyToOne23, OneToMany as OneToMany15, JoinColumn as JoinColumn23 } from "typeorm";
6310
+ var Cart = class {
6311
+ id;
6312
+ guestToken;
6313
+ contactId;
6314
+ currency;
6315
+ expiresAt;
6316
+ createdAt;
6317
+ updatedAt;
6318
+ contact;
6319
+ items;
6320
+ };
6321
+ __decorateClass([
6322
+ PrimaryGeneratedColumn36()
6323
+ ], Cart.prototype, "id", 2);
6324
+ __decorateClass([
6325
+ Column36("varchar", { nullable: true })
6326
+ ], Cart.prototype, "guestToken", 2);
6327
+ __decorateClass([
6328
+ Column36("int", { nullable: true })
6329
+ ], Cart.prototype, "contactId", 2);
6330
+ __decorateClass([
6331
+ Column36("varchar", { default: "INR" })
6332
+ ], Cart.prototype, "currency", 2);
6333
+ __decorateClass([
6334
+ Column36({ type: "timestamp", nullable: true })
6335
+ ], Cart.prototype, "expiresAt", 2);
6336
+ __decorateClass([
6337
+ Column36({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6338
+ ], Cart.prototype, "createdAt", 2);
6339
+ __decorateClass([
6340
+ Column36({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6341
+ ], Cart.prototype, "updatedAt", 2);
6342
+ __decorateClass([
6343
+ ManyToOne23(() => Contact, { onDelete: "CASCADE" }),
6344
+ JoinColumn23({ name: "contactId" })
6345
+ ], Cart.prototype, "contact", 2);
6346
+ __decorateClass([
6347
+ OneToMany15("CartItem", "cart")
6348
+ ], Cart.prototype, "items", 2);
6349
+ Cart = __decorateClass([
6350
+ Entity36("carts")
6351
+ ], Cart);
6352
+
6353
+ // src/entities/cart-item.entity.ts
6354
+ import { Entity as Entity37, PrimaryGeneratedColumn as PrimaryGeneratedColumn37, Column as Column37, ManyToOne as ManyToOne24, JoinColumn as JoinColumn24 } from "typeorm";
6355
+ var CartItem = class {
6356
+ id;
6357
+ cartId;
6358
+ productId;
6359
+ quantity;
6360
+ metadata;
6361
+ createdAt;
6362
+ updatedAt;
6363
+ cart;
6364
+ product;
6365
+ };
6366
+ __decorateClass([
6367
+ PrimaryGeneratedColumn37()
6368
+ ], CartItem.prototype, "id", 2);
6369
+ __decorateClass([
6370
+ Column37("int")
6371
+ ], CartItem.prototype, "cartId", 2);
6372
+ __decorateClass([
6373
+ Column37("int")
6374
+ ], CartItem.prototype, "productId", 2);
6375
+ __decorateClass([
6376
+ Column37("int", { default: 1 })
6377
+ ], CartItem.prototype, "quantity", 2);
6378
+ __decorateClass([
6379
+ Column37("jsonb", { nullable: true })
6380
+ ], CartItem.prototype, "metadata", 2);
6381
+ __decorateClass([
6382
+ Column37({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6383
+ ], CartItem.prototype, "createdAt", 2);
6384
+ __decorateClass([
6385
+ Column37({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6386
+ ], CartItem.prototype, "updatedAt", 2);
6387
+ __decorateClass([
6388
+ ManyToOne24(() => Cart, (c) => c.items, { onDelete: "CASCADE" }),
6389
+ JoinColumn24({ name: "cartId" })
6390
+ ], CartItem.prototype, "cart", 2);
6391
+ __decorateClass([
6392
+ ManyToOne24(() => Product, { onDelete: "CASCADE" }),
6393
+ JoinColumn24({ name: "productId" })
6394
+ ], CartItem.prototype, "product", 2);
6395
+ CartItem = __decorateClass([
6396
+ Entity37("cart_items")
6397
+ ], CartItem);
6398
+
6399
+ // src/entities/wishlist.entity.ts
6400
+ import { Entity as Entity38, PrimaryGeneratedColumn as PrimaryGeneratedColumn38, Column as Column38, ManyToOne as ManyToOne25, OneToMany as OneToMany16, JoinColumn as JoinColumn25 } from "typeorm";
6401
+ var Wishlist = class {
6402
+ id;
6403
+ guestId;
6404
+ contactId;
6405
+ name;
6406
+ createdAt;
6407
+ updatedAt;
6408
+ contact;
6409
+ items;
6410
+ };
6411
+ __decorateClass([
6412
+ PrimaryGeneratedColumn38()
6413
+ ], Wishlist.prototype, "id", 2);
6414
+ __decorateClass([
6415
+ Column38("varchar", { nullable: true })
6416
+ ], Wishlist.prototype, "guestId", 2);
6417
+ __decorateClass([
6418
+ Column38("int", { nullable: true })
6419
+ ], Wishlist.prototype, "contactId", 2);
6420
+ __decorateClass([
6421
+ Column38("varchar", { default: "default" })
6422
+ ], Wishlist.prototype, "name", 2);
6423
+ __decorateClass([
6424
+ Column38({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6425
+ ], Wishlist.prototype, "createdAt", 2);
6426
+ __decorateClass([
6427
+ Column38({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6428
+ ], Wishlist.prototype, "updatedAt", 2);
6429
+ __decorateClass([
6430
+ ManyToOne25(() => Contact, { onDelete: "CASCADE" }),
6431
+ JoinColumn25({ name: "contactId" })
6432
+ ], Wishlist.prototype, "contact", 2);
6433
+ __decorateClass([
6434
+ OneToMany16("WishlistItem", "wishlist")
6435
+ ], Wishlist.prototype, "items", 2);
6436
+ Wishlist = __decorateClass([
6437
+ Entity38("wishlists")
6438
+ ], Wishlist);
6439
+
6440
+ // src/entities/wishlist-item.entity.ts
6441
+ import { Entity as Entity39, PrimaryGeneratedColumn as PrimaryGeneratedColumn39, Column as Column39, ManyToOne as ManyToOne26, JoinColumn as JoinColumn26 } from "typeorm";
6442
+ var WishlistItem = class {
6443
+ id;
6444
+ wishlistId;
6445
+ productId;
6446
+ metadata;
6447
+ createdAt;
6448
+ updatedAt;
6449
+ wishlist;
6450
+ product;
6451
+ };
6452
+ __decorateClass([
6453
+ PrimaryGeneratedColumn39()
6454
+ ], WishlistItem.prototype, "id", 2);
6455
+ __decorateClass([
6456
+ Column39("int")
6457
+ ], WishlistItem.prototype, "wishlistId", 2);
6458
+ __decorateClass([
6459
+ Column39("int")
6460
+ ], WishlistItem.prototype, "productId", 2);
6461
+ __decorateClass([
6462
+ Column39("jsonb", { nullable: true })
6463
+ ], WishlistItem.prototype, "metadata", 2);
6464
+ __decorateClass([
6465
+ Column39({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6466
+ ], WishlistItem.prototype, "createdAt", 2);
6467
+ __decorateClass([
6468
+ Column39({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6469
+ ], WishlistItem.prototype, "updatedAt", 2);
6470
+ __decorateClass([
6471
+ ManyToOne26(() => Wishlist, (w) => w.items, { onDelete: "CASCADE" }),
6472
+ JoinColumn26({ name: "wishlistId" })
6473
+ ], WishlistItem.prototype, "wishlist", 2);
6474
+ __decorateClass([
6475
+ ManyToOne26(() => Product, { onDelete: "CASCADE" }),
6476
+ JoinColumn26({ name: "productId" })
6477
+ ], WishlistItem.prototype, "product", 2);
6478
+ WishlistItem = __decorateClass([
6479
+ Entity39("wishlist_items")
6480
+ ], WishlistItem);
6481
+
6482
+ // src/entities/llm-agent-knowledge-document.entity.ts
6483
+ import { Entity as Entity40, PrimaryGeneratedColumn as PrimaryGeneratedColumn40, Column as Column40, ManyToOne as ManyToOne27, JoinColumn as JoinColumn27, Index as Index2, Unique as Unique2 } from "typeorm";
6484
+ var LlmAgentKnowledgeDocument = class {
6485
+ id;
6486
+ agentId;
6487
+ documentId;
6488
+ createdAt;
6489
+ agent;
6490
+ document;
6491
+ };
6492
+ __decorateClass([
6493
+ PrimaryGeneratedColumn40()
6494
+ ], LlmAgentKnowledgeDocument.prototype, "id", 2);
6495
+ __decorateClass([
6496
+ Column40("int")
6497
+ ], LlmAgentKnowledgeDocument.prototype, "agentId", 2);
6498
+ __decorateClass([
6499
+ Column40("int")
6500
+ ], LlmAgentKnowledgeDocument.prototype, "documentId", 2);
6501
+ __decorateClass([
6502
+ Column40({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6503
+ ], LlmAgentKnowledgeDocument.prototype, "createdAt", 2);
6504
+ __decorateClass([
6505
+ ManyToOne27(() => LlmAgent, { onDelete: "CASCADE" }),
6506
+ JoinColumn27({ name: "agentId" })
6507
+ ], LlmAgentKnowledgeDocument.prototype, "agent", 2);
6508
+ __decorateClass([
6509
+ ManyToOne27(() => KnowledgeBaseDocument, { onDelete: "CASCADE" }),
6510
+ JoinColumn27({ name: "documentId" })
6511
+ ], LlmAgentKnowledgeDocument.prototype, "document", 2);
6512
+ LlmAgentKnowledgeDocument = __decorateClass([
6513
+ Entity40("llm_agent_knowledge_documents"),
6514
+ Unique2("UQ_llm_agent_knowledge_agent_document", ["agentId", "documentId"]),
6515
+ Index2("IDX_llm_agent_knowledge_agent", ["agentId"])
6516
+ ], LlmAgentKnowledgeDocument);
6517
+
6518
+ // src/entities/index.ts
6519
+ var CMS_ENTITY_MAP = {
6520
+ users: User,
6521
+ otp_challenges: OtpChallenge,
6522
+ password_reset_tokens: PasswordResetToken,
6523
+ user_groups: UserGroup,
6524
+ permissions: Permission,
6525
+ blogs: Blog,
6526
+ tags: Tag,
6527
+ categories: Category,
6528
+ comments: Comment,
6529
+ contacts: Contact,
6530
+ addresses: Address,
6531
+ forms: Form,
6532
+ form_fields: FormField,
6533
+ form_submissions: FormSubmission,
6534
+ seos: Seo,
6535
+ configs: Config,
6536
+ message_templates: MessageTemplate,
6537
+ media: Media,
6538
+ pages: Page,
6539
+ product_categories: ProductCategory,
6540
+ collections: Collection,
6541
+ products: Product,
6542
+ attributes: Attribute,
6543
+ product_attributes: ProductAttribute,
6544
+ taxes: Tax,
6545
+ product_taxes: ProductTax,
6546
+ orders: Order,
6547
+ order_items: OrderItem,
6548
+ payments: Payment,
6549
+ brands: Brand,
6550
+ knowledge_base_documents: KnowledgeBaseDocument,
6551
+ knowledge_base_chunks: KnowledgeBaseChunk,
6552
+ chat_conversations: ChatConversation,
6553
+ chat_messages: ChatMessage,
6554
+ carts: Cart,
6555
+ cart_items: CartItem,
6556
+ wishlists: Wishlist,
6557
+ wishlist_items: WishlistItem,
6558
+ llm_agents: LlmAgent,
6559
+ llm_agent_knowledge_documents: LlmAgentKnowledgeDocument
6560
+ };
6561
+
6562
+ // src/api/cms-api-handler.ts
6563
+ var KNOWLEDGE_SUFFIX = "knowledge";
6564
+ var CMS_API_LOG = "[cms-api]";
6565
+ function withLlmKnowledgeEntityFallbacks(base) {
6566
+ const keys = [
6567
+ "llm_agents",
6568
+ "llm_agent_knowledge_documents",
6569
+ "knowledge_base_documents",
6570
+ "knowledge_base_chunks"
6571
+ ];
6572
+ const patch = {};
6573
+ for (const key of keys) {
6574
+ if (!(key in base) || base[key] == null) {
6575
+ const fallback = CMS_ENTITY_MAP[key];
6576
+ if (fallback) patch[key] = fallback;
6577
+ }
6578
+ }
6579
+ const merged = Object.keys(patch).length > 0 ? { ...base, ...patch } : base;
6580
+ if (!merged.llm_agents) {
6581
+ const agent = CMS_ENTITY_MAP.llm_agents ?? LlmAgent;
6582
+ return { ...merged, llm_agents: agent };
6583
+ }
6584
+ return merged;
6585
+ }
6586
+ function matchLlmAgentKnowledgeRoute(path) {
6587
+ const p = path[0] === "api" ? path.slice(1) : path;
6588
+ if (p[0] !== "llm_agents" || p.length < 2) return null;
6589
+ const seg1 = p[1];
6590
+ if (!seg1) return null;
6591
+ if (p[2] === KNOWLEDGE_SUFFIX) {
6592
+ return {
6593
+ slug: seg1,
6594
+ documentId: p.length >= 4 ? p[3] : void 0
6595
+ };
6596
+ }
6597
+ if (seg1.endsWith(KNOWLEDGE_SUFFIX) && seg1.length > KNOWLEDGE_SUFFIX.length) {
6598
+ const slug = seg1.slice(0, -KNOWLEDGE_SUFFIX.length);
6599
+ if (!slug) return null;
6600
+ if (p.length === 2) return { slug, documentId: void 0 };
6601
+ if (p.length === 3) return { slug, documentId: p[2] };
6602
+ }
6603
+ return null;
6604
+ }
6605
+ var DEFAULT_EXCLUDE = /* @__PURE__ */ new Set([
6606
+ "users",
6607
+ "password_reset_tokens",
6608
+ "user_groups",
6609
+ "permissions",
6610
+ "comments",
6611
+ "form_fields",
6612
+ "configs",
6613
+ "carts",
6614
+ "cart_items",
6615
+ "wishlists",
6616
+ "wishlist_items",
6617
+ "message_templates",
6618
+ "llm_agent_knowledge_documents"
6619
+ ]);
6620
+ function createCmsApiHandler(config) {
6621
+ const {
6622
+ dataSource,
6623
+ entityMap: rawEntityMap,
6624
+ pathToModel = (s) => s,
6625
+ crudResources: crudResourcesOverride,
6626
+ getCms,
6627
+ userAuth: userAuthConfig,
6628
+ dashboard,
6629
+ ecommerceAnalytics,
6630
+ analytics: analyticsConfig,
6631
+ upload,
6632
+ blogBySlug,
6633
+ formBySlug,
6634
+ formSave: formSaveConfig,
6635
+ formSubmission: formSubmissionConfig,
6636
+ formSubmissionGetById: formSubmissionGetByIdConfig,
6637
+ usersApi,
6638
+ userAvatar,
6639
+ userProfile,
6640
+ settings: settingsConfig,
6641
+ chat: chatConfig,
6642
+ llmAgentKnowledge: llmAgentKnowledgeConfig,
6643
+ requireEntityPermission: userRequireEntityPermission,
6644
+ getSessionUser
6645
+ } = config;
6646
+ const entityMap = withLlmKnowledgeEntityFallbacks(rawEntityMap);
6647
+ const baseCrudResources = crudResourcesOverride ?? Object.keys(entityMap).filter((k) => !DEFAULT_EXCLUDE.has(k));
6648
+ const crudResources = entityMap.llm_agents && !baseCrudResources.includes("llm_agents") ? [...baseCrudResources, "llm_agents"] : baseCrudResources;
6649
+ const requireEntityPermissionEffective = userRequireEntityPermission ?? (async (_req, entity, action) => config.json({ error: "Forbidden", reason: "entity_rbac_required", entity, action }, { status: 403 }));
6650
+ const analytics = analyticsConfig ?? (getCms ? {
6651
+ json: config.json,
6652
+ requireAuth: async () => null,
6653
+ getAnalyticsData: async (days) => {
6654
+ const cms = await getCms();
6655
+ const a = cms.getPlugin("analytics");
6656
+ if (!a?.getAnalyticsData) throw new Error("Analytics not configured");
6657
+ return a.getAnalyticsData(days);
6658
+ },
6659
+ getPropertyId: () => ({ currentViewId: process.env.GOOGLE_ANALYTICS_VIEW_ID }),
6660
+ getPermissions: () => ({
6661
+ serviceAccountEmail: process.env.GOOGLE_ANALYTICS_CLIENT_EMAIL,
6662
+ currentViewId: process.env.GOOGLE_ANALYTICS_VIEW_ID
6663
+ })
6664
+ } : void 0);
6665
+ const userAuth = userAuthConfig && getCms && userAuthConfig.sendEmail === void 0 ? {
6666
+ ...userAuthConfig,
6667
+ sendEmail: async (opts) => {
6668
+ const cms = await getCms();
6669
+ const queue = cms.getPlugin("queue");
6670
+ const companyDetails = config.getCompanyDetails ? await config.getCompanyDetails() : {};
6671
+ const resetLink = typeof opts.resetLink === "string" && opts.resetLink.trim() || typeof opts.text === "string" && opts.text.trim() || (typeof opts.html === "string" ? opts.html.match(/href\s*=\s*["']([^"']+)["']/)?.[1] ?? "" : "");
6672
+ const ctx = { resetLink, companyDetails };
6673
+ if (queue) {
6674
+ const { queueEmail: queueEmail2 } = await Promise.resolve().then(() => (init_email_queue(), email_queue_exports));
6675
+ await queueEmail2(cms, { to: opts.to, templateName: "passwordReset", ctx });
6676
+ return;
6677
+ }
6678
+ const email = cms.getPlugin("email");
6679
+ if (!email?.send) return;
6680
+ const rendered = email.renderTemplate("passwordReset", ctx);
6681
+ await email.send({ subject: rendered.subject, html: rendered.html, text: rendered.text, to: opts.to });
6682
+ }
6683
+ } : userAuthConfig;
6684
+ const crudOpts = {
6685
+ requireAuth: config.requireAuth,
6686
+ json: config.json,
6687
+ requireEntityPermission: requireEntityPermissionEffective,
6688
+ getCms,
6689
+ ...getSessionUser ? {
6690
+ getDeletedByUserId: async () => {
6691
+ const u = await getSessionUser();
6692
+ if (!u?.id) return null;
6693
+ const n = Number(u.id);
6694
+ return Number.isFinite(n) ? n : null;
6695
+ }
6696
+ } : {}
6697
+ };
6698
+ const crud = createCrudHandler(dataSource, entityMap, crudOpts);
6699
+ const crudById = createCrudByIdHandler(dataSource, entityMap, crudOpts);
6700
+ const mergePerm = (c) => !c ? void 0 : { ...c, requireEntityPermission: requireEntityPermissionEffective };
6701
+ const adminRoles = getSessionUser && createAdminRolesHandlers({
6702
+ dataSource,
6703
+ entityMap,
6704
+ json: config.json,
6705
+ getSessionUser
6706
+ });
6707
+ const userAuthRouter = userAuth ? createUserAuthApiRouter(userAuth) : null;
6708
+ const dashboardGet = dashboard ? createDashboardStatsHandler(mergePerm(dashboard) ?? dashboard) : null;
6709
+ const ecommerceAnalyticsResolved = mergePerm(
6710
+ ecommerceAnalytics ?? {
6711
+ dataSource,
6712
+ entityMap,
6713
+ json: config.json,
6714
+ requireAuth: config.requireAuth
6715
+ }
6716
+ );
6717
+ const ecommerceAnalyticsGet = createEcommerceAnalyticsHandler(ecommerceAnalyticsResolved);
6718
+ const analyticsHandlers = analytics ? createAnalyticsHandlers(analytics) : null;
6719
+ const uploadMerged = upload ? {
6720
+ ...mergePerm(upload) ?? upload,
6721
+ dataSource: upload.dataSource ?? dataSource,
6722
+ entityMap: upload.entityMap ?? entityMap
6723
+ } : null;
6724
+ const uploadPost = uploadMerged ? createUploadHandler(uploadMerged) : null;
6725
+ const zipExtractPost = uploadMerged ? createMediaZipExtractHandler(uploadMerged) : null;
6726
+ const blogBySlugGet = blogBySlug ? createBlogBySlugHandler(blogBySlug) : null;
6727
+ const formBySlugGet = formBySlug ? createFormBySlugHandler(formBySlug) : null;
6728
+ const formSaveHandlers = formSaveConfig ? createFormSaveHandlers(mergePerm(formSaveConfig) ?? formSaveConfig) : null;
6729
+ const formSubmissionPost = formSubmissionConfig ? createFormSubmissionHandler(formSubmissionConfig) : null;
6730
+ const formSubmissionGetById = formSubmissionGetByIdConfig ? createFormSubmissionGetByIdHandler(mergePerm(formSubmissionGetByIdConfig) ?? formSubmissionGetByIdConfig) : null;
6731
+ const formSubmissionList = formSubmissionGetByIdConfig ? createFormSubmissionListHandler(mergePerm(formSubmissionGetByIdConfig) ?? formSubmissionGetByIdConfig) : null;
6732
+ const usersApiMerged = usersApi && getCms ? {
6733
+ ...usersApi,
6734
+ getCms: usersApi.getCms ?? getCms,
6735
+ getCompanyDetails: usersApi.getCompanyDetails ?? config.getCompanyDetails,
3810
6736
  ...getSessionUser ? { getSessionUser: usersApi.getSessionUser ?? getSessionUser } : {}
3811
6737
  } : usersApi ? {
3812
6738
  ...usersApi,
@@ -3826,7 +6752,7 @@ function createCmsApiHandler(config) {
3826
6752
  const chatHandlers = chatConfig ? createChatHandlers(chatConfig) : null;
3827
6753
  const llmAgentKnowledgeMerged = llmAgentKnowledgeConfig ?? (chatConfig ? {
3828
6754
  dataSource: chatConfig.dataSource,
3829
- entityMap: chatConfig.entityMap,
6755
+ entityMap: withLlmKnowledgeEntityFallbacks(chatConfig.entityMap ?? rawEntityMap),
3830
6756
  getCms: chatConfig.getCms,
3831
6757
  json: chatConfig.json,
3832
6758
  requireAuth: chatConfig.requireAuth
@@ -3840,7 +6766,9 @@ function createCmsApiHandler(config) {
3840
6766
  return crudResources.includes(model) ? model : segment;
3841
6767
  }
3842
6768
  return {
3843
- async handle(method, path, req) {
6769
+ async handle(method, pathInput, req) {
6770
+ const m = typeof method === "string" ? method.toUpperCase() : "GET";
6771
+ const path = pathInput.length > 0 && pathInput[0] === "api" ? pathInput.slice(1) : pathInput;
3844
6772
  async function analyticsGate() {
3845
6773
  const a = await config.requireAuth(req);
3846
6774
  if (a) return a;
@@ -3848,86 +6776,86 @@ function createCmsApiHandler(config) {
3848
6776
  }
3849
6777
  if (path[0] === "admin" && path[1] === "roles") {
3850
6778
  if (!adminRoles) return config.json({ error: "Not found" }, { status: 404 });
3851
- if (path.length === 2 && method === "GET") return adminRoles.list();
3852
- if (path.length === 2 && method === "POST") return adminRoles.createGroup(req);
3853
- if (path.length === 3 && method === "PATCH") return adminRoles.patchGroup(req, path[2]);
3854
- if (path.length === 3 && method === "DELETE") return adminRoles.deleteGroup(path[2]);
3855
- if (path.length === 4 && path[3] === "permissions" && method === "PUT") return adminRoles.putPermissions(req, path[2]);
6779
+ if (path.length === 2 && m === "GET") return adminRoles.list();
6780
+ if (path.length === 2 && m === "POST") return adminRoles.createGroup(req);
6781
+ if (path.length === 3 && m === "PATCH") return adminRoles.patchGroup(req, path[2]);
6782
+ if (path.length === 3 && m === "DELETE") return adminRoles.deleteGroup(path[2]);
6783
+ if (path.length === 4 && path[3] === "permissions" && m === "PUT") return adminRoles.putPermissions(req, path[2]);
3856
6784
  return config.json({ error: "Not found" }, { status: 404 });
3857
6785
  }
3858
- if (path[0] === "dashboard" && path[1] === "stats" && path.length === 2 && method === "GET" && dashboardGet) {
6786
+ if (path[0] === "dashboard" && path[1] === "stats" && path.length === 2 && m === "GET" && dashboardGet) {
3859
6787
  return dashboardGet(req);
3860
6788
  }
3861
- if (path[0] === "dashboard" && path[1] === "ecommerce" && path.length === 2 && method === "GET" && ecommerceAnalyticsGet) {
6789
+ if (path[0] === "dashboard" && path[1] === "ecommerce" && path.length === 2 && m === "GET" && ecommerceAnalyticsGet) {
3862
6790
  const g = await analyticsGate();
3863
6791
  if (g) return g;
3864
6792
  return ecommerceAnalyticsGet(req);
3865
6793
  }
3866
6794
  if (path[0] === "analytics" && analyticsHandlers) {
3867
- if (path.length === 1 && method === "GET") {
6795
+ if (path.length === 1 && m === "GET") {
3868
6796
  const g = await analyticsGate();
3869
6797
  if (g) return g;
3870
6798
  return analyticsHandlers.GET(req);
3871
6799
  }
3872
- if (path.length === 2 && path[1] === "property-id" && method === "GET") {
6800
+ if (path.length === 2 && path[1] === "property-id" && m === "GET") {
3873
6801
  const g = await analyticsGate();
3874
6802
  if (g) return g;
3875
6803
  return analyticsHandlers.propertyId();
3876
6804
  }
3877
- if (path.length === 2 && path[1] === "permissions" && method === "GET") {
6805
+ if (path.length === 2 && path[1] === "permissions" && m === "GET") {
3878
6806
  const g = await analyticsGate();
3879
6807
  if (g) return g;
3880
6808
  return analyticsHandlers.permissions();
3881
6809
  }
3882
6810
  }
3883
- if (path[0] === "upload" && path.length === 1 && method === "POST" && uploadPost) return uploadPost(req);
3884
- if (path[0] === "media" && path[1] === "extract" && path.length === 3 && method === "POST" && zipExtractPost) {
6811
+ if (path[0] === "upload" && path.length === 1 && m === "POST" && uploadPost) return uploadPost(req);
6812
+ if (path[0] === "media" && path[1] === "extract" && path.length === 3 && m === "POST" && zipExtractPost) {
3885
6813
  return zipExtractPost(req, path[2]);
3886
6814
  }
3887
- if (path[0] === "blogs" && path[1] === "slug" && path.length === 3 && method === "GET" && blogBySlugGet) {
6815
+ if (path[0] === "blogs" && path[1] === "slug" && path.length === 3 && m === "GET" && blogBySlugGet) {
3888
6816
  return blogBySlugGet(req, path[2]);
3889
6817
  }
3890
- if (path[0] === "forms" && path[1] === "slug" && path.length === 3 && method === "GET" && formBySlugGet) {
6818
+ if (path[0] === "forms" && path[1] === "slug" && path.length === 3 && m === "GET" && formBySlugGet) {
3891
6819
  return formBySlugGet(req, path[2]);
3892
6820
  }
3893
6821
  if (path[0] === "form-submissions") {
3894
6822
  if (path.length === 1) {
3895
- if (method === "GET" && formSubmissionList) return formSubmissionList(req);
3896
- if (method === "POST" && formSubmissionPost) return formSubmissionPost(req);
6823
+ if (m === "GET" && formSubmissionList) return formSubmissionList(req);
6824
+ if (m === "POST" && formSubmissionPost) return formSubmissionPost(req);
3897
6825
  }
3898
- if (path.length === 2 && method === "GET" && formSubmissionGetById) return formSubmissionGetById(req, path[1]);
6826
+ if (path.length === 2 && m === "GET" && formSubmissionGetById) return formSubmissionGetById(req, path[1]);
3899
6827
  }
3900
6828
  if (path[0] === "forms" && formSaveHandlers) {
3901
- if (path.length === 1 && method === "POST") return formSaveHandlers.POST(req);
6829
+ if (path.length === 1 && m === "POST") return formSaveHandlers.POST(req);
3902
6830
  if (path.length === 2) {
3903
- if (method === "GET") return formSaveHandlers.GET(req, path[1]);
3904
- if (method === "PUT" || method === "PATCH") return formSaveHandlers.PUT(req, path[1]);
6831
+ if (m === "GET") return formSaveHandlers.GET(req, path[1]);
6832
+ if (m === "PUT" || m === "PATCH") return formSaveHandlers.PUT(req, path[1]);
3905
6833
  }
3906
6834
  }
3907
6835
  if (path[0] === "users" && usersHandlers) {
3908
6836
  if (path.length === 1) {
3909
- if (method === "GET") return usersHandlers.list(req);
3910
- if (method === "POST") return usersHandlers.create(req);
6837
+ if (m === "GET") return usersHandlers.list(req);
6838
+ if (m === "POST") return usersHandlers.create(req);
3911
6839
  }
3912
6840
  if (path.length === 2) {
3913
- if (path[1] === "avatar" && method === "POST" && avatarPost) return avatarPost(req);
3914
- if (path[1] === "profile" && method === "PUT" && profilePut) return profilePut(req);
6841
+ if (path[1] === "avatar" && m === "POST" && avatarPost) return avatarPost(req);
6842
+ if (path[1] === "profile" && m === "PUT" && profilePut) return profilePut(req);
3915
6843
  const id = path[1];
3916
- if (method === "GET") return usersHandlers.getById(req, id);
3917
- if (method === "PUT" || method === "PATCH") return usersHandlers.update(req, id);
3918
- if (method === "DELETE") return usersHandlers.delete(req, id);
6844
+ if (m === "GET") return usersHandlers.getById(req, id);
6845
+ if (m === "PUT" || m === "PATCH") return usersHandlers.update(req, id);
6846
+ if (m === "DELETE") return usersHandlers.delete(req, id);
3919
6847
  }
3920
- if (path.length === 3 && path[2] === "regenerate-invite" && method === "POST") {
6848
+ if (path.length === 3 && path[2] === "regenerate-invite" && m === "POST") {
3921
6849
  return usersHandlers.regenerateInvite(req, path[1]);
3922
6850
  }
3923
6851
  }
3924
- if (path[0] === "users" && path.length === 2 && userAuthRouter && method === "POST") {
6852
+ if (path[0] === "users" && path.length === 2 && userAuthRouter && m === "POST") {
3925
6853
  return userAuthRouter.POST(req, path[1]);
3926
6854
  }
3927
6855
  if (path[0] === "settings" && path.length === 2 && settingsHandlers) {
3928
6856
  const group = path[1];
3929
6857
  const isPublic = settingsConfig?.publicGetGroups?.includes(group);
3930
- if (method === "GET") {
6858
+ if (m === "GET") {
3931
6859
  if (!isPublic) {
3932
6860
  const a = await config.requireAuth(req);
3933
6861
  if (a) return a;
@@ -3936,15 +6864,38 @@ function createCmsApiHandler(config) {
3936
6864
  }
3937
6865
  return settingsHandlers.GET(req, group);
3938
6866
  }
3939
- if (method === "PUT") {
6867
+ if (m === "PUT") {
3940
6868
  const pe = await requireEntityPermissionEffective(req, "settings", "update");
3941
6869
  if (pe) return pe;
3942
6870
  return settingsHandlers.PUT(req, group);
3943
6871
  }
3944
6872
  }
3945
6873
  if (path[0] === "message-templates" && path[1] === "sms" && path.length === 2) {
3946
- if (method === "GET") return smsMessageTemplateHandlers.GET(req);
3947
- if (method === "PUT") return smsMessageTemplateHandlers.PUT(req);
6874
+ if (m === "GET") return smsMessageTemplateHandlers.GET(req);
6875
+ if (m === "PUT") return smsMessageTemplateHandlers.PUT(req);
6876
+ }
6877
+ if (path[0] === "llm_agents") {
6878
+ if (!entityMap.llm_agents) {
6879
+ console.error(CMS_API_LOG, "llm_agents route: entity missing after merge", {
6880
+ method: m,
6881
+ pathJoined: path.join("/"),
6882
+ entityMapKeyCount: Object.keys(entityMap).length
6883
+ });
6884
+ return config.json(
6885
+ { error: "LlmAgent entity is not registered", hint: "Ensure migrations ran and entities include LlmAgent." },
6886
+ { status: 503 }
6887
+ );
6888
+ }
6889
+ if (path.length === 1) {
6890
+ if (m === "GET") return crud.GET(req, "llm_agents");
6891
+ if (m === "POST") return crud.POST(req, "llm_agents");
6892
+ }
6893
+ if (path.length === 2 && !path[1]?.includes("knowledge")) {
6894
+ const id = path[1];
6895
+ if (m === "GET") return crudById.GET(req, "llm_agents", id);
6896
+ if (m === "PUT" || m === "PATCH") return crudById.PUT(req, "llm_agents", id);
6897
+ if (m === "DELETE") return crudById.DELETE(req, "llm_agents", id);
6898
+ }
3948
6899
  }
3949
6900
  {
3950
6901
  const kbMatch = matchLlmAgentKnowledgeRoute(path);
@@ -3959,24 +6910,24 @@ function createCmsApiHandler(config) {
3959
6910
  );
3960
6911
  }
3961
6912
  const { slug, documentId } = kbMatch;
3962
- if (method === "DELETE" && documentId != null && documentId !== "") {
6913
+ if (m === "DELETE" && documentId != null && documentId !== "") {
3963
6914
  return llmAgentKnowledgeHandlers.unlink(req, slug, documentId);
3964
6915
  }
3965
- if (method === "GET" && (documentId == null || documentId === "")) {
6916
+ if (m === "GET" && (documentId == null || documentId === "")) {
3966
6917
  return llmAgentKnowledgeHandlers.list(req, slug);
3967
6918
  }
3968
- if (method === "POST" && (documentId == null || documentId === "")) {
6919
+ if (m === "POST" && (documentId == null || documentId === "")) {
3969
6920
  return llmAgentKnowledgeHandlers.post(req, slug);
3970
6921
  }
3971
6922
  }
3972
6923
  }
3973
6924
  if (path[0] === "chat" && chatHandlers) {
3974
- if (path.length === 2 && path[1] === "config" && method === "GET") return chatHandlers.publicConfig(req);
3975
- if (path.length === 2 && path[1] === "identify" && method === "POST") return chatHandlers.identify(req);
3976
- if (path.length === 4 && path[1] === "conversations" && path[3] === "messages" && method === "GET") return chatHandlers.getMessages(req, path[2]);
3977
- if (path.length === 2 && path[1] === "messages" && method === "POST") return chatHandlers.postMessage(req);
6925
+ if (path.length === 2 && path[1] === "config" && m === "GET") return chatHandlers.publicConfig(req);
6926
+ if (path.length === 2 && path[1] === "identify" && m === "POST") return chatHandlers.identify(req);
6927
+ if (path.length === 4 && path[1] === "conversations" && path[3] === "messages" && m === "GET") return chatHandlers.getMessages(req, path[2]);
6928
+ if (path.length === 2 && path[1] === "messages" && m === "POST") return chatHandlers.postMessage(req);
3978
6929
  }
3979
- if (path[0] === "orders" && path.length === 3 && path[2] === "invoice" && method === "GET" && getCms) {
6930
+ if (path[0] === "orders" && path.length === 3 && path[2] === "invoice" && m === "GET" && getCms) {
3980
6931
  const a = await config.requireAuth(req);
3981
6932
  if (a) return a;
3982
6933
  const pe = await requireEntityPermissionEffective(req, "orders", "read");
@@ -3990,17 +6941,17 @@ function createCmsApiHandler(config) {
3990
6941
  if (path[0] === "orders" && path.length === 3 && path[2] === "repost-erp" && getCms) {
3991
6942
  const a = await config.requireAuth(req);
3992
6943
  if (a) return a;
3993
- const pe = await requireEntityPermissionEffective(req, "orders", method === "GET" ? "read" : "update");
6944
+ const pe = await requireEntityPermissionEffective(req, "orders", m === "GET" ? "read" : "update");
3994
6945
  if (pe) return pe;
3995
6946
  const oid = Number(path[1]);
3996
6947
  if (!Number.isFinite(oid)) return config.json({ error: "Invalid id" }, { status: 400 });
3997
6948
  const cms = await getCms();
3998
6949
  const { isErpIntegrationEnabled: isErpIntegrationEnabled3 } = await Promise.resolve().then(() => (init_erp_config_enabled(), erp_config_enabled_exports));
3999
6950
  const enabled = await isErpIntegrationEnabled3(cms, dataSource, entityMap);
4000
- if (method === "GET") {
6951
+ if (m === "GET") {
4001
6952
  return config.json({ enabled });
4002
6953
  }
4003
- if (method === "POST") {
6954
+ if (m === "POST") {
4004
6955
  if (!enabled) return config.json({ error: "ERP integration is disabled" }, { status: 409 });
4005
6956
  const { queueErpPaidOrderForOrderId: queueErpPaidOrderForOrderId2 } = await Promise.resolve().then(() => (init_paid_order_erp(), paid_order_erp_exports));
4006
6957
  await queueErpPaidOrderForOrderId2(cms, dataSource, entityMap, oid);
@@ -4010,28 +6961,39 @@ function createCmsApiHandler(config) {
4010
6961
  }
4011
6962
  if (path.length === 0) return config.json({ error: "Not found" }, { status: 404 });
4012
6963
  const resource = resolveResource(path[0]);
4013
- if (!crudResources.includes(resource)) return config.json({ error: "Invalid resource" }, { status: 400 });
6964
+ if (!crudResources.includes(resource)) {
6965
+ console.warn(CMS_API_LOG, "generic CRUD gate: Invalid resource (not in crudResources)", {
6966
+ method: m,
6967
+ pathJoined: path.join("/"),
6968
+ pathSegments: path,
6969
+ resource,
6970
+ hasLlmAgentsEntity: Boolean(entityMap.llm_agents),
6971
+ crudResourcesHasResource: crudResources.includes(resource),
6972
+ crudResourcesLength: crudResources.length
6973
+ });
6974
+ return config.json({ error: "Invalid resource" }, { status: 400 });
6975
+ }
4014
6976
  if (path.length === 2) {
4015
- if (path[1] === "metadata" && method === "GET") {
6977
+ if (path[1] === "metadata" && m === "GET") {
4016
6978
  return crud.GET_METADATA(req, resource);
4017
6979
  }
4018
- if (path[1] === "bulk" && method === "POST") {
6980
+ if (path[1] === "bulk" && m === "POST") {
4019
6981
  return crud.BULK_POST(req, resource);
4020
6982
  }
4021
- if (path[1] === "export" && method === "GET") {
6983
+ if (path[1] === "export" && m === "GET") {
4022
6984
  return crud.GET_EXPORT(req, resource);
4023
6985
  }
4024
6986
  }
4025
6987
  if (path.length === 1) {
4026
- if (method === "GET") return crud.GET(req, resource);
4027
- if (method === "POST") return crud.POST(req, resource);
6988
+ if (m === "GET") return crud.GET(req, resource);
6989
+ if (m === "POST") return crud.POST(req, resource);
4028
6990
  return config.json({ error: "Method not allowed" }, { status: 405 });
4029
6991
  }
4030
6992
  if (path.length === 2) {
4031
6993
  const id = path[1];
4032
- if (method === "GET") return crudById.GET(req, resource, id);
4033
- if (method === "PUT" || method === "PATCH") return crudById.PUT(req, resource, id);
4034
- if (method === "DELETE") return crudById.DELETE(req, resource, id);
6994
+ if (m === "GET") return crudById.GET(req, resource, id);
6995
+ if (m === "PUT" || m === "PATCH") return crudById.PUT(req, resource, id);
6996
+ if (m === "DELETE") return crudById.DELETE(req, resource, id);
4035
6997
  return config.json({ error: "Method not allowed" }, { status: 405 });
4036
6998
  }
4037
6999
  return config.json({ error: "Not found" }, { status: 404 });