@infuro/cms-core 1.0.20 → 1.0.22

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