From 0a484e0b45000c43e445273ed8f41ed9783c8fd5 Mon Sep 17 00:00:00 2001 From: phaichayon Date: Tue, 16 Jun 2026 17:01:29 +0700 Subject: [PATCH] task-i --- ...009-approved-document-storage-lifecycle.md | 30 +- ...1-enquiry-assignment-role-stabilization.md | 144 + .../task-h1-pdf-generation-stabilization.md | 122 + .../task-i-storage-artifact-lifecycle.md | 155 + docs/implementation/technical-debt.md | 106 + drizzle/0009_lazy_shard.sql | 30 + drizzle/meta/0009_snapshot.json | 3192 +++++++++++++++++ drizzle/meta/_journal.json | 7 + package-lock.json | 681 ++++ package.json | 2 + plans/task-i.md | 475 +++ scripts/seed-task-h1-fixture.js | 10 +- .../document-artifacts/[id]/download/route.ts | 36 + .../crm/quotations/[id]/approved-pdf/route.ts | 8 +- src/db/schema.ts | 29 + src/features/crm/quotations/api/types.ts | 18 + .../components/quotation-detail.tsx | 645 +++- src/features/crm/quotations/server/service.ts | 163 +- .../foundation/approval/server/service.ts | 48 +- .../document-artifact/server/service.ts | 313 ++ .../pdf-generator/server/service.ts | 229 +- .../foundation/storage/server/checksum.ts | 5 + .../storage/server/local-provider.ts | 77 + .../foundation/storage/server/provider.ts | 24 + .../foundation/storage/server/s3-provider.ts | 126 + src/features/foundation/storage/service.ts | 20 + src/features/foundation/storage/types.ts | 50 + src/lib/auth/rbac.ts | 15 + 28 files changed, 6483 insertions(+), 277 deletions(-) create mode 100644 docs/implementation/task-d1-enquiry-assignment-role-stabilization.md create mode 100644 docs/implementation/task-h1-pdf-generation-stabilization.md create mode 100644 docs/implementation/task-i-storage-artifact-lifecycle.md create mode 100644 drizzle/0009_lazy_shard.sql create mode 100644 drizzle/meta/0009_snapshot.json create mode 100644 plans/task-i.md create mode 100644 src/app/api/crm/document-artifacts/[id]/download/route.ts create mode 100644 src/features/foundation/document-artifact/server/service.ts create mode 100644 src/features/foundation/storage/server/checksum.ts create mode 100644 src/features/foundation/storage/server/local-provider.ts create mode 100644 src/features/foundation/storage/server/provider.ts create mode 100644 src/features/foundation/storage/server/s3-provider.ts create mode 100644 src/features/foundation/storage/service.ts create mode 100644 src/features/foundation/storage/types.ts diff --git a/docs/adr/0009-approved-document-storage-lifecycle.md b/docs/adr/0009-approved-document-storage-lifecycle.md index 942fd11..a87e574 100644 --- a/docs/adr/0009-approved-document-storage-lifecycle.md +++ b/docs/adr/0009-approved-document-storage-lifecycle.md @@ -3,22 +3,30 @@ accepted Context: Task H introduced server-side PDF generation for quotation preview, download, and approved-document persistence. -Task H.1 validated the full path with a real quotation fixture and confirmed that approved artifacts currently persist to local disk under `public/generated/...`. +Task H.1 validated the full path with a real quotation fixture and confirmed that approved artifacts originally persisted to local disk under `public/generated/...`. +Task I introduces a storage-provider abstraction and a database-backed document artifact model so approved PDFs are no longer tied to raw public paths as the source of truth. Decision: -- Keep approved quotation PDFs on local filesystem storage for development and MVP use. -- Persist the generated file path on the quotation row via `approved_pdf_url`. -- Persist `approved_snapshot` and `approved_template_version_id` alongside the stored file path so the approved artifact can be traced back to the data and template used at generation time. -- Treat this storage model as acceptable only for local/dev and early MVP deployment, not as the final production storage architecture. + +- Use a storage provider abstraction for approved quotation PDFs. +- Support a local provider for development and an S3 / MinIO-compatible provider for production-oriented deployments. +- Persist approved-document metadata in `crm_document_artifacts`. +- Persist `approved_artifact_id` on the quotation row as the primary approved-artifact reference. +- Keep `approved_pdf_url` as a compatibility field and allow `artifact:` references during the migration period. +- Lock approved PDF artifacts after generation and treat them as immutable-first records. Consequences: -- Preview/download/generate-approved flows can ship now without blocking on object storage integration. -- Approved PDF persistence works with the current dashboard and static file serving model. -- Local public storage is simple, but it does not provide immutability guarantees, signed access control, retention policy, or durable storage semantics expected for long-lived production artifacts. + +- Approved PDF persistence no longer depends on raw `public/generated/...` paths as the system of record. +- Secure download routes can resolve artifacts from database metadata and storage-provider reads. +- Local storage remains acceptable for development, but production-oriented deployments can move to S3/MinIO-compatible object storage without changing the quotation flow contract. +- Legacy approved PDFs stored under `public/generated/...` still require explicit migration and remain a temporary compatibility burden. Future: -- introduce an object-storage abstraction shared by generated documents and manual attachments + +- migrate legacy approved PDFs into `crm_document_artifacts` +- extend the storage abstraction to manual attachments as well as generated artifacts - support signed URLs or another private delivery strategy where required -- define immutable approved artifact rules and whether regeneration is allowed -- add retention/cleanup policy for superseded or regenerated artifacts +- define operator-facing void/replacement workflow for immutable approved artifacts +- add retention/cleanup policy for superseded or voided artifacts - move approved-PDF generation to an async job when post-approval auto-generation is introduced diff --git a/docs/implementation/task-d1-enquiry-assignment-role-stabilization.md b/docs/implementation/task-d1-enquiry-assignment-role-stabilization.md new file mode 100644 index 0000000..bc07ff5 --- /dev/null +++ b/docs/implementation/task-d1-enquiry-assignment-role-stabilization.md @@ -0,0 +1,144 @@ +# Task D.1: Enquiry Assignment and CRM Role Stabilization + +## 1. Files Added + +- `src/app/api/crm/enquiries/[id]/_schemas.ts` +- `src/app/api/crm/enquiries/[id]/assign/route.ts` +- `src/app/api/crm/enquiries/[id]/reassign/route.ts` +- `src/features/crm/enquiries/components/enquiry-assignment-dialog.tsx` +- `drizzle/0008_clean_justin_hammer.sql` +- `drizzle/meta/0008_snapshot.json` + +## 2. Files Modified + +- `src/db/schema.ts` +- `src/lib/auth/rbac.ts` +- `src/app/dashboard/crm/enquiries/page.tsx` +- `src/app/dashboard/crm/enquiries/[id]/page.tsx` +- `src/features/crm/enquiries/api/types.ts` +- `src/features/crm/enquiries/api/service.ts` +- `src/features/crm/enquiries/api/mutations.ts` +- `src/features/crm/enquiries/server/service.ts` +- `src/features/crm/enquiries/components/enquiry-columns.tsx` +- `src/features/crm/enquiries/components/enquiries-table.tsx` +- `src/features/crm/enquiries/components/enquiry-listing.tsx` +- `src/features/crm/enquiries/components/enquiry-detail.tsx` +- `src/features/crm/enquiries/components/enquiry-cell-action.tsx` +- `src/features/users/api/types.ts` +- `src/features/users/schemas/user.ts` +- `src/features/users/components/user-form-sheet.tsx` +- `src/app/api/users/_lib.ts` +- `src/app/api/users/route.ts` +- `src/app/api/organizations/route.ts` +- `src/features/foundation/auth-context/service.ts` + +## 3. Schema Added + +Added assignment fields to `crm_enquiries`: + +- `assigned_to_user_id` +- `assigned_at` +- `assigned_by` +- `assignment_remark` + +Rules implemented: + +- assignee must belong to the same organization +- assigner is the current user +- latest assignment timestamp is persisted +- assignment remark is optional + +## 4. API Routes Added + +- `POST /api/crm/enquiries/[id]/assign` +- `POST /api/crm/enquiries/[id]/reassign` + +Payload: + +```ts +{ + assignedToUserId: string; + remark?: string; +} +``` + +Behavior: + +- requires organization access +- enforces `crm.enquiry.assign` or `crm.enquiry.reassign` +- validates assignee organization membership +- rejects assign on already-assigned enquiry +- rejects reassign on unassigned enquiry + +## 5. Permissions Added + +- `crm.enquiry.assign` +- `crm.enquiry.reassign` + +CRM business-role set was also stabilized around: + +- `sales_manager` +- `sales` +- `sales_support` +- `department_manager` +- `top_manager` + +Legacy IT-CENTER business roles were removed from active runtime paths and defaults. + +## 6. UI Added + +Enquiry detail now supports: + +- `Assign Sales` +- `Reassign Sales` +- assigned sales metadata display + +Enquiry list now shows: + +- `Assigned Sales` column + +Assignment dialog now includes: + +- `Sales User` +- `Remark` + +The sales-user dropdown is populated from organization memberships instead of hardcoded values. + +## 7. Audit Integration + +Assignment writes audit logs under: + +- `entityType = crm_enquiry` + +Actions added: + +- `assign` +- `reassign` + +Audit payload shape: + +- `beforeData.oldAssignedToUserId` +- `afterData.newAssignedToUserId` +- `afterData.remark` + +## 8. Membership / Permission Stabilization + +Workspace membership management now uses CRM-aligned business roles instead of the old template roles. + +Updated areas: + +- user API types and validation +- membership defaults +- organization-management fallbacks +- auth-context business-role fallback + +## 9. Remaining Risks + +- current `sales` access still operates at organization scope; there is not yet a server-enforced “own or assigned only” data policy +- old database rows that still carry removed legacy business-role strings may need a one-time data backfill if they exist in a real environment +- assignable-user filtering currently accepts organization admins plus sales-oriented roles; if future CRM staffing rules become stricter, that policy should move into a dedicated assignment rule layer + +## 10. Verification + +- `npx tsc --noEmit` +- `npx oxlint` on changed Task D.1 files diff --git a/docs/implementation/task-h1-pdf-generation-stabilization.md b/docs/implementation/task-h1-pdf-generation-stabilization.md new file mode 100644 index 0000000..495ab18 --- /dev/null +++ b/docs/implementation/task-h1-pdf-generation-stabilization.md @@ -0,0 +1,122 @@ +# Task H.1: PDF Generation Stabilization + +## 1. Files Added + +- `scripts/seed-task-h1-fixture.js` +- `scripts/verify-task-h1.js` +- `docs/adr/0009-approved-document-storage-lifecycle.md` + +## 2. Files Modified + +- `package.json` +- `docs/implementation/technical-debt.md` + +Task H.1 builds on the Task H PDF pipeline and focuses on validation, fixture support, documentation, and storage-lifecycle clarification. + +## 3. Smoke Test Record Used + +Added a dev-only fixture script for a real quotation scenario: + +- approved fixture code: `QT-TASK-H1-APPROVED` +- draft fixture code: `QT-TASK-H1-DRAFT` +- customer fixture code: `CUS-TASK-H1` + +Fixture script provisions: + +- organization-scoped customer and contact +- approved quotation with item, customer role, scope/exclusion/payment topics, and completed approval history +- draft quotation for negative approved-PDF validation +- test users for permission checks + +## 4. PDF APIs Verified + +Task H.1 verification script covers: + +- `GET /api/crm/quotations/[id]/pdf-preview` +- `GET /api/crm/quotations/[id]/pdf-download` +- `POST /api/crm/quotations/[id]/approved-pdf` +- `GET /api/crm/quotations/[id]/approved-pdf` + +Expected checks included: + +- preview responds as inline PDF +- download responds as attachment PDF +- approved-PDF POST succeeds for approved quotation +- approved-PDF GET returns persisted artifact +- non-approved quotation cannot generate approved PDF + +## 5. Persistence Verified + +Task H.1 verification targets: + +- `approvedPdfUrl` +- `approvedSnapshot` +- `approvedTemplateVersionId` +- quotation attachment metadata row +- audit log row +- generated file under `public/generated/quotations//` + +## 6. Permission Verified + +Fixture and verification support explicit checks for: + +- `super_admin` +- admin workspace member +- regular user with PDF permissions +- regular user without PDF permissions + +Permissions covered: + +- `crm.quotation.pdf.preview` +- `crm.quotation.pdf.download` +- `crm.quotation.pdf.generate_approved` + +## 7. Error Handling / Hardening + +Task H.1 centered hardening around safe operational verification rather than a large refactor. + +The main stabilization additions were: + +- reusable dev fixture creation +- repeatable HTTP verification script +- clearer storage lifecycle documentation +- explicit debt tracking for fonts, local storage, and approved-artifact policy + +## 8. ADR / Technical Debt Updated + +Added ADR: + +- `docs/adr/0009-approved-document-storage-lifecycle.md` + +Updated debt notes in: + +- `docs/implementation/technical-debt.md` + +Tracked concerns include: + +- font compatibility fallback +- local filesystem storage limitation +- approved artifact immutability policy +- post-approval automation gap +- missing CI-backed PDF E2E coverage + +## 9. Remaining Risks + +- approved PDF storage still uses local public filesystem semantics and is not production-grade object storage +- approved artifact lifecycle is still not immutable by policy +- PDF verification is script-based and not yet part of CI +- task fixture scripts currently depend on a prepared local environment and seeded master-option / approval data + +## 10. Task I Readiness + +Task H.1 leaves the PDF flow better prepared for Task I by providing: + +- a repeatable quotation fixture path +- a repeatable verification script +- explicit storage-lifecycle decision documentation +- visible technical-debt boundaries for future production hardening + +## 11. Verification Commands + +- `npm run seed:task-h1-fixture` +- `npm run verify:task-h1` diff --git a/docs/implementation/task-i-storage-artifact-lifecycle.md b/docs/implementation/task-i-storage-artifact-lifecycle.md new file mode 100644 index 0000000..ae96ba5 --- /dev/null +++ b/docs/implementation/task-i-storage-artifact-lifecycle.md @@ -0,0 +1,155 @@ +# Task I: Storage Abstraction and Approved Artifact Lifecycle + +## 1. Files Added + +- `src/features/foundation/storage/types.ts` +- `src/features/foundation/storage/service.ts` +- `src/features/foundation/storage/server/local-provider.ts` +- `src/features/foundation/storage/server/s3-provider.ts` +- `src/features/foundation/storage/server/provider.ts` +- `src/features/foundation/storage/server/checksum.ts` +- `src/features/foundation/document-artifact/server/service.ts` +- `src/app/api/crm/document-artifacts/[id]/download/route.ts` +- `drizzle/0009_lazy_shard.sql` +- `drizzle/meta/0009_snapshot.json` + +## 2. Files Modified + +- `package.json` +- `package-lock.json` +- `src/db/schema.ts` +- `src/lib/auth/rbac.ts` +- `src/features/foundation/pdf-generator/server/service.ts` +- `src/features/foundation/approval/server/service.ts` +- `src/features/crm/quotations/api/types.ts` +- `src/features/crm/quotations/server/service.ts` +- `src/features/crm/quotations/components/quotation-detail.tsx` +- `src/app/api/crm/quotations/[id]/approved-pdf/route.ts` +- `scripts/seed-task-h1-fixture.js` +- `docs/implementation/technical-debt.md` +- `docs/adr/0009-approved-document-storage-lifecycle.md` + +## 3. Storage Provider Added + +Added a storage foundation under `src/features/foundation/storage/**`. + +Providers: + +- local provider for development +- S3 / MinIO-compatible provider for production-oriented storage + +Configuration supported: + +- `STORAGE_PROVIDER` +- `LOCAL_STORAGE_ROOT` +- `S3_ENDPOINT` +- `S3_REGION` +- `S3_BUCKET` +- `S3_ACCESS_KEY_ID` +- `S3_SECRET_ACCESS_KEY` +- `S3_FORCE_PATH_STYLE` + +## 4. Artifact Schema Added + +Added `crm_document_artifacts` with: + +- organization/entity identity +- document and artifact types +- template version reference +- storage provider and storage key +- file metadata +- checksum +- lifecycle status +- generated / locked / voided metadata +- JSON metadata payload + +Added `approved_artifact_id` to `crm_quotations`. + +## 5. Approved PDF Refactor + +Approved quotation PDFs now: + +- write through `StorageProvider.putObject()` +- persist checksum via SHA-256 +- create a `crm_document_artifacts` row +- lock the artifact after generation +- update quotation `approvedArtifactId` +- keep `approvedPdfUrl` as compatibility reference in `artifact:` form + +Rules enforced: + +- only approved quotations can generate approved PDF +- locked approved artifacts cannot be overwritten +- existing active approved artifact blocks silent regeneration + +## 6. Secure Download Added + +Added secure artifact route: + +- `GET /api/crm/document-artifacts/[id]/download` + +Updated quotation approved-PDF flow so secure reads resolve artifact metadata from the database and fetch bytes through the storage provider instead of treating public file paths as source of truth. + +## 7. UI Updated + +Quotation detail now shows approved artifact metadata when available: + +- file name +- generated by +- generated at +- checksum short form +- locked status badge + +It also shows a legacy warning when a quotation still references old `/generated/...` storage without an artifact record. + +## 8. Permissions Added + +- `crm.document_artifact.read` +- `crm.document_artifact.download` +- `crm.document_artifact.void` + +Defaults were added alongside the existing quotation PDF permissions in RBAC role derivation. + +## 9. Audit Integration + +Artifact service now audits: + +- `create` +- `lock` +- `void` +- `download` + +Entity type: + +- `crm_document_artifact` + +## 10. Compatibility Notes + +Compatibility behavior now supports: + +- `approvedArtifactId` when present +- `approvedPdfUrl = artifact:` during migration +- legacy `/generated/...` approved PDF paths with warning fallback + +Task I intentionally does not bulk-migrate legacy files yet. + +## 11. Remaining Risks + +- artifact void/regeneration still has no admin UI workflow +- legacy approved PDFs still need one-time migration into artifact storage +- signed-URL delivery is not enabled yet; downloads are still server-streamed +- storage-provider health and bucket policy checks are still operational concerns outside the app + +## 12. Task J Readiness + +Task I leaves the app ready for: + +- richer artifact lifecycle tooling +- legacy-file migration command +- object-storage rollout beyond local development +- future secure delivery strategies such as signed URLs + +## 13. Verification + +- `npx tsc --noEmit` +- `npm run gen` diff --git a/docs/implementation/technical-debt.md b/docs/implementation/technical-debt.md index a911d72..466c9f4 100644 --- a/docs/implementation/technical-debt.md +++ b/docs/implementation/technical-debt.md @@ -3,136 +3,242 @@ ## After Task D ### Database foreign keys + Customer, contact, and enquiry relationships are still enforced mainly in application logic. Future: + - add FK constraints after the CRM schema settles - review cascade behavior before enabling hard relational enforcement ### Date input UX + Several forms still use plain `YYYY-MM-DD` text/date inputs. Future: + - move to a shared date picker pattern - standardize timezone handling for CRM forms ### Related enquiry pagination + Customer detail can show related enquiries, but that view still has no dedicated pagination strategy. Future: + - add paging once real data volume grows ### Follow-up activity timeline + Activity history still relies heavily on audit payloads instead of a curated domain timeline. Future: + - build a combined activity view/service for CRM interactions +## After Task D.1 + +### Enquiry Own / Assigned Scope + +Current: +sales role ยังอ่าน enquiry ในระดับ organization scope + +Future: +เพิ่ม server-side policy: + +- sales เห็นเฉพาะ enquiry ที่ตัวเองสร้าง +- หรือ enquiry ที่ assigned ให้ตัวเอง +- sales_manager เห็นทั้งทีม + +Priority: +High + +### Legacy Business Role Backfill + +Current: +ระบบ runtime ใช้ CRM businessRole แล้ว แต่ DB เก่าอาจยังมี role จาก IT-CENTER + +Future: +ทำ one-time migration/backfill script สำหรับ memberships.businessRole + +Priority: +Medium + ## After Task E ### Mixed tax rollup + Quotation items support per-line tax input, but summary calculation still assumes a header-centric tax model. Future: + - support mixed-tax aggregation from actual item rows - align document totals and reporting with per-line tax logic ### Attachment storage abstraction + Quotation attachments started as metadata-only and approved PDFs now write to local disk, but there is still no real storage abstraction. Future: + - introduce a provider abstraction - support upload/download lifecycle consistently across manual attachments and generated artifacts - define migration strategy for existing local/public paths ### Revision snapshot coverage + Revision copy currently focuses on quotation header, items, customers, and topics. Future: + - decide whether follow-ups and attachments belong in revision snapshots - define immutable vs mutable child-data behavior across revisions ### CRM foreign keys + Core CRM tables still depend on organization-scoped validation in service code. Future: + - add FK constraints after schema churn slows down - review delete and soft-delete interactions first ## After Task F ### Permission sync for existing memberships + New permissions are defined in code, but old membership rows may still hold stale permission arrays. Future: + - add a permission sync/backfill command - provide admin tooling for role and permission maintenance ### Approval workflow configuration UI + Approval workflows are seeded and usable, but still not configurable from the dashboard. Future: + - build workflow setup screens - add step editing and role mapping management ### Approval notifications + Approval flow has no queue-backed notification channel yet. Future: + - add notification jobs - support reminders and escalation policy ## After Task G ### Document mapping editor + Template mappings are seeded and readable, but not manageable from UI. Future: + - add mapping CRUD for admins - support table column editing - add draft/publish template workflow ### Product-specific template resolution + Quotation document template resolution still defaults to a coarse product selection strategy. Future: + - define clearer rules for crane, dock door, solar, and service-specific templates ## After Task H / H.1 ### Font compatibility fallback + PDF generation now uses vendored Cordia TTF files from `public/fonts`, which fixed the TTC runtime issue, but generator-side fallback normalization still remains as a safety net. Future: + - keep validating Thai text metrics against designer output - remove fallback normalization only after render parity is proven stable ### Local filesystem storage + Approved PDFs currently persist under `public/generated/quotations//`. Future: + - replace local public storage for production with object storage - add signed/private delivery where required - define backup and cleanup expectations ### Approved artifact immutability + Approved PDF persistence exists, but the lifecycle is not immutable by policy yet. Future: + - define whether regeneration is allowed after approval - version approved artifacts explicitly if regeneration must remain possible - document which snapshot fields are contractual records ### Post-approval automation + Approved PDF generation is still manual by design. Future: + - add a non-blocking auto-generation hook after final approval - move heavy generation/retry behavior to a background job when needed ### PDF pipeline test coverage + Task H.1 added dev fixture and HTTP verification scripts, but there is still no CI-backed E2E coverage for the PDF pipeline. Future: + - promote fixture verification into automated test coverage - add regression checks for template mappings, storage persistence, and permission enforcement + +## After Task I + +### Storage provider production rollout + +Task I introduced a storage provider abstraction with local and S3/MinIO-compatible implementations, but the production rollout still depends on environment configuration and infrastructure ownership outside the app. + +Future: + +- validate real bucket policies, credentials rotation, and environment separation +- add operational runbooks for provider misconfiguration and storage outage handling +- add smoke checks for startup-time storage provider health + +### Legacy approved PDF migration + +Task I keeps compatibility for legacy `public/generated/...` approved PDFs, but those legacy files are still outside the new artifact source-of-truth model. + +Future: + +- add a one-time migration script from legacy local paths into `crm_document_artifacts` +- backfill `approvedArtifactId` where possible +- remove legacy compatibility once migration is complete and verified + +### Artifact lifecycle policy depth + +Approved artifacts are now immutable-first and locked after generation, but void/regeneration policy is still service-level rather than a full operator workflow. + +Future: + +- add explicit admin tooling for artifact void and replacement flows +- define whether artifact voiding also clears or supersedes quotation-facing references automatically +- document retention expectations for voided objects in object storage + +### Secure artifact delivery model + +Approved-PDF viewing now goes through secure server routes and storage-backed reads, but signed-url/offload behavior is not yet used. + +Future: + +- decide when direct signed URLs are acceptable versus mandatory server streaming +- add response caching strategy for large artifact downloads +- evaluate optional download-audit sampling if volume grows diff --git a/drizzle/0009_lazy_shard.sql b/drizzle/0009_lazy_shard.sql new file mode 100644 index 0000000..0a38938 --- /dev/null +++ b/drizzle/0009_lazy_shard.sql @@ -0,0 +1,30 @@ +CREATE TABLE "crm_document_artifacts" ( + "id" text PRIMARY KEY NOT NULL, + "organization_id" text NOT NULL, + "entity_type" text NOT NULL, + "entity_id" text NOT NULL, + "document_type" text NOT NULL, + "artifact_type" text NOT NULL, + "template_version_id" text, + "storage_provider" text NOT NULL, + "storage_key" text NOT NULL, + "file_name" text NOT NULL, + "content_type" text NOT NULL, + "file_size" integer, + "checksum" text, + "status" text DEFAULT 'active' NOT NULL, + "generated_by" text NOT NULL, + "generated_at" timestamp with time zone DEFAULT now() NOT NULL, + "locked_at" timestamp with time zone, + "locked_by" text, + "voided_at" timestamp with time zone, + "voided_by" text, + "void_reason" text, + "metadata" jsonb, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + "updated_at" timestamp with time zone DEFAULT now() NOT NULL, + "deleted_at" timestamp with time zone +); +--> statement-breakpoint +ALTER TABLE "memberships" ALTER COLUMN "business_role" SET DEFAULT 'sales_support';--> statement-breakpoint +ALTER TABLE "crm_quotations" ADD COLUMN "approved_artifact_id" text; \ No newline at end of file diff --git a/drizzle/meta/0009_snapshot.json b/drizzle/meta/0009_snapshot.json new file mode 100644 index 0000000..a3b1a4c --- /dev/null +++ b/drizzle/meta/0009_snapshot.json @@ -0,0 +1,3192 @@ +{ + "id": "ef6e9c14-9f8a-42aa-bbd3-4638dccea8a4", + "prevId": "0237eb23-9304-48dd-a770-8bf5013172da", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.crm_approval_actions": { + "name": "crm_approval_actions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "approval_request_id": { + "name": "approval_request_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "step_number": { + "name": "step_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "acted_by": { + "name": "acted_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "acted_at": { + "name": "acted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_approval_requests": { + "name": "crm_approval_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "current_step": { + "name": "current_step", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requested_by": { + "name": "requested_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_approval_steps": { + "name": "crm_approval_steps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "step_number": { + "name": "step_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role_code": { + "name": "role_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role_name": { + "name": "role_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_required": { + "name": "is_required", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "crm_approval_steps_workflow_step_idx": { + "name": "crm_approval_steps_workflow_step_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "step_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_approval_workflows": { + "name": "crm_approval_workflows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "crm_approval_workflows_org_code_idx": { + "name": "crm_approval_workflows_org_code_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_customer_contacts": { + "name": "crm_customer_contacts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "customer_id": { + "name": "customer_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "department": { + "name": "department", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mobile": { + "name": "mobile", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_primary": { + "name": "is_primary", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_customers": { + "name": "crm_customers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "branch_id": { + "name": "branch_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "abbr": { + "name": "abbr", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "customer_type": { + "name": "customer_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "customer_status": { + "name": "customer_status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "province": { + "name": "province", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "district": { + "name": "district", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sub_district": { + "name": "sub_district", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "postal_code": { + "name": "postal_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fax": { + "name": "fax", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "website": { + "name": "website", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lead_channel": { + "name": "lead_channel", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "customer_group": { + "name": "customer_group", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "crm_customers_org_code_idx": { + "name": "crm_customers_org_code_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_document_artifacts": { + "name": "crm_document_artifacts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "document_type": { + "name": "document_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "artifact_type": { + "name": "artifact_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "template_version_id": { + "name": "template_version_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "storage_provider": { + "name": "storage_provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "storage_key": { + "name": "storage_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "checksum": { + "name": "checksum", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "generated_by": { + "name": "generated_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "generated_at": { + "name": "generated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "locked_at": { + "name": "locked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "locked_by": { + "name": "locked_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "voided_at": { + "name": "voided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "voided_by": { + "name": "voided_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "void_reason": { + "name": "void_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_document_template_mappings": { + "name": "crm_document_template_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "template_version_id": { + "name": "template_version_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "placeholder_key": { + "name": "placeholder_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_path": { + "name": "source_path", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data_type": { + "name": "data_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sheet_name": { + "name": "sheet_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "default_value": { + "name": "default_value", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "format_mask": { + "name": "format_mask", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "crm_document_template_mappings_version_placeholder_idx": { + "name": "crm_document_template_mappings_version_placeholder_idx", + "columns": [ + { + "expression": "template_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "placeholder_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_document_template_table_columns": { + "name": "crm_document_template_table_columns", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mapping_id": { + "name": "mapping_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "column_name": { + "name": "column_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_field": { + "name": "source_field", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "column_letter": { + "name": "column_letter", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "format_mask": { + "name": "format_mask", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "crm_document_template_table_columns_mapping_name_idx": { + "name": "crm_document_template_table_columns_mapping_name_idx", + "columns": [ + { + "expression": "mapping_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "column_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_document_template_versions": { + "name": "crm_document_template_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "template_id": { + "name": "template_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "schema_json": { + "name": "schema_json", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "preview_image_url": { + "name": "preview_image_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "crm_document_template_versions_template_version_idx": { + "name": "crm_document_template_versions_template_version_idx", + "columns": [ + { + "expression": "template_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_document_templates": { + "name": "crm_document_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "document_type": { + "name": "document_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "product_type": { + "name": "product_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "template_name": { + "name": "template_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_default": { + "name": "is_default", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "crm_document_templates_org_doc_product_file_name_idx": { + "name": "crm_document_templates_org_doc_product_file_name_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "document_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "product_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "file_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "template_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_enquiries": { + "name": "crm_enquiries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "branch_id": { + "name": "branch_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "customer_id": { + "name": "customer_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact_id": { + "name": "contact_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requirement": { + "name": "requirement", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_name": { + "name": "project_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_location": { + "name": "project_location", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "product_type": { + "name": "product_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "lead_channel": { + "name": "lead_channel", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estimated_value": { + "name": "estimated_value", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "chance_percent": { + "name": "chance_percent", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "expected_close_date": { + "name": "expected_close_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "competitor": { + "name": "competitor", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_hot_project": { + "name": "is_hot_project", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "assigned_to_user_id": { + "name": "assigned_to_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assigned_at": { + "name": "assigned_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "assigned_by": { + "name": "assigned_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assignment_remark": { + "name": "assignment_remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "crm_enquiries_org_code_idx": { + "name": "crm_enquiries_org_code_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_enquiry_followups": { + "name": "crm_enquiry_followups", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enquiry_id": { + "name": "enquiry_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "followup_date": { + "name": "followup_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "followup_type": { + "name": "followup_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact_id": { + "name": "contact_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_followup_date": { + "name": "next_followup_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "next_action": { + "name": "next_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_quotation_attachments": { + "name": "crm_quotation_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quotation_id": { + "name": "quotation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_quotation_customers": { + "name": "crm_quotation_customers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quotation_id": { + "name": "quotation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "customer_id": { + "name": "customer_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_primary": { + "name": "is_primary", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_quotation_followups": { + "name": "crm_quotation_followups", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quotation_id": { + "name": "quotation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "followup_date": { + "name": "followup_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "followup_type": { + "name": "followup_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact_id": { + "name": "contact_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_followup_date": { + "name": "next_followup_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "next_action": { + "name": "next_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_quotation_items": { + "name": "crm_quotation_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quotation_id": { + "name": "quotation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "item_number": { + "name": "item_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "product_type": { + "name": "product_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quantity": { + "name": "quantity", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "unit": { + "name": "unit", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "unit_price": { + "name": "unit_price", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "discount": { + "name": "discount", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "discount_type": { + "name": "discount_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tax_rate": { + "name": "tax_rate", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_price": { + "name": "total_price", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_quotation_topic_items": { + "name": "crm_quotation_topic_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "topic_id": { + "name": "topic_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_quotation_topics": { + "name": "crm_quotation_topics", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quotation_id": { + "name": "quotation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "topic_type": { + "name": "topic_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.crm_quotations": { + "name": "crm_quotations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "branch_id": { + "name": "branch_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enquiry_id": { + "name": "enquiry_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "customer_id": { + "name": "customer_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact_id": { + "name": "contact_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quotation_date": { + "name": "quotation_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "valid_until": { + "name": "valid_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "quotation_type": { + "name": "quotation_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "project_name": { + "name": "project_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_location": { + "name": "project_location", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attention": { + "name": "attention", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference": { + "name": "reference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "parent_quotation_id": { + "name": "parent_quotation_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revision_remark": { + "name": "revision_remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "exchange_rate": { + "name": "exchange_rate", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "subtotal": { + "name": "subtotal", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "discount": { + "name": "discount", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "discount_type": { + "name": "discount_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tax_rate": { + "name": "tax_rate", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "tax_amount": { + "name": "tax_amount", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_amount": { + "name": "total_amount", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "chance_percent": { + "name": "chance_percent", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "is_hot_project": { + "name": "is_hot_project", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "competitor": { + "name": "competitor", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "salesman_id": { + "name": "salesman_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_sent": { + "name": "is_sent", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "sent_via": { + "name": "sent_via", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "approved_artifact_id": { + "name": "approved_artifact_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approved_pdf_url": { + "name": "approved_pdf_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approved_snapshot": { + "name": "approved_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "approved_template_version_id": { + "name": "approved_template_version_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "rejected_at": { + "name": "rejected_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "crm_quotations_org_code_idx": { + "name": "crm_quotations_org_code_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.document_sequences": { + "name": "document_sequences", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "branch_id": { + "name": "branch_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "document_type": { + "name": "document_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "prefix": { + "name": "prefix", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "period": { + "name": "period", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "current_number": { + "name": "current_number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "padding_length": { + "name": "padding_length", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 3 + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "document_sequences_org_doc_period_branch_idx": { + "name": "document_sequences_org_doc_period_branch_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "document_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "period", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "branch_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memberships": { + "name": "memberships", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'user'" + }, + "business_role": { + "name": "business_role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'sales_support'" + }, + "permissions": { + "name": "permissions", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ms_options": { + "name": "ms_options", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "ms_options_org_category_code_idx": { + "name": "ms_options_org_category_code_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "category", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organizations": { + "name": "organizations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "image_url": { + "name": "image_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "plan": { + "name": "plan", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'free'" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "organizations_slug_idx": { + "name": "organizations_slug_idx", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.products": { + "name": "products", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "products_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "photo_url": { + "name": "photo_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "price": { + "name": "price", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tr_audit_logs": { + "name": "tr_audit_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "branch_id": { + "name": "branch_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "before_data": { + "name": "before_data", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "after_data": { + "name": "after_data", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "system_role": { + "name": "system_role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'user'" + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "active_organization_id": { + "name": "active_organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "users_email_idx": { + "name": "users_email_idx", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index de1b017..a5ab9d0 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -64,6 +64,13 @@ "when": 1781595962545, "tag": "0008_clean_justin_hammer", "breakpoints": true + }, + { + "idx": 9, + "version": "7", + "when": 1781603421415, + "tag": "0009_lazy_shard", + "breakpoints": true } ] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d917dc2..63b03fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,8 @@ "name": "alla-allaos-fullstack", "version": "1.0.0", "dependencies": { + "@aws-sdk/client-s3": "^3.1069.0", + "@aws-sdk/s3-request-presigner": "^3.1069.0", "@dnd-kit/core": "^6.3.1", "@dnd-kit/modifiers": "^9.0.0", "@dnd-kit/sortable": "^10.0.0", @@ -143,6 +145,453 @@ } } }, + "node_modules/@aws-crypto/crc32": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/crc32/-/crc32-5.2.0.tgz", + "integrity": "sha512-nLbCWqQNgUiwwtFsen1AdzAtvuLRsQS8rYgMuxCrdKf9kOssamGLuPwyTY9wyYblNr9+1XM8v6zoDTPPSIeANg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/util": "^5.2.0", + "@aws-sdk/types": "^3.222.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-crypto/crc32c": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/crc32c/-/crc32c-5.2.0.tgz", + "integrity": "sha512-+iWb8qaHLYKrNvGRbiYRHSdKRWhto5XlZUEBwDjYNf+ly5SVYG6zEoYIdxvf5R3zyeP16w4PLBn3rH1xc74Rag==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/util": "^5.2.0", + "@aws-sdk/types": "^3.222.0", + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-crypto/sha1-browser": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/sha1-browser/-/sha1-browser-5.2.0.tgz", + "integrity": "sha512-OH6lveCFfcDjX4dbAvCFSYUjJZjDr/3XJ3xHtjn3Oj5b9RjojQo8npoLeA/bNwkOkrSQ0wgrHzXk4tDRxGKJeg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/supports-web-crypto": "^5.2.0", + "@aws-crypto/util": "^5.2.0", + "@aws-sdk/types": "^3.222.0", + "@aws-sdk/util-locate-window": "^3.0.0", + "@smithy/util-utf8": "^2.0.0", + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-crypto/sha256-browser": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-browser/-/sha256-browser-5.2.0.tgz", + "integrity": "sha512-AXfN/lGotSQwu6HNcEsIASo7kWXZ5HYWvfOmSNKDsEqC4OashTp8alTmaz+F7TC2L083SFv5RdB+qU3Vs1kZqw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-js": "^5.2.0", + "@aws-crypto/supports-web-crypto": "^5.2.0", + "@aws-crypto/util": "^5.2.0", + "@aws-sdk/types": "^3.222.0", + "@aws-sdk/util-locate-window": "^3.0.0", + "@smithy/util-utf8": "^2.0.0", + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-crypto/sha256-js": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-js/-/sha256-js-5.2.0.tgz", + "integrity": "sha512-FFQQyu7edu4ufvIZ+OadFpHHOt+eSTBaYaki44c+akjg7qZg9oOQeLlk77F6tSYqjDAFClrHJk9tMf0HdVyOvA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/util": "^5.2.0", + "@aws-sdk/types": "^3.222.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-crypto/supports-web-crypto": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/supports-web-crypto/-/supports-web-crypto-5.2.0.tgz", + "integrity": "sha512-iAvUotm021kM33eCdNfwIN//F77/IADDSs58i+MDaOqFrVjZo9bAal0NK7HurRuWLLpF1iLX7gbWrjHjeo+YFg==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-crypto/util": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/util/-/util-5.2.0.tgz", + "integrity": "sha512-4RkU9EsI6ZpBve5fseQlGNUWKMa1RLPQ1dnjnQoe07ldfIzcsGb5hC5W0Dm7u423KWzawlrpbjXBrXCEv9zazQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "^3.222.0", + "@smithy/util-utf8": "^2.0.0", + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-sdk/checksums": { + "version": "3.1000.6", + "resolved": "https://registry.npmjs.org/@aws-sdk/checksums/-/checksums-3.1000.6.tgz", + "integrity": "sha512-RMCrCteiUwYTEv2G9zfP/BEuKHv57665vVieJyp9cf8VgilWxP/KrWVtMdfdDlIH8nFhvu3rIMc29z3ebGEZ1w==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/crc32": "5.2.0", + "@aws-crypto/crc32c": "5.2.0", + "@aws-crypto/util": "5.2.0", + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/client-s3": { + "version": "3.1069.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-s3/-/client-s3-3.1069.0.tgz", + "integrity": "sha512-zkwCW4D88foQ0YHyjVyFhDOIWG+IWiTGXYg8+kUgH6M19son3OsZLvioZGyZdNtlRgLNYfQGBjfArSJOYYt2QQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha1-browser": "5.2.0", + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/credential-provider-node": "^3.972.56", + "@aws-sdk/middleware-flexible-checksums": "^3.974.31", + "@aws-sdk/middleware-sdk-s3": "^3.972.52", + "@aws-sdk/signature-v4-multi-region": "^3.996.35", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/fetch-http-handler": "^5.4.6", + "@smithy/node-http-handler": "^4.7.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/core": { + "version": "3.974.21", + "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.974.21.tgz", + "integrity": "sha512-P5JAHvn4dTi96UsAGS67LVOqqpUNNRhnfFXqzCYtdBIGZtqBue4CXvRr9YenOO7PALj/Pn8uuyw53FBCiCYw8w==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "^3.973.13", + "@aws-sdk/xml-builder": "^3.972.30", + "@aws/lambda-invoke-store": "^0.2.2", + "@smithy/core": "^3.24.6", + "@smithy/signature-v4": "^5.4.6", + "@smithy/types": "^4.14.3", + "bowser": "^2.11.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-env": { + "version": "3.972.47", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.972.47.tgz", + "integrity": "sha512-3YoPwJczcc+MtX2xxXaYaOOWO6xKUJr1ZIIDIFuninr51BYONVVcF/CP8K2xfVRC/PztJjqKWxNGFH7BWQAw1Q==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-http": { + "version": "3.972.49", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-http/-/credential-provider-http-3.972.49.tgz", + "integrity": "sha512-2UtGUPy+x3lqyceHrtC1uEuVxBZbDalPF6KAFqBwYgm4edWdBrZKNnCqzDs7KynWUvEC6mrR+ojRk+ZgQz9C2w==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/fetch-http-handler": "^5.4.6", + "@smithy/node-http-handler": "^4.7.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-ini": { + "version": "3.972.54", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.972.54.tgz", + "integrity": "sha512-Hx4gO4YRjFwitf3MVl3cDwYe1aryJthC4txVl9b+JAURovA50M2ywf9r8j1E/Q6SCTPT4qQpjOAbKYIC9CG+Vw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/credential-provider-env": "^3.972.47", + "@aws-sdk/credential-provider-http": "^3.972.49", + "@aws-sdk/credential-provider-login": "^3.972.53", + "@aws-sdk/credential-provider-process": "^3.972.47", + "@aws-sdk/credential-provider-sso": "^3.972.53", + "@aws-sdk/credential-provider-web-identity": "^3.972.53", + "@aws-sdk/nested-clients": "^3.997.21", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/credential-provider-imds": "^4.3.7", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-login": { + "version": "3.972.53", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-login/-/credential-provider-login-3.972.53.tgz", + "integrity": "sha512-+71sluhkgPqdhbbD3UDwUpj24GCkng9HQx6z7qoBFb8dwkF4ktpOcVKDeHpgg8PvBgLYwAnUYLTEGRC/PniCiQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/nested-clients": "^3.997.21", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-node": { + "version": "3.972.56", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.972.56.tgz", + "integrity": "sha512-iI+4o0dvQQ4NHel4FMDiFy5q2gaU/ryLK3niOsoPccAt9WLFRkV4XTYPWRr9XvmBUqEzXG73S4p/8gm0Lu/W3A==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/credential-provider-env": "^3.972.47", + "@aws-sdk/credential-provider-http": "^3.972.49", + "@aws-sdk/credential-provider-ini": "^3.972.54", + "@aws-sdk/credential-provider-process": "^3.972.47", + "@aws-sdk/credential-provider-sso": "^3.972.53", + "@aws-sdk/credential-provider-web-identity": "^3.972.53", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/credential-provider-imds": "^4.3.7", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-process": { + "version": "3.972.47", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.972.47.tgz", + "integrity": "sha512-tAizPm9IFo/PHn06c+LQJlzfY2AGOlyF0CUljFejrU6LcZBjnk8pmbZK3/xoIDdnIzjEdbClfvY3mXfr818ZEg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-sso": { + "version": "3.972.53", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.972.53.tgz", + "integrity": "sha512-pUXE3fu4tfEDV8BksIgf4dXvuIH10FhwHMl/wu8rBD5T1sMpryQWFVitH3kdPS90wlgrGYJQ/meQTSPacyZfeg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/nested-clients": "^3.997.21", + "@aws-sdk/token-providers": "3.1069.0", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-web-identity": { + "version": "3.972.53", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.972.53.tgz", + "integrity": "sha512-JmMGlhVvSj8uSG9CpeDkJAXT35H89tc6v84iMgEIE75q4yp1MKVVKvopv6Gg28HJIR7hMNkojRF8H2m5W44wyg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/nested-clients": "^3.997.21", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/middleware-flexible-checksums": { + "version": "3.974.31", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-flexible-checksums/-/middleware-flexible-checksums-3.974.31.tgz", + "integrity": "sha512-Yzj6NRYVZdBaCp7o1BwHGyeDBfixdeToLIAMprshIITEdl9wKVSiidVOfeaiH8FyeC1hBmBfDZFvs/aH1Y3xpw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/checksums": "^3.1000.6", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/middleware-sdk-s3": { + "version": "3.972.52", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-sdk-s3/-/middleware-sdk-s3-3.972.52.tgz", + "integrity": "sha512-rerjP08onRqkBh0AcCqip6GkKvESapmLoTgi1xysZ4C6a1xMrIMtTBcEbUb6EY71oeajnigeUD4KwZjtIO+aWQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/signature-v4-multi-region": "^3.996.35", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/nested-clients": { + "version": "3.997.21", + "resolved": "https://registry.npmjs.org/@aws-sdk/nested-clients/-/nested-clients-3.997.21.tgz", + "integrity": "sha512-eC7Vl7Qom/BGhZjG9GEqPwdQ/fk45hg1t5LP4EUxG5d1fdshLbaxCiwh/tszUzDX/4mW40mu2QsbeJJRPBbqUw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/signature-v4-multi-region": "^3.996.35", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/fetch-http-handler": "^5.4.6", + "@smithy/node-http-handler": "^4.7.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/s3-request-presigner": { + "version": "3.1069.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/s3-request-presigner/-/s3-request-presigner-3.1069.0.tgz", + "integrity": "sha512-/s8zMe/C4bLLilx8Jlh3neN2sbaGmQTdi5dxu/GG1D9wlg+3MDemqyzYy9Gi1W2m/iD2+qf6kEpNk97qEEBcZA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/signature-v4-multi-region": "^3.996.35", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/signature-v4-multi-region": { + "version": "3.996.35", + "resolved": "https://registry.npmjs.org/@aws-sdk/signature-v4-multi-region/-/signature-v4-multi-region-3.996.35.tgz", + "integrity": "sha512-6L/VWs+Wch2stHemCGTmUNqKLMzURxQDK5boNG3Jn3kAOp71meDUuS5sbObpEvFxHDq0uWeSLFDNSYsjNt+Dlg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "^3.973.13", + "@smithy/signature-v4": "^5.4.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/token-providers": { + "version": "3.1069.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.1069.0.tgz", + "integrity": "sha512-ks4X+kngC3PA5howV7Qu1TgG4bfC4jPykKdvw3nmBSXR9yZxRJouBholFSNQ5kY3L+Fgwyw+LCjzQmNi+KR91g==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "^3.974.21", + "@aws-sdk/nested-clients": "^3.997.21", + "@aws-sdk/types": "^3.973.13", + "@smithy/core": "^3.24.6", + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/types": { + "version": "3.973.13", + "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.973.13.tgz", + "integrity": "sha512-pEHZqRkAlHfnfAU9tK+WpKv/gBNjGJrHMgA3A0iYRGyswBS2t0pfez+lWlwktb3Bqa0ovh7w/QJTFwp3fDxLNg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.14.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/util-locate-window": { + "version": "3.965.8", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-locate-window/-/util-locate-window-3.965.8.tgz", + "integrity": "sha512-uUbMs1cBZPafD0ohUj6EwNf0fPZ534NvBxHox4hjX+0Rxq5paSYUem7+hi833pYrzrcnBATKIYpR02MDXT5M9g==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws-sdk/xml-builder": { + "version": "3.972.30", + "resolved": "https://registry.npmjs.org/@aws-sdk/xml-builder/-/xml-builder-3.972.30.tgz", + "integrity": "sha512-StElZPEoBquWwNqw1AcfpzEyZqJvFxouG+mpDNYlcH6ZOrqd2CuIryv+8LV8gNHZUOyKyJF3Dq9vxaXEmDR9TQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.14.3", + "fast-xml-parser": "5.7.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/@aws/lambda-invoke-store": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.2.4.tgz", + "integrity": "sha512-iY8yvjE0y651BixKNPgmv1WrQc+GZ142sb0z4gYnChDDY2YqI4P/jsSopBWrKfAt7LOJAkOXt7rC/hms+WclQQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/@babel/code-frame": { "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", @@ -2044,6 +2493,18 @@ "node": ">= 10" } }, + "node_modules/@nodable/entities": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@nodable/entities/-/entities-2.2.0.tgz", + "integrity": "sha512-9uGyhaQavEUMC8AIddIjau4NsnsXhou+j5sBAGojCM1oxmQpVKTWR/9JxABD6UAv12vpIms55fPZKFQEhG6uBg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/nodable" + } + ], + "license": "MIT" + }, "node_modules/@opentelemetry/api": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.1.tgz", @@ -5581,6 +6042,126 @@ "webpack": ">=5.0.0" } }, + "node_modules/@smithy/core": { + "version": "3.25.0", + "resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.25.0.tgz", + "integrity": "sha512-TTD6el7tvKyafkXBf7XO3jLOE+qVxOTrLjp/fEGiV3BMfUHK/LfdYlQO9YgZvzxC7kqA3H/IhJXNqQgnbgjb7A==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/crc32": "5.2.0", + "@smithy/types": "^4.15.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/credential-provider-imds": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@smithy/credential-provider-imds/-/credential-provider-imds-4.4.0.tgz", + "integrity": "sha512-pPQmNdEvMJttv9z2kdYxoui83p/nr32zjMf0aMfmzmGmFEgKXUfy0vXiNg0fx4R5XLQzmJBLM9Wg0guEq2/q8A==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.25.0", + "@smithy/types": "^4.15.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/fetch-http-handler": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-5.5.0.tgz", + "integrity": "sha512-OG8kBYAgX7lf32+xLzgirvuLffn1KNoszaSiButt45i2cRa5irk8LQXLYQ5Smij1SBTN4KMNcBsRwRrLPfIGyA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.25.0", + "@smithy/types": "^4.15.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/is-array-buffer": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz", + "integrity": "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@smithy/node-http-handler": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-4.8.0.tgz", + "integrity": "sha512-Mq7TNt/VhlEWiYRLQGpzUWeUxh899UGpjKh7Ru0WVIDIjnE+cTRAn0NYlFQ6bWfsQnKnpCbWJj86HzmcG0qEdg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.25.0", + "@smithy/types": "^4.15.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/signature-v4": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/@smithy/signature-v4/-/signature-v4-5.5.0.tgz", + "integrity": "sha512-vW6UdK7e7gV2wU/tXRsPq4pMQMusb8VymdVOyIFNA1FtyRmEClRFkYDtYI8UcO/HM0wK3qqjvvQs3HOlbgMbdg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.25.0", + "@smithy/types": "^4.15.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/types": { + "version": "4.15.0", + "resolved": "https://registry.npmjs.org/@smithy/types/-/types-4.15.0.tgz", + "integrity": "sha512-Z5TAOxygoFvybJV3igo5SloFflSokHx2hu1eFA+DxDTcn+FtKxUSui+rbTRG1pAafMA888Z3MVvCWUuvCrTXjg==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-buffer-from": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz", + "integrity": "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/is-array-buffer": "^2.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@smithy/util-utf8": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.3.0.tgz", + "integrity": "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/util-buffer-from": "^2.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/@standard-schema/spec": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.0.0.tgz", @@ -6268,6 +6849,18 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/anynum": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/anynum/-/anynum-1.0.0.tgz", + "integrity": "sha512-xjR9/zBVnUOP6ztMIIgShjsxui80nQUQH+5xJnvrYLs+90bF25/KJqaAi8mk+B4RDtX1Nspi6fmp4YTEts8SfA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT" + }, "node_modules/aria-hidden": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/aria-hidden/-/aria-hidden-1.2.6.tgz", @@ -6339,6 +6932,12 @@ "bcrypt": "bin/bcrypt" } }, + "node_modules/bowser": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.14.1.tgz", + "integrity": "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg==", + "license": "MIT" + }, "node_modules/brace-expansion": { "version": "5.0.6", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz", @@ -7159,6 +7758,43 @@ "integrity": "sha512-caj/ZmjHljPrZtbzJ3kfH5ia/k4mTJe/qSiXAGzxZWRZgsgDV0cvNaQULqUX8t0/JVlzzEdYOwCN5DmzTxoD4w==", "license": "MIT" }, + "node_modules/fast-xml-builder": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.2.0.tgz", + "integrity": "sha512-00aAWieqff+ZJhsXA4g1g7M8k+7AYoMUUHF+/zFb5U6Uv/P0Vl4QZo84/IcufzYalLuEj9928bXN9PbbFzMF0Q==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "dependencies": { + "path-expression-matcher": "^1.5.0", + "xml-naming": "^0.1.0" + } + }, + "node_modules/fast-xml-parser": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.7.3.tgz", + "integrity": "sha512-C0AaNuC+mscy6vrAQKAc/rMq+zAPHodfHGZu4sGVehvAQt/JLG1O5zEcYcXSY5zSqr4YVgxsB+pHXTq0i7eDlg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "dependencies": { + "@nodable/entities": "^2.1.0", + "fast-xml-builder": "^1.1.7", + "path-expression-matcher": "^1.5.0", + "strnum": "^2.2.3" + }, + "bin": { + "fxparser": "src/cli/cli.js" + } + }, "node_modules/fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", @@ -9007,6 +9643,21 @@ "node": ">=8" } }, + "node_modules/path-expression-matcher": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.5.0.tgz", + "integrity": "sha512-cbrerZV+6rvdQrrD+iGMcZFEiiSrbv9Tfdkvnusy6y0x0GKBXREFg/Y65GhIfm0tnLntThhzCnfKwp1WRjeCyQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -10014,6 +10665,21 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/strnum": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.4.0.tgz", + "integrity": "sha512-sHrVyWWdq28RbhjuJdZsA1SnGRJV6NiXbk6AXBxDOsgAcA+lmpUZCYjOdLBxkXMwis6RRe7dlZt4VlIWFVzkmg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "dependencies": { + "anynum": "^1.0.0" + } + }, "node_modules/styled-jsx": { "version": "5.1.6", "resolved": "https://registry.npmjs.org/styled-jsx/-/styled-jsx-5.1.6.tgz", @@ -10869,6 +11535,21 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/xml-naming": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/xml-naming/-/xml-naming-0.1.0.tgz", + "integrity": "sha512-k8KO9hrMyNk6tUWqUfkTEZbezRRpONVOzUTnc97VnCvyj6Tf9lyUR9EDAIeiVLv56jsMcoXEwjW8Kv5yPY52lw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", diff --git a/package.json b/package.json index 62e7089..ff82064 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,8 @@ "setup:db": "npm run migrate && npm run seed:super-admin && npm run seed:foundation" }, "dependencies": { + "@aws-sdk/client-s3": "^3.1069.0", + "@aws-sdk/s3-request-presigner": "^3.1069.0", "@dnd-kit/core": "^6.3.1", "@dnd-kit/modifiers": "^9.0.0", "@dnd-kit/sortable": "^10.0.0", diff --git a/plans/task-i.md b/plans/task-i.md new file mode 100644 index 0000000..4182714 --- /dev/null +++ b/plans/task-i.md @@ -0,0 +1,475 @@ +# Task I: Storage Abstraction + Approved Artifact Lifecycle + +## ALLA OS CRM vNext + +คุณคือ Senior Full-stack Engineer + +ให้ implement storage abstraction และ approved artifact lifecycle สำหรับ Quotation PDF โดยต่อยอดจาก Task H และ H.1 + +--- + +## Must Read + +```txt +docs/implementation/technical-debt.md +docs/adr/0008-attachment-storage-strategy.md +docs/adr/0009-approved-document-storage-lifecycle.md + +src/features/foundation/pdf-generator/** +src/features/foundation/document-template/** +src/features/crm/quotations/document/** +src/features/crm/quotations/** +src/app/api/crm/quotations/[id]/approved-pdf/route.ts +src/db/schema.ts +``` + +--- + +# Goal + +ทำให้ PDF storage พร้อม production มากขึ้น + +จากเดิม: + +```txt +public/generated/quotations// +``` + +ไปเป็น: + +```txt +Storage Provider Interface +Local Provider for dev +S3 / MinIO compatible provider for production +Secure download route +Immutable approved artifact lifecycle +``` + +--- + +# Scope I1: Storage Provider Interface + +สร้าง foundation module: + +```txt +src/features/foundation/storage/** +``` + +Files: + +```txt +types.ts +service.ts +server/local-provider.ts +server/s3-provider.ts +server/provider.ts +``` + +Interface: + +```ts +export interface StorageProvider { + putObject(input: PutObjectInput): Promise + getObject(input: GetObjectInput): Promise + deleteObject(input: DeleteObjectInput): Promise + objectExists(input: ObjectExistsInput): Promise + getSignedUrl?(input: GetSignedUrlInput): Promise +} +``` + +Types: + +```ts +PutObjectInput +GetObjectInput +DeleteObjectInput +ObjectExistsInput +GetSignedUrlInput +StoredObject +StoredObjectStream +``` + +Rules: + +* service ต้อง server-only +* client ห้ามเข้าถึง provider โดยตรง +* storage key ต้อง organization-scoped +* ห้ามใช้ raw public path เป็น source of truth + +--- + +# Scope I2: Storage Configuration + +รองรับ env: + +```txt +STORAGE_PROVIDER=local | s3 + +LOCAL_STORAGE_ROOT=storage + +S3_ENDPOINT= +S3_REGION= +S3_BUCKET= +S3_ACCESS_KEY_ID= +S3_SECRET_ACCESS_KEY= +S3_FORCE_PATH_STYLE=true +``` + +Rules: + +* local ใช้ได้ใน dev +* s3 provider ต้อง compatible กับ MinIO/S3 +* ถ้า config ไม่ครบ ให้ throw error ชัดเจน +* อย่า hardcode bucket/path + +--- + +# Scope I3: Artifact Schema + +เพิ่ม table ถ้ายังไม่มี: + +```txt +crm_document_artifacts +``` + +Fields: + +```txt +id +organizationId + +entityType +entityId + +documentType +artifactType + +templateVersionId + +storageProvider +storageKey +fileName +contentType +fileSize +checksum + +status + +generatedBy +generatedAt + +lockedAt +lockedBy + +voidedAt +voidedBy +voidReason + +metadata + +createdAt +updatedAt +deletedAt +``` + +artifactType: + +```txt +preview +approved_pdf +export +``` + +status: + +```txt +active +locked +voided +deleted +``` + +Rules: + +* approved_pdf ต้อง lock หลัง generate +* approved_pdf ห้าม overwrite +* ถ้าต้อง regenerate ให้สร้าง artifact ใหม่หรือ void artifact เดิมก่อนตาม policy +* organizationId required + +--- + +# Scope I4: Checksum + +เพิ่ม utility: + +```txt +src/features/foundation/storage/server/checksum.ts +``` + +รองรับ: + +```ts +sha256(buffer) +``` + +ใช้บันทึก checksum ของ PDF artifact + +--- + +# Scope I5: Approved PDF Storage Refactor + +ปรับ `generateApprovedQuotationPdf()` จากการเขียน: + +```txt +public/generated/... +``` + +เป็น: + +```txt +StorageProvider.putObject() +crm_document_artifacts insert +quotation.approvedPdfUrl update เป็น secure reference +``` + +Recommended `approvedPdfUrl`: + +```txt +artifact: +``` + +หรือถ้ามี field ใหม่: + +```txt +approvedArtifactId +``` + +ถ้าต้องเพิ่ม field ใน quotation: + +```txt +approvedArtifactId +``` + +ให้เพิ่มแบบระวัง + +Rules: + +* approved PDF generate ได้เฉพาะ quotation.status = approved +* ถ้ามี locked approved artifact อยู่แล้ว ให้ไม่ overwrite +* ถ้าต้อง regenerate ให้ return error พร้อมข้อความชัดเจน +* create attachment metadata ให้ชี้ storageKey/artifactId +* audit generate approved PDF + +--- + +# Scope I6: Secure Download Route + +ปรับ: + +```txt +GET /api/crm/quotations/[id]/approved-pdf +``` + +ให้: + +* อ่าน artifact จาก database +* validate organizationId +* validate permission +* ดึงไฟล์ผ่าน StorageProvider.getObject() +* stream PDF กลับ +* ไม่ใช้ public file path ตรง ๆ + +เพิ่ม route generic ได้ถ้าเหมาะสม: + +```txt +GET /api/crm/document-artifacts/[id]/download +``` + +Rules: + +* ห้าม expose storageKey ถ้าไม่จำเป็น +* ห้ามให้ user เดา URL แล้วโหลดได้ +* permission guard ต้องอยู่ server route +* approved PDF download ควร audit ได้ ถ้าทำไม่ใหญ่เกินไป + +--- + +# Scope I7: Artifact Lifecycle + +Implement service: + +```txt +src/features/foundation/document-artifact/server/service.ts +``` + +Functions: + +```ts +createArtifact() +getArtifact() +getActiveArtifactForEntity() +lockArtifact() +voidArtifact() +deleteArtifactMetadataOnly() +downloadArtifact() +``` + +Rules: + +* `locked` artifact ห้ามแก้ storageKey/fileSize/checksum +* `voided` artifact ยังเก็บ metadata +* delete จริงยังไม่ต้องลบ object storage ถ้าไม่จำเป็น +* approved PDF lifecycle ต้อง immutable-first + +--- + +# Scope I8: UI Integration + +Quotation detail: + +* View Approved PDF ใช้ secure download route +* ถ้ามี approved artifact แสดง: + + * fileName + * generatedAt + * generatedBy + * checksum short + * locked badge +* ถ้ายังไม่มี artifact แต่มี old approvedPdfUrl จาก Task H ให้แสดง migration warning + +--- + +# Scope I9: Migration Compatibility + +ถ้ามี approvedPdfUrl เดิมแบบ: + +```txt +/generated/... +``` + +ให้ไม่ลบทิ้งทันที + +เพิ่ม compatibility: + +* ถ้า approvedPdfUrl เป็น artifact reference → ใช้ artifact +* ถ้าเป็น legacy local path → แสดง legacy warning +* future migration script ค่อย migrate legacy file + +--- + +# Scope I10: Documentation + +Update: + +```txt +docs/implementation/technical-debt.md +docs/adr/0009-approved-document-storage-lifecycle.md +``` + +เพิ่ม: + +```txt +Storage provider abstraction +Local vs S3/MinIO policy +Immutable artifact policy +Legacy public/generated migration +Download security model +``` + +--- + +# Permissions + +เพิ่มถ้ายังไม่มี: + +```txt +crm.document_artifact.read +crm.document_artifact.download +crm.document_artifact.void +``` + +--- + +# Audit + +Audit required: + +```txt +crm_document_artifact +``` + +Actions: + +```txt +create +lock +void +download +``` + +ถ้า download audit ทำให้ระบบหนัก ให้ทำ optional toggle ได้ + +--- + +# ห้ามทำ + +```txt +Report +Dashboard KPI +Notification +Template Designer +Mapping Editor +Full object-storage admin UI +Bulk migration of legacy files +``` + +--- + +# Output + +หลังทำเสร็จ สรุป: + +1. Files Added +2. Files Modified +3. Storage Provider Added +4. Artifact Schema Added +5. Approved PDF Refactor +6. Secure Download Added +7. UI Updated +8. Permissions Added +9. Audit Integration +10. Compatibility Notes +11. Remaining Risks +12. Task J Readiness + +--- + +# Definition of Done + +Task I ผ่านเมื่อ: + +✔ storage provider interface พร้อม + +✔ local provider พร้อม + +✔ s3/minio provider skeleton พร้อม + +✔ approved PDF ไม่เขียนลง public/generated เป็น source of truth แล้ว + +✔ approved artifact ถูกบันทึกใน crm_document_artifacts + +✔ approved artifact locked/immutable + +✔ approved PDF download ผ่าน secure route + +✔ permission guard download/generate ครบ + +✔ checksum ถูกบันทึก + +✔ quotation UI แสดง artifact metadata + +✔ legacy approvedPdfUrl compatibility มี + +✔ technical debt / ADR updated + +✔ ยังไม่ทำ report/dashboard/notification diff --git a/scripts/seed-task-h1-fixture.js b/scripts/seed-task-h1-fixture.js index 4686a43..6b3b1d5 100644 --- a/scripts/seed-task-h1-fixture.js +++ b/scripts/seed-task-h1-fixture.js @@ -21,7 +21,9 @@ const PDF_PERMISSIONS = [ 'crm.quotation.document.preview', 'crm.quotation.pdf.preview', 'crm.quotation.pdf.download', - 'crm.quotation.pdf.generate_approved' + 'crm.quotation.pdf.generate_approved', + 'crm.document_artifact.read', + 'crm.document_artifact.download' ]; function loadEnvFile(filePath) { @@ -886,7 +888,7 @@ async function main() { const users = { admin: await ensureUser(sql, organization, creatorId, FIXTURE_USERS.admin, 'Task H.1 Admin', { role: 'admin', - businessRole: 'it_admin', + businessRole: 'sales_manager', permissions: [...PDF_PERMISSIONS, 'users:manage'] }), pdfUser: await ensureUser( @@ -897,13 +899,13 @@ async function main() { 'Task H.1 PDF User', { role: 'user', - businessRole: 'viewer', + businessRole: 'sales_support', permissions: PDF_PERMISSIONS } ), viewer: await ensureUser(sql, organization, creatorId, FIXTURE_USERS.viewer, 'Task H.1 Viewer', { role: 'user', - businessRole: 'viewer', + businessRole: 'sales_support', permissions: ['crm.quotation.read'] }) }; diff --git a/src/app/api/crm/document-artifacts/[id]/download/route.ts b/src/app/api/crm/document-artifacts/[id]/download/route.ts new file mode 100644 index 0000000..189a3f2 --- /dev/null +++ b/src/app/api/crm/document-artifacts/[id]/download/route.ts @@ -0,0 +1,36 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { downloadArtifact } from '@/features/foundation/document-artifact/server/service'; +import { PERMISSIONS } from '@/lib/auth/rbac'; +import { AuthError, requireOrganizationAccess } from '@/lib/auth/session'; + +type Params = { + params: Promise<{ id: string }>; +}; + +export async function GET(_request: NextRequest, { params }: Params) { + try { + const { id } = await params; + const { organization, session } = await requireOrganizationAccess({ + permission: PERMISSIONS.crmDocumentArtifactDownload + }); + const { object } = await downloadArtifact({ + artifactId: id, + organizationId: organization.id, + userId: session.user.id, + auditDownload: true + }); + + return new NextResponse(object.body, { + headers: { + 'Content-Type': object.contentType, + 'Content-Disposition': `inline; filename="${object.fileName || 'artifact'}"` + } + }); + } catch (error) { + if (error instanceof AuthError) { + return NextResponse.json({ message: error.message }, { status: error.status }); + } + + return NextResponse.json({ message: 'Unable to download document artifact' }, { status: 500 }); + } +} diff --git a/src/app/api/crm/quotations/[id]/approved-pdf/route.ts b/src/app/api/crm/quotations/[id]/approved-pdf/route.ts index 33ea636..e4edbb5 100644 --- a/src/app/api/crm/quotations/[id]/approved-pdf/route.ts +++ b/src/app/api/crm/quotations/[id]/approved-pdf/route.ts @@ -15,10 +15,13 @@ type Params = { export async function GET(_request: NextRequest, { params }: Params) { try { const { id } = await params; - const { organization } = await requireOrganizationAccess({ + const { organization, session } = await requireOrganizationAccess({ permission: PERMISSIONS.crmQuotationPdfDownload }); - const pdf = await getStoredApprovedQuotationPdf(id, organization.id); + const pdf = await getStoredApprovedQuotationPdf(id, organization.id, { + userId: session.user.id, + auditDownload: true + }); return new NextResponse(pdf.buffer, { headers: { @@ -52,6 +55,7 @@ export async function POST(_request: NextRequest, { params }: Params) { action: 'generate_approved', beforeData: before, afterData: { + approvedArtifactId: after.approvedArtifactId, approvedPdfUrl: after.approvedPdfUrl, approvedTemplateVersionId: after.approvedTemplateVersionId } diff --git a/src/db/schema.ts b/src/db/schema.ts index 58d3548..70c5e31 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -289,6 +289,7 @@ export const crmQuotations = pgTable( sentAt: timestamp('sent_at', { withTimezone: true }), sentVia: text('sent_via'), approvedAt: timestamp('approved_at', { withTimezone: true }), + approvedArtifactId: text('approved_artifact_id'), approvedPdfUrl: text('approved_pdf_url'), approvedSnapshot: jsonb('approved_snapshot'), approvedTemplateVersionId: text('approved_template_version_id'), @@ -401,6 +402,34 @@ export const crmQuotationAttachments = pgTable('crm_quotation_attachments', { deletedAt: timestamp('deleted_at', { withTimezone: true }) }); +export const crmDocumentArtifacts = pgTable('crm_document_artifacts', { + id: text('id').primaryKey(), + organizationId: text('organization_id').notNull(), + entityType: text('entity_type').notNull(), + entityId: text('entity_id').notNull(), + documentType: text('document_type').notNull(), + artifactType: text('artifact_type').notNull(), + templateVersionId: text('template_version_id'), + storageProvider: text('storage_provider').notNull(), + storageKey: text('storage_key').notNull(), + fileName: text('file_name').notNull(), + contentType: text('content_type').notNull(), + fileSize: integer('file_size'), + checksum: text('checksum'), + status: text('status').default('active').notNull(), + generatedBy: text('generated_by').notNull(), + generatedAt: timestamp('generated_at', { withTimezone: true }).defaultNow().notNull(), + lockedAt: timestamp('locked_at', { withTimezone: true }), + lockedBy: text('locked_by'), + voidedAt: timestamp('voided_at', { withTimezone: true }), + voidedBy: text('voided_by'), + voidReason: text('void_reason'), + metadata: jsonb('metadata'), + createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(), + updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(), + deletedAt: timestamp('deleted_at', { withTimezone: true }) +}); + export const crmApprovalWorkflows = pgTable( 'crm_approval_workflows', { diff --git a/src/features/crm/quotations/api/types.ts b/src/features/crm/quotations/api/types.ts index 5b0f4b5..7490066 100644 --- a/src/features/crm/quotations/api/types.ts +++ b/src/features/crm/quotations/api/types.ts @@ -44,6 +44,21 @@ export interface QuotationSalesmanLookup { name: string; } +export interface QuotationApprovedArtifactSummary { + id: string; + fileName: string; + contentType: string; + fileSize: number | null; + checksum: string | null; + status: string; + generatedAt: string; + generatedBy: string; + generatedByName: string | null; + lockedAt: string | null; + lockedBy: string | null; + lockedByName: string | null; +} + export interface QuotationRecord { id: string; organizationId: string; @@ -80,9 +95,12 @@ export interface QuotationRecord { sentAt: string | null; sentVia: string | null; approvedAt: string | null; + approvedArtifactId: string | null; approvedPdfUrl: string | null; approvedSnapshot: unknown | null; approvedTemplateVersionId: string | null; + approvedArtifact: QuotationApprovedArtifactSummary | null; + hasLegacyApprovedPdf: boolean; acceptedAt: string | null; rejectedAt: string | null; rejectionReason: string | null; diff --git a/src/features/crm/quotations/components/quotation-detail.tsx b/src/features/crm/quotations/components/quotation-detail.tsx index d2f8038..dcf248d 100644 --- a/src/features/crm/quotations/components/quotation-detail.tsx +++ b/src/features/crm/quotations/components/quotation-detail.tsx @@ -129,47 +129,102 @@ function ItemDialog({ Line items drive quotation totals from the server.
- setValues((s) => ({ ...s, productType: value }))} + > + + + {referenceData.productTypes.map((option) => ( - {option.label} + + {option.label} + ))} - setValues((s) => ({ ...s, description: e.target.value }))} placeholder='Description' /> + setValues((s) => ({ ...s, description: e.target.value }))} + placeholder='Description' + />
- setValues((s) => ({ ...s, quantity: e.target.value }))} type='number' placeholder='Quantity' /> - setValues((s) => ({ ...s, quantity: e.target.value }))} + type='number' + placeholder='Quantity' + /> +
- setValues((s) => ({ ...s, unitPrice: e.target.value }))} type='number' placeholder='Unit price' /> - setValues((s) => ({ ...s, discount: e.target.value }))} type='number' placeholder='Discount' /> + setValues((s) => ({ ...s, unitPrice: e.target.value }))} + type='number' + placeholder='Unit price' + /> + setValues((s) => ({ ...s, discount: e.target.value }))} + type='number' + placeholder='Discount' + />
- + setValues((s) => ({ ...s, discountType: value === '__none__' ? '' : value })) + } + > + + + No discount type {referenceData.discountTypes.map((option) => ( - {option.label} + + {option.label} + ))} - setValues((s) => ({ ...s, taxRate: e.target.value }))} type='number' placeholder='Tax rate %' /> + setValues((s) => ({ ...s, taxRate: e.target.value }))} + type='number' + placeholder='Tax rate %' + />
-