@open-mercato/core 0.4.2-canary-ed15f2e753 → 0.4.2-canary-f075c3eb92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/entities.ids.generated.js +0 -1
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +0 -2
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/api_keys/setup.js +11 -0
- package/dist/modules/api_keys/setup.js.map +7 -0
- package/dist/modules/attachments/components/AttachmentLibrary.js +1 -1
- package/dist/modules/attachments/components/AttachmentLibrary.js.map +2 -2
- package/dist/modules/attachments/lib/assignmentDetails.js +31 -17
- package/dist/modules/attachments/lib/assignmentDetails.js.map +2 -2
- package/dist/modules/attachments/lib/partitions.js +3 -3
- package/dist/modules/attachments/lib/partitions.js.map +2 -2
- package/dist/modules/attachments/setup.js +11 -0
- package/dist/modules/attachments/setup.js.map +7 -0
- package/dist/modules/audit_logs/setup.js +12 -0
- package/dist/modules/audit_logs/setup.js.map +7 -0
- package/dist/modules/auth/lib/setup-app.js +29 -159
- package/dist/modules/auth/lib/setup-app.js.map +2 -2
- package/dist/modules/auth/setup.js +11 -0
- package/dist/modules/auth/setup.js.map +7 -0
- package/dist/modules/business_rules/data/validators.js +0 -34
- package/dist/modules/business_rules/data/validators.js.map +2 -2
- package/dist/modules/business_rules/index.js +1 -21
- package/dist/modules/business_rules/index.js.map +2 -2
- package/dist/modules/business_rules/lib/rule-engine.js +1 -182
- package/dist/modules/business_rules/lib/rule-engine.js.map +2 -2
- package/dist/modules/business_rules/setup.js +11 -0
- package/dist/modules/business_rules/setup.js.map +7 -0
- package/dist/modules/catalog/setup.js +22 -0
- package/dist/modules/catalog/setup.js.map +7 -0
- package/dist/modules/configs/lib/upgrade-actions.js +65 -15
- package/dist/modules/configs/lib/upgrade-actions.js.map +2 -2
- package/dist/modules/configs/setup.js +16 -0
- package/dist/modules/configs/setup.js.map +7 -0
- package/dist/modules/currencies/setup.js +16 -0
- package/dist/modules/currencies/setup.js.map +7 -0
- package/dist/modules/customers/setup.js +36 -0
- package/dist/modules/customers/setup.js.map +7 -0
- package/dist/modules/dashboards/setup.js +12 -0
- package/dist/modules/dashboards/setup.js.map +7 -0
- package/dist/modules/dictionaries/setup.js +12 -0
- package/dist/modules/dictionaries/setup.js.map +7 -0
- package/dist/modules/directory/setup.js +12 -0
- package/dist/modules/directory/setup.js.map +7 -0
- package/dist/modules/entities/setup.js +11 -0
- package/dist/modules/entities/setup.js.map +7 -0
- package/dist/modules/feature_toggles/setup.js +11 -0
- package/dist/modules/feature_toggles/setup.js.map +7 -0
- package/dist/modules/perspectives/setup.js +12 -0
- package/dist/modules/perspectives/setup.js.map +7 -0
- package/dist/modules/planner/setup.js +21 -0
- package/dist/modules/planner/setup.js.map +7 -0
- package/dist/modules/query_index/setup.js +11 -0
- package/dist/modules/query_index/setup.js.map +7 -0
- package/dist/modules/resources/setup.js +21 -0
- package/dist/modules/resources/setup.js.map +7 -0
- package/dist/modules/sales/acl.js +0 -1
- package/dist/modules/sales/acl.js.map +2 -2
- package/dist/modules/sales/backend/sales/documents/[id]/page.js +0 -12
- package/dist/modules/sales/backend/sales/documents/[id]/page.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +0 -62
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/lib/dictionaries.js +0 -3
- package/dist/modules/sales/lib/dictionaries.js.map +2 -2
- package/dist/modules/sales/setup.js +99 -0
- package/dist/modules/sales/setup.js.map +7 -0
- package/dist/modules/staff/setup.js +27 -0
- package/dist/modules/staff/setup.js.map +7 -0
- package/dist/modules/workflows/acl.js +0 -2
- package/dist/modules/workflows/acl.js.map +2 -2
- package/dist/modules/workflows/api/instances/route.js +6 -18
- package/dist/modules/workflows/api/instances/route.js.map +2 -2
- package/dist/modules/workflows/api/tasks/route.js +1 -6
- package/dist/modules/workflows/api/tasks/route.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/[id]/page.js +1 -9
- package/dist/modules/workflows/backend/definitions/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/[id]/page.meta.js +1 -1
- package/dist/modules/workflows/backend/definitions/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/create/page.js +15 -24
- package/dist/modules/workflows/backend/definitions/create/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/create/page.meta.js +1 -1
- package/dist/modules/workflows/backend/definitions/create/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/visual-editor/page.js +132 -150
- package/dist/modules/workflows/backend/definitions/visual-editor/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/visual-editor/page.meta.js +1 -1
- package/dist/modules/workflows/backend/definitions/visual-editor/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.js +1 -1
- package/dist/modules/workflows/backend/events/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.meta.js +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/instances/[id]/page.meta.js +2 -2
- package/dist/modules/workflows/backend/instances/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.js +1 -1
- package/dist/modules/workflows/backend/tasks/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.meta.js +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/page.js +6 -5
- package/dist/modules/workflows/backend/tasks/page.js.map +2 -2
- package/dist/modules/workflows/cli.js +3 -81
- package/dist/modules/workflows/cli.js.map +3 -3
- package/dist/modules/workflows/data/entities.js +1 -64
- package/dist/modules/workflows/data/entities.js.map +2 -2
- package/dist/modules/workflows/data/validators.js +0 -115
- package/dist/modules/workflows/data/validators.js.map +2 -2
- package/dist/modules/workflows/examples/checkout-demo-definition.json +5 -1
- package/dist/modules/workflows/lib/activity-executor.js +13 -75
- package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
- package/dist/modules/workflows/lib/graph-utils.js +2 -71
- package/dist/modules/workflows/lib/graph-utils.js.map +2 -2
- package/dist/modules/workflows/lib/seeds.js +7 -36
- package/dist/modules/workflows/lib/seeds.js.map +2 -2
- package/dist/modules/workflows/lib/start-validator.js +23 -33
- package/dist/modules/workflows/lib/start-validator.js.map +2 -2
- package/dist/modules/workflows/lib/transition-handler.js +45 -157
- package/dist/modules/workflows/lib/transition-handler.js.map +3 -3
- package/dist/modules/workflows/migrations/Migration20251207131955.js +76 -72
- package/dist/modules/workflows/migrations/Migration20251207131955.js.map +2 -2
- package/dist/modules/workflows/setup.js +16 -0
- package/dist/modules/workflows/setup.js.map +7 -0
- package/generated/entities.ids.generated.ts +0 -1
- package/generated/entity-fields-registry.ts +0 -2
- package/package.json +2 -2
- package/src/__tests__/module-decoupling.test.ts +356 -0
- package/src/modules/api_keys/setup.ts +9 -0
- package/src/modules/attachments/components/AttachmentLibrary.tsx +2 -2
- package/src/modules/attachments/lib/assignmentDetails.ts +32 -16
- package/src/modules/attachments/lib/partitions.ts +3 -3
- package/src/modules/attachments/setup.ts +9 -0
- package/src/modules/audit_logs/setup.ts +10 -0
- package/src/modules/auth/__tests__/cli-setup-acl.test.ts +30 -0
- package/src/modules/auth/lib/setup-app.ts +40 -177
- package/src/modules/auth/setup.ts +9 -0
- package/src/modules/business_rules/data/validators.ts +0 -40
- package/src/modules/business_rules/index.ts +0 -25
- package/src/modules/business_rules/lib/rule-engine.ts +1 -281
- package/src/modules/business_rules/setup.ts +9 -0
- package/src/modules/catalog/setup.ts +22 -0
- package/src/modules/configs/lib/upgrade-actions.ts +78 -17
- package/src/modules/configs/setup.ts +14 -0
- package/src/modules/currencies/setup.ts +15 -0
- package/src/modules/customers/setup.ts +36 -0
- package/src/modules/dashboards/setup.ts +10 -0
- package/src/modules/dictionaries/setup.ts +10 -0
- package/src/modules/directory/setup.ts +10 -0
- package/src/modules/entities/setup.ts +9 -0
- package/src/modules/feature_toggles/setup.ts +9 -0
- package/src/modules/perspectives/setup.ts +10 -0
- package/src/modules/planner/setup.ts +21 -0
- package/src/modules/query_index/setup.ts +9 -0
- package/src/modules/resources/setup.ts +21 -0
- package/src/modules/sales/acl.ts +0 -1
- package/src/modules/sales/backend/sales/documents/[id]/page.tsx +0 -16
- package/src/modules/sales/commands/documents.ts +1 -74
- package/src/modules/sales/lib/dictionaries.ts +0 -3
- package/src/modules/sales/setup.ts +108 -0
- package/src/modules/staff/setup.ts +27 -0
- package/src/modules/workflows/acl.ts +0 -2
- package/src/modules/workflows/api/__tests__/instances.route.test.ts +2 -5
- package/src/modules/workflows/api/instances/route.ts +7 -21
- package/src/modules/workflows/api/tasks/route.ts +1 -7
- package/src/modules/workflows/backend/definitions/[id]/page.meta.ts +1 -1
- package/src/modules/workflows/backend/definitions/[id]/page.tsx +0 -9
- package/src/modules/workflows/backend/definitions/create/page.meta.ts +1 -1
- package/src/modules/workflows/backend/definitions/create/page.tsx +0 -9
- package/src/modules/workflows/backend/definitions/visual-editor/page.meta.ts +1 -1
- package/src/modules/workflows/backend/definitions/visual-editor/page.tsx +3 -21
- package/src/modules/workflows/backend/events/[id]/page.meta.ts +2 -2
- package/src/modules/workflows/backend/events/[id]/page.tsx +1 -1
- package/src/modules/workflows/backend/instances/[id]/page.meta.ts +2 -2
- package/src/modules/workflows/backend/tasks/[id]/page.meta.ts +2 -2
- package/src/modules/workflows/backend/tasks/[id]/page.tsx +1 -1
- package/src/modules/workflows/backend/tasks/page.tsx +6 -5
- package/src/modules/workflows/cli.ts +0 -111
- package/src/modules/workflows/data/entities.ts +0 -124
- package/src/modules/workflows/data/validators.ts +0 -138
- package/src/modules/workflows/examples/checkout-demo-definition.json +5 -1
- package/src/modules/workflows/i18n/en.json +0 -71
- package/src/modules/workflows/lib/__tests__/activity-executor.test.ts +36 -43
- package/src/modules/workflows/lib/__tests__/transition-handler.test.ts +90 -170
- package/src/modules/workflows/lib/activity-executor.ts +16 -129
- package/src/modules/workflows/lib/graph-utils.ts +2 -117
- package/src/modules/workflows/lib/seeds.ts +12 -50
- package/src/modules/workflows/lib/start-validator.ts +28 -38
- package/src/modules/workflows/lib/transition-handler.ts +55 -208
- package/src/modules/workflows/migrations/Migration20251207131955.ts +77 -143
- package/src/modules/workflows/setup.ts +15 -0
- package/dist/generated/entities/workflow_event_trigger/index.js +0 -33
- package/dist/generated/entities/workflow_event_trigger/index.js.map +0 -7
- package/dist/modules/auth/events.js +0 -30
- package/dist/modules/auth/events.js.map +0 -7
- package/dist/modules/business_rules/api/execute/[ruleId]/route.js +0 -145
- package/dist/modules/business_rules/api/execute/[ruleId]/route.js.map +0 -7
- package/dist/modules/catalog/events.js +0 -34
- package/dist/modules/catalog/events.js.map +0 -7
- package/dist/modules/customers/events.js +0 -49
- package/dist/modules/customers/events.js.map +0 -7
- package/dist/modules/directory/events.js +0 -23
- package/dist/modules/directory/events.js.map +0 -7
- package/dist/modules/sales/events.js +0 -63
- package/dist/modules/sales/events.js.map +0 -7
- package/dist/modules/sales/lib/frontend/documentDataEvents.js +0 -25
- package/dist/modules/sales/lib/frontend/documentDataEvents.js.map +0 -7
- package/dist/modules/workflows/components/DefinitionTriggersEditor.js +0 -481
- package/dist/modules/workflows/components/DefinitionTriggersEditor.js.map +0 -7
- package/dist/modules/workflows/components/EventTriggersEditor.js +0 -553
- package/dist/modules/workflows/components/EventTriggersEditor.js.map +0 -7
- package/dist/modules/workflows/events.js +0 -38
- package/dist/modules/workflows/events.js.map +0 -7
- package/dist/modules/workflows/examples/order-approval-definition.json +0 -257
- package/dist/modules/workflows/examples/order-approval-guard-rules.json +0 -32
- package/dist/modules/workflows/lib/event-trigger-service.js +0 -308
- package/dist/modules/workflows/lib/event-trigger-service.js.map +0 -7
- package/dist/modules/workflows/migrations/Migration20260123143500.js +0 -36
- package/dist/modules/workflows/migrations/Migration20260123143500.js.map +0 -7
- package/dist/modules/workflows/subscribers/event-trigger.js +0 -78
- package/dist/modules/workflows/subscribers/event-trigger.js.map +0 -7
- package/dist/modules/workflows/widgets/injection/order-approval/widget.client.js +0 -323
- package/dist/modules/workflows/widgets/injection/order-approval/widget.client.js.map +0 -7
- package/dist/modules/workflows/widgets/injection/order-approval/widget.js +0 -17
- package/dist/modules/workflows/widgets/injection/order-approval/widget.js.map +0 -7
- package/dist/modules/workflows/widgets/injection-table.js +0 -19
- package/dist/modules/workflows/widgets/injection-table.js.map +0 -7
- package/generated/entities/workflow_event_trigger/index.ts +0 -15
- package/src/modules/auth/events.ts +0 -39
- package/src/modules/business_rules/api/execute/[ruleId]/route.ts +0 -163
- package/src/modules/catalog/events.ts +0 -45
- package/src/modules/customers/events.ts +0 -63
- package/src/modules/directory/events.ts +0 -31
- package/src/modules/sales/events.ts +0 -82
- package/src/modules/sales/lib/frontend/documentDataEvents.ts +0 -28
- package/src/modules/workflows/components/DefinitionTriggersEditor.tsx +0 -581
- package/src/modules/workflows/components/EventTriggersEditor.tsx +0 -664
- package/src/modules/workflows/events.ts +0 -49
- package/src/modules/workflows/examples/order-approval-definition.json +0 -257
- package/src/modules/workflows/examples/order-approval-guard-rules.json +0 -32
- package/src/modules/workflows/lib/event-trigger-service.ts +0 -557
- package/src/modules/workflows/migrations/Migration20260123143500.ts +0 -38
- package/src/modules/workflows/subscribers/event-trigger.ts +0 -109
- package/src/modules/workflows/widgets/injection/order-approval/widget.client.tsx +0 -446
- package/src/modules/workflows/widgets/injection/order-approval/widget.ts +0 -16
- package/src/modules/workflows/widgets/injection-table.ts +0 -21
|
@@ -4,12 +4,15 @@ let _entityLinkSpecsCache = null;
|
|
|
4
4
|
function getEntityLinkSpecs() {
|
|
5
5
|
if (_entityLinkSpecsCache) return _entityLinkSpecsCache;
|
|
6
6
|
const E = getEntityIds();
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const specs = {};
|
|
8
|
+
if (E.catalog?.catalog_product) {
|
|
9
|
+
specs[E.catalog.catalog_product] = {
|
|
9
10
|
labelFields: ["title", "sku", "handle"],
|
|
10
11
|
buildHref: (record) => buildSimpleHref("/backend/catalog/products", record.id)
|
|
11
|
-
}
|
|
12
|
-
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (E.catalog?.catalog_product_variant) {
|
|
15
|
+
specs[E.catalog.catalog_product_variant] = {
|
|
13
16
|
labelFields: ["name", "sku"],
|
|
14
17
|
extraFields: ["product_id"],
|
|
15
18
|
buildHref: (record) => {
|
|
@@ -17,8 +20,10 @@ function getEntityLinkSpecs() {
|
|
|
17
20
|
if (!productId) return null;
|
|
18
21
|
return `/backend/catalog/products/${encodeURIComponent(productId)}/variants/${encodeURIComponent(String(record.id ?? ""))}`;
|
|
19
22
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (E.customers?.customer_entity) {
|
|
26
|
+
specs[E.customers.customer_entity] = {
|
|
22
27
|
labelFields: ["display_name"],
|
|
23
28
|
extraFields: ["kind"],
|
|
24
29
|
buildHref: (record) => {
|
|
@@ -27,32 +32,41 @@ function getEntityLinkSpecs() {
|
|
|
27
32
|
if (kind === "person") return buildSimpleHref("/backend/customers/people", record.id);
|
|
28
33
|
return null;
|
|
29
34
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (E.customers?.customer_person_profile) {
|
|
38
|
+
specs[E.customers.customer_person_profile] = {
|
|
32
39
|
labelFields: ["preferred_name", "display_name", "first_name", "last_name"],
|
|
33
40
|
extraFields: ["entity_id", "first_name", "last_name"],
|
|
34
41
|
buildHref: (record) => {
|
|
35
42
|
const entityId = readRecordValue(record, "entity_id");
|
|
36
43
|
return entityId ? buildSimpleHref("/backend/customers/people", entityId) : null;
|
|
37
44
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (E.customers?.customer_company_profile) {
|
|
48
|
+
specs[E.customers.customer_company_profile] = {
|
|
40
49
|
labelFields: ["brand_name", "display_name", "legal_name"],
|
|
41
50
|
extraFields: ["entity_id"],
|
|
42
51
|
buildHref: (record) => {
|
|
43
52
|
const entityId = readRecordValue(record, "entity_id");
|
|
44
53
|
return entityId ? buildSimpleHref("/backend/customers/companies", entityId) : null;
|
|
45
54
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (E.customers?.customer_deal) {
|
|
58
|
+
specs[E.customers.customer_deal] = {
|
|
48
59
|
labelFields: ["title"],
|
|
49
60
|
buildHref: (record) => buildSimpleHref("/backend/customers/deals", record.id)
|
|
50
|
-
}
|
|
51
|
-
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (E.sales?.sales_channel) {
|
|
64
|
+
specs[E.sales.sales_channel] = {
|
|
52
65
|
labelFields: ["name", "title"],
|
|
53
66
|
buildHref: (record) => buildSimpleHref("/backend/sales/channels", record.id, "/edit")
|
|
54
|
-
}
|
|
55
|
-
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
_entityLinkSpecsCache = specs;
|
|
56
70
|
return _entityLinkSpecsCache;
|
|
57
71
|
}
|
|
58
72
|
const LIBRARY_ENTITY_ID = "attachments:library";
|
|
@@ -128,7 +142,7 @@ function isUuid(value) {
|
|
|
128
142
|
}
|
|
129
143
|
function filterIdsForEntity(entityId, ids) {
|
|
130
144
|
const E = getEntityIds();
|
|
131
|
-
if (entityId === E.catalog
|
|
145
|
+
if (entityId === E.catalog?.catalog_product_variant || entityId === E.catalog?.catalog_product) {
|
|
132
146
|
return ids.filter((id) => isUuid(id));
|
|
133
147
|
}
|
|
134
148
|
return ids;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/attachments/lib/assignmentDetails.ts"],
|
|
4
|
-
"sourcesContent": ["import type { QueryEngine } from '@open-mercato/shared/lib/query/types'\nimport type { AttachmentAssignment } from './metadata'\nimport type { CustomEntitySpec } from '@open-mercato/shared/modules/entities'\nimport { getEntityIds } from '@open-mercato/shared/lib/encryption/entityIds'\nimport { getModules } from '@open-mercato/shared/lib/i18n/server'\n\ntype AssignmentLinkSpec = {\n labelFields?: string[]\n extraFields?: string[]\n buildHref?: (record: Record<string, unknown>) => string | null | undefined\n}\n\nlet _entityLinkSpecsCache: Record<string, AssignmentLinkSpec> | null = null\n\nfunction getEntityLinkSpecs(): Record<string, AssignmentLinkSpec> {\n if (_entityLinkSpecsCache) return _entityLinkSpecsCache\n const E = getEntityIds() as any\n _entityLinkSpecsCache = {\n [E.catalog.catalog_product]: {\n labelFields: ['title', 'sku', 'handle'],\n buildHref: (record) => buildSimpleHref('/backend/catalog/products', record.id),\n },\n [E.catalog.catalog_product_variant]: {\n labelFields: ['name', 'sku'],\n extraFields: ['product_id'],\n buildHref: (record) => {\n const productId = readRecordValue(record, 'product_id')\n if (!productId) return null\n return `/backend/catalog/products/${encodeURIComponent(productId)}/variants/${encodeURIComponent(String(record.id ?? ''))}`\n },\n },\n [E.customers.customer_entity]: {\n labelFields: ['display_name'],\n extraFields: ['kind'],\n buildHref: (record) => {\n const kind = String(readRecordValue(record, 'kind') || '').toLowerCase()\n if (kind === 'company') return buildSimpleHref('/backend/customers/companies', record.id)\n if (kind === 'person') return buildSimpleHref('/backend/customers/people', record.id)\n return null\n },\n },\n [E.customers.customer_person_profile]: {\n labelFields: ['preferred_name', 'display_name', 'first_name', 'last_name'],\n extraFields: ['entity_id', 'first_name', 'last_name'],\n buildHref: (record) => {\n const entityId = readRecordValue(record, 'entity_id')\n return entityId ? buildSimpleHref('/backend/customers/people', entityId) : null\n },\n },\n [E.customers.customer_company_profile]: {\n labelFields: ['brand_name', 'display_name', 'legal_name'],\n extraFields: ['entity_id'],\n buildHref: (record) => {\n const entityId = readRecordValue(record, 'entity_id')\n return entityId ? buildSimpleHref('/backend/customers/companies', entityId) : null\n },\n },\n [E.customers.customer_deal]: {\n labelFields: ['title'],\n buildHref: (record) => buildSimpleHref('/backend/customers/deals', record.id),\n },\n [E.sales.sales_channel]: {\n labelFields: ['name', 'title'],\n buildHref: (record) => buildSimpleHref('/backend/sales/channels', record.id, '/edit'),\n },\n }\n return _entityLinkSpecsCache\n}\n\nconst LIBRARY_ENTITY_ID = 'attachments:library'\nconst DEFAULT_LABEL_FIELDS = [\n 'label',\n 'title',\n 'name',\n 'display_name',\n 'displayName',\n 'subject',\n 'sku',\n 'handle',\n 'order_number',\n 'quote_number',\n 'invoice_number',\n 'email',\n 'company_name',\n 'legal_name',\n 'brand_name',\n]\n\nlet entitySpecsPromise: Promise<Map<string, CustomEntitySpec>> | null = null\n\nasync function loadEntitySpecs(): Promise<Map<string, CustomEntitySpec>> {\n if (!entitySpecsPromise) {\n entitySpecsPromise = Promise.resolve()\n .then(() => {\n const map = new Map<string, CustomEntitySpec>()\n const mods = getModules()\n for (const mod of mods) {\n const specs = ((mod as any).customEntities as CustomEntitySpec[] | undefined) ?? []\n for (const spec of specs) {\n if (spec?.id && !map.has(spec.id)) {\n map.set(spec.id, spec)\n }\n }\n }\n return map\n })\n .catch(() => new Map<string, CustomEntitySpec>())\n }\n return entitySpecsPromise\n}\n\nexport type AssignmentEnrichment = {\n label?: string\n href?: string\n}\n\nexport type AssignmentEnrichmentMap = Map<string, AssignmentEnrichment>\n\nfunction camelToSnake(value: string): string {\n return value\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/[\\s-]+/g, '_')\n .toLowerCase()\n}\n\nfunction snakeToCamel(value: string): string {\n return value.replace(/[_-](\\w)/g, (_, c: string) => c.toUpperCase())\n}\n\nfunction normalizeValue(value: unknown): string | null {\n if (value === undefined || value === null) return null\n if (typeof value === 'string') {\n const trimmed = value.trim()\n return trimmed.length ? trimmed : null\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value)\n }\n return null\n}\n\nfunction readRecordValue(record: Record<string, unknown>, field: string): string | null {\n if (!field) return null\n if (record[field] !== undefined) return normalizeValue(record[field])\n const snake = camelToSnake(field)\n if (snake !== field && record[snake] !== undefined) return normalizeValue(record[snake])\n const camel = snakeToCamel(field)\n if (camel !== field && record[camel] !== undefined) return normalizeValue(record[camel])\n return null\n}\n\nfunction buildSimpleHref(base: string, idValue: unknown, suffix: string = ''): string | null {\n const id = normalizeValue(idValue)\n if (!id) return null\n return `${base}/${encodeURIComponent(id)}${suffix}`\n}\n\nfunction isUuid(value: string | null | undefined): boolean {\n return typeof value === 'string' && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value.trim())\n}\n\nfunction filterIdsForEntity(entityId: string, ids: string[]): string[] {\n const E = getEntityIds() as any\n if (entityId === E.catalog.catalog_product_variant || entityId === E.catalog.catalog_product) {\n return ids.filter((id) => isUuid(id))\n }\n return ids\n}\n\nfunction resolveLabelCandidates(entityId: string, linkSpec: AssignmentLinkSpec | undefined, entitySpecs: Map<string, CustomEntitySpec>): string[] {\n const candidates = new Set<string>()\n const spec = entitySpecs.get(entityId)\n if (spec?.labelField) {\n candidates.add(spec.labelField)\n candidates.add(camelToSnake(spec.labelField))\n }\n for (const field of linkSpec?.labelFields ?? []) {\n candidates.add(field)\n candidates.add(camelToSnake(field))\n }\n DEFAULT_LABEL_FIELDS.forEach((field) => {\n candidates.add(field)\n candidates.add(camelToSnake(field))\n })\n return Array.from(candidates).filter((field) => field.length > 0)\n}\n\nfunction buildLabel(\n record: Record<string, unknown>,\n entityId: string,\n linkSpec: AssignmentLinkSpec | undefined,\n entitySpecs: Map<string, CustomEntitySpec>\n): string | null {\n const candidates = resolveLabelCandidates(entityId, linkSpec, entitySpecs)\n for (const candidate of candidates) {\n const value = readRecordValue(record, candidate)\n if (value) return value\n }\n const fullName = [readRecordValue(record, 'first_name'), readRecordValue(record, 'last_name')]\n .filter((part): part is string => Boolean(part))\n .join(' ')\n .trim()\n if (fullName.length) return fullName\n return null\n}\n\nexport async function resolveAssignmentEnrichments(\n assignments: AttachmentAssignment[],\n opts: { queryEngine?: QueryEngine | null; tenantId: string; organizationId: string },\n): Promise<AssignmentEnrichmentMap> {\n const map: AssignmentEnrichmentMap = new Map()\n if (!assignments.length || !opts.queryEngine) return map\n const entitySpecs = await loadEntitySpecs()\n const grouped = new Map<string, Set<string>>()\n for (const assignment of assignments) {\n if (!assignment || assignment.type === LIBRARY_ENTITY_ID) continue\n const type = assignment.type?.trim()\n const id = assignment.id?.trim()\n if (!type || !id) continue\n if (!grouped.has(type)) grouped.set(type, new Set())\n grouped.get(type)!.add(id)\n }\n if (!grouped.size) return map\n\n const entityLinkSpecs = getEntityLinkSpecs()\n for (const [entityId, idsSet] of grouped.entries()) {\n const ids = filterIdsForEntity(entityId, Array.from(idsSet.values()))\n if (!ids.length) continue\n const linkSpec = entityLinkSpecs[entityId]\n const fields = new Set<string>(['id'])\n const candidates = resolveLabelCandidates(entityId, linkSpec, entitySpecs)\n candidates.forEach((field) => fields.add(field))\n for (const extra of linkSpec?.extraFields ?? []) {\n fields.add(extra)\n fields.add(camelToSnake(extra))\n }\n try {\n const result = await opts.queryEngine.query(entityId as any, {\n fields: Array.from(fields),\n filters: { id: ids.length === 1 ? { $eq: ids[0] } : { $in: ids } },\n tenantId: opts.tenantId,\n organizationId: opts.organizationId,\n page: { pageSize: Math.max(ids.length, 20) },\n })\n for (const record of result.items ?? []) {\n const recordId = normalizeValue((record as Record<string, unknown>).id)\n if (!recordId) continue\n const label = buildLabel(record as Record<string, unknown>, entityId, linkSpec, entitySpecs)\n const href = linkSpec?.buildHref?.(record as Record<string, unknown>) ?? null\n if (label || href) {\n map.set(`${entityId}:${recordId}`, {\n label: label ?? undefined,\n href: href ?? undefined,\n })\n }\n }\n } catch (error) {\n console.warn('[attachments] Failed to resolve assignment details for', entityId, error)\n }\n }\n return map\n}\n\nexport function applyAssignmentEnrichments(\n assignments: AttachmentAssignment[],\n enrichments: AssignmentEnrichmentMap,\n): AttachmentAssignment[] {\n if (!enrichments.size) return assignments\n return assignments.map((assignment) => {\n if (!assignment || !assignment.type || !assignment.id) return assignment\n const key = `${assignment.type}:${assignment.id}`\n const detail = enrichments.get(key)\n if (!detail) return assignment\n const next: AttachmentAssignment = { ...assignment }\n if (!next.label && detail.label) next.label = detail.label\n if (!next.href && detail.href) next.href = detail.href\n return next\n })\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAQ3B,IAAI,wBAAmE;AAEvE,SAAS,qBAAyD;AAChE,MAAI,sBAAuB,QAAO;AAClC,QAAM,IAAI,aAAa;AACvB,
|
|
4
|
+
"sourcesContent": ["import type { QueryEngine } from '@open-mercato/shared/lib/query/types'\nimport type { AttachmentAssignment } from './metadata'\nimport type { CustomEntitySpec } from '@open-mercato/shared/modules/entities'\nimport { getEntityIds } from '@open-mercato/shared/lib/encryption/entityIds'\nimport { getModules } from '@open-mercato/shared/lib/i18n/server'\n\ntype AssignmentLinkSpec = {\n labelFields?: string[]\n extraFields?: string[]\n buildHref?: (record: Record<string, unknown>) => string | null | undefined\n}\n\nlet _entityLinkSpecsCache: Record<string, AssignmentLinkSpec> | null = null\n\nfunction getEntityLinkSpecs(): Record<string, AssignmentLinkSpec> {\n if (_entityLinkSpecsCache) return _entityLinkSpecsCache\n const E = getEntityIds() as any\n const specs: Record<string, AssignmentLinkSpec> = {}\n\n if (E.catalog?.catalog_product) {\n specs[E.catalog.catalog_product] = {\n labelFields: ['title', 'sku', 'handle'],\n buildHref: (record) => buildSimpleHref('/backend/catalog/products', record.id),\n }\n }\n if (E.catalog?.catalog_product_variant) {\n specs[E.catalog.catalog_product_variant] = {\n labelFields: ['name', 'sku'],\n extraFields: ['product_id'],\n buildHref: (record) => {\n const productId = readRecordValue(record, 'product_id')\n if (!productId) return null\n return `/backend/catalog/products/${encodeURIComponent(productId)}/variants/${encodeURIComponent(String(record.id ?? ''))}`\n },\n }\n }\n if (E.customers?.customer_entity) {\n specs[E.customers.customer_entity] = {\n labelFields: ['display_name'],\n extraFields: ['kind'],\n buildHref: (record) => {\n const kind = String(readRecordValue(record, 'kind') || '').toLowerCase()\n if (kind === 'company') return buildSimpleHref('/backend/customers/companies', record.id)\n if (kind === 'person') return buildSimpleHref('/backend/customers/people', record.id)\n return null\n },\n }\n }\n if (E.customers?.customer_person_profile) {\n specs[E.customers.customer_person_profile] = {\n labelFields: ['preferred_name', 'display_name', 'first_name', 'last_name'],\n extraFields: ['entity_id', 'first_name', 'last_name'],\n buildHref: (record) => {\n const entityId = readRecordValue(record, 'entity_id')\n return entityId ? buildSimpleHref('/backend/customers/people', entityId) : null\n },\n }\n }\n if (E.customers?.customer_company_profile) {\n specs[E.customers.customer_company_profile] = {\n labelFields: ['brand_name', 'display_name', 'legal_name'],\n extraFields: ['entity_id'],\n buildHref: (record) => {\n const entityId = readRecordValue(record, 'entity_id')\n return entityId ? buildSimpleHref('/backend/customers/companies', entityId) : null\n },\n }\n }\n if (E.customers?.customer_deal) {\n specs[E.customers.customer_deal] = {\n labelFields: ['title'],\n buildHref: (record) => buildSimpleHref('/backend/customers/deals', record.id),\n }\n }\n if (E.sales?.sales_channel) {\n specs[E.sales.sales_channel] = {\n labelFields: ['name', 'title'],\n buildHref: (record) => buildSimpleHref('/backend/sales/channels', record.id, '/edit'),\n }\n }\n\n _entityLinkSpecsCache = specs\n return _entityLinkSpecsCache\n}\n\nconst LIBRARY_ENTITY_ID = 'attachments:library'\nconst DEFAULT_LABEL_FIELDS = [\n 'label',\n 'title',\n 'name',\n 'display_name',\n 'displayName',\n 'subject',\n 'sku',\n 'handle',\n 'order_number',\n 'quote_number',\n 'invoice_number',\n 'email',\n 'company_name',\n 'legal_name',\n 'brand_name',\n]\n\nlet entitySpecsPromise: Promise<Map<string, CustomEntitySpec>> | null = null\n\nasync function loadEntitySpecs(): Promise<Map<string, CustomEntitySpec>> {\n if (!entitySpecsPromise) {\n entitySpecsPromise = Promise.resolve()\n .then(() => {\n const map = new Map<string, CustomEntitySpec>()\n const mods = getModules()\n for (const mod of mods) {\n const specs = ((mod as any).customEntities as CustomEntitySpec[] | undefined) ?? []\n for (const spec of specs) {\n if (spec?.id && !map.has(spec.id)) {\n map.set(spec.id, spec)\n }\n }\n }\n return map\n })\n .catch(() => new Map<string, CustomEntitySpec>())\n }\n return entitySpecsPromise\n}\n\nexport type AssignmentEnrichment = {\n label?: string\n href?: string\n}\n\nexport type AssignmentEnrichmentMap = Map<string, AssignmentEnrichment>\n\nfunction camelToSnake(value: string): string {\n return value\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/[\\s-]+/g, '_')\n .toLowerCase()\n}\n\nfunction snakeToCamel(value: string): string {\n return value.replace(/[_-](\\w)/g, (_, c: string) => c.toUpperCase())\n}\n\nfunction normalizeValue(value: unknown): string | null {\n if (value === undefined || value === null) return null\n if (typeof value === 'string') {\n const trimmed = value.trim()\n return trimmed.length ? trimmed : null\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value)\n }\n return null\n}\n\nfunction readRecordValue(record: Record<string, unknown>, field: string): string | null {\n if (!field) return null\n if (record[field] !== undefined) return normalizeValue(record[field])\n const snake = camelToSnake(field)\n if (snake !== field && record[snake] !== undefined) return normalizeValue(record[snake])\n const camel = snakeToCamel(field)\n if (camel !== field && record[camel] !== undefined) return normalizeValue(record[camel])\n return null\n}\n\nfunction buildSimpleHref(base: string, idValue: unknown, suffix: string = ''): string | null {\n const id = normalizeValue(idValue)\n if (!id) return null\n return `${base}/${encodeURIComponent(id)}${suffix}`\n}\n\nfunction isUuid(value: string | null | undefined): boolean {\n return typeof value === 'string' && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value.trim())\n}\n\nfunction filterIdsForEntity(entityId: string, ids: string[]): string[] {\n const E = getEntityIds() as any\n if (entityId === E.catalog?.catalog_product_variant || entityId === E.catalog?.catalog_product) {\n return ids.filter((id) => isUuid(id))\n }\n return ids\n}\n\nfunction resolveLabelCandidates(entityId: string, linkSpec: AssignmentLinkSpec | undefined, entitySpecs: Map<string, CustomEntitySpec>): string[] {\n const candidates = new Set<string>()\n const spec = entitySpecs.get(entityId)\n if (spec?.labelField) {\n candidates.add(spec.labelField)\n candidates.add(camelToSnake(spec.labelField))\n }\n for (const field of linkSpec?.labelFields ?? []) {\n candidates.add(field)\n candidates.add(camelToSnake(field))\n }\n DEFAULT_LABEL_FIELDS.forEach((field) => {\n candidates.add(field)\n candidates.add(camelToSnake(field))\n })\n return Array.from(candidates).filter((field) => field.length > 0)\n}\n\nfunction buildLabel(\n record: Record<string, unknown>,\n entityId: string,\n linkSpec: AssignmentLinkSpec | undefined,\n entitySpecs: Map<string, CustomEntitySpec>\n): string | null {\n const candidates = resolveLabelCandidates(entityId, linkSpec, entitySpecs)\n for (const candidate of candidates) {\n const value = readRecordValue(record, candidate)\n if (value) return value\n }\n const fullName = [readRecordValue(record, 'first_name'), readRecordValue(record, 'last_name')]\n .filter((part): part is string => Boolean(part))\n .join(' ')\n .trim()\n if (fullName.length) return fullName\n return null\n}\n\nexport async function resolveAssignmentEnrichments(\n assignments: AttachmentAssignment[],\n opts: { queryEngine?: QueryEngine | null; tenantId: string; organizationId: string },\n): Promise<AssignmentEnrichmentMap> {\n const map: AssignmentEnrichmentMap = new Map()\n if (!assignments.length || !opts.queryEngine) return map\n const entitySpecs = await loadEntitySpecs()\n const grouped = new Map<string, Set<string>>()\n for (const assignment of assignments) {\n if (!assignment || assignment.type === LIBRARY_ENTITY_ID) continue\n const type = assignment.type?.trim()\n const id = assignment.id?.trim()\n if (!type || !id) continue\n if (!grouped.has(type)) grouped.set(type, new Set())\n grouped.get(type)!.add(id)\n }\n if (!grouped.size) return map\n\n const entityLinkSpecs = getEntityLinkSpecs()\n for (const [entityId, idsSet] of grouped.entries()) {\n const ids = filterIdsForEntity(entityId, Array.from(idsSet.values()))\n if (!ids.length) continue\n const linkSpec = entityLinkSpecs[entityId]\n const fields = new Set<string>(['id'])\n const candidates = resolveLabelCandidates(entityId, linkSpec, entitySpecs)\n candidates.forEach((field) => fields.add(field))\n for (const extra of linkSpec?.extraFields ?? []) {\n fields.add(extra)\n fields.add(camelToSnake(extra))\n }\n try {\n const result = await opts.queryEngine.query(entityId as any, {\n fields: Array.from(fields),\n filters: { id: ids.length === 1 ? { $eq: ids[0] } : { $in: ids } },\n tenantId: opts.tenantId,\n organizationId: opts.organizationId,\n page: { pageSize: Math.max(ids.length, 20) },\n })\n for (const record of result.items ?? []) {\n const recordId = normalizeValue((record as Record<string, unknown>).id)\n if (!recordId) continue\n const label = buildLabel(record as Record<string, unknown>, entityId, linkSpec, entitySpecs)\n const href = linkSpec?.buildHref?.(record as Record<string, unknown>) ?? null\n if (label || href) {\n map.set(`${entityId}:${recordId}`, {\n label: label ?? undefined,\n href: href ?? undefined,\n })\n }\n }\n } catch (error) {\n console.warn('[attachments] Failed to resolve assignment details for', entityId, error)\n }\n }\n return map\n}\n\nexport function applyAssignmentEnrichments(\n assignments: AttachmentAssignment[],\n enrichments: AssignmentEnrichmentMap,\n): AttachmentAssignment[] {\n if (!enrichments.size) return assignments\n return assignments.map((assignment) => {\n if (!assignment || !assignment.type || !assignment.id) return assignment\n const key = `${assignment.type}:${assignment.id}`\n const detail = enrichments.get(key)\n if (!detail) return assignment\n const next: AttachmentAssignment = { ...assignment }\n if (!next.label && detail.label) next.label = detail.label\n if (!next.href && detail.href) next.href = detail.href\n return next\n })\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAQ3B,IAAI,wBAAmE;AAEvE,SAAS,qBAAyD;AAChE,MAAI,sBAAuB,QAAO;AAClC,QAAM,IAAI,aAAa;AACvB,QAAM,QAA4C,CAAC;AAEnD,MAAI,EAAE,SAAS,iBAAiB;AAC9B,UAAM,EAAE,QAAQ,eAAe,IAAI;AAAA,MACjC,aAAa,CAAC,SAAS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|
|
20
|
+
[E.catalog?.catalog_product].filter(Boolean)
|
|
21
|
+
);
|
|
22
22
|
const FALLBACK_PARTITION = "privateAttachments";
|
|
23
23
|
function resolveDefaultPartitionCode(entityId) {
|
|
24
24
|
if (!entityId) return FALLBACK_PARTITION;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/attachments/lib/partitions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { AttachmentPartition } from '../data/entities'\nimport { resolveDefaultAttachmentOcrEnabled } from './ocrConfig'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\nimport { E } from '#generated/entities.ids.generated'\n\nexport type AttachmentPartitionSeed = {\n code: string\n title: string\n description?: string | null\n isPublic?: boolean\n}\n\nexport const DEFAULT_ATTACHMENT_PARTITIONS: AttachmentPartitionSeed[] = [\n {\n code: 'productsMedia',\n title: 'Products media',\n description: 'Public media uploaded for catalog products.',\n isPublic: true,\n },\n {\n code: 'privateAttachments',\n title: 'Private attachments',\n description: 'Internal attachments scoped to tenants and organizations.',\n isPublic: false,\n },\n]\n\nconst PRODUCT_MEDIA_ENTITY_IDS = new Set<string>(
|
|
5
|
-
"mappings": "AACA,SAAS,2BAA2B;AACpC,SAAS,0CAA0C;AACnD,SAAS,yBAAyB;AAClC,SAAS,SAAS;AASX,MAAM,gCAA2D;AAAA,EACtE;AAAA,IACE,MAAM;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AACF;AAEA,MAAM,2BAA2B,
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { AttachmentPartition } from '../data/entities'\nimport { resolveDefaultAttachmentOcrEnabled } from './ocrConfig'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\nimport { E } from '#generated/entities.ids.generated'\n\nexport type AttachmentPartitionSeed = {\n code: string\n title: string\n description?: string | null\n isPublic?: boolean\n}\n\nexport const DEFAULT_ATTACHMENT_PARTITIONS: AttachmentPartitionSeed[] = [\n {\n code: 'productsMedia',\n title: 'Products media',\n description: 'Public media uploaded for catalog products.',\n isPublic: true,\n },\n {\n code: 'privateAttachments',\n title: 'Private attachments',\n description: 'Internal attachments scoped to tenants and organizations.',\n isPublic: false,\n },\n]\n\nconst PRODUCT_MEDIA_ENTITY_IDS = new Set<string>(\n [(E as any).catalog?.catalog_product].filter(Boolean) as string[]\n)\n\nconst FALLBACK_PARTITION = 'privateAttachments'\n\nexport function resolveDefaultPartitionCode(entityId: string | null | undefined): string {\n if (!entityId) return FALLBACK_PARTITION\n if (PRODUCT_MEDIA_ENTITY_IDS.has(entityId)) return 'productsMedia'\n return FALLBACK_PARTITION\n}\n\nexport async function ensureDefaultPartitions(em: EntityManager): Promise<void> {\n const repo = em.getRepository(AttachmentPartition)\n const existing = await repo.findAll({ fields: ['code'] })\n const existingCodes = new Set(existing.map((entry) => entry.code))\n const pending = DEFAULT_ATTACHMENT_PARTITIONS.filter((seed) => !existingCodes.has(seed.code))\n if (!pending.length) return\n for (const seed of pending) {\n const record = repo.create({\n code: seed.code,\n title: seed.title,\n description: seed.description ?? null,\n storageDriver: 'local',\n isPublic: seed.isPublic ?? false,\n requiresOcr: resolveDefaultAttachmentOcrEnabled(),\n })\n em.persist(record)\n }\n await em.flush()\n}\n\nexport function sanitizePartitionCode(input: string): string {\n const trimmed = input.trim()\n const normalized = trimmed.replace(/[^a-zA-Z0-9_-]/g, '')\n return normalized\n}\n\nexport function isPartitionSettingsLocked(): boolean {\n const demoModeParsed = parseBooleanToken(process.env.DEMO_MODE ?? '')\n const demoModeEnabled = demoModeParsed === false ? false : true\n const onboardingEnabled = parseBooleanToken(process.env.SELF_SERVICE_ONBOARDING_ENABLED ?? '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,UAAU,MAAM,KAAK;AAC3B,QAAM,aAAa,QAAQ,QAAQ,mBAAmB,EAAE;AACxD,SAAO;AACT;AAEO,SAAS,4BAAqC;AACnD,QAAM,iBAAiB,kBAAkB,QAAQ,IAAI,aAAa,EAAE;AACpE,QAAM,kBAAkB,mBAAmB,QAAQ,QAAQ;AAC3D,QAAM,oBAAoB,kBAAkB,QAAQ,IAAI,mCAAmC,EAAE,MAAM;AACnG,SAAO,mBAAmB;AAC5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/modules/attachments/setup.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup'\n\nexport const setup: ModuleSetupConfig = {\n defaultRoleFeatures: {\n admin: ['attachments.*', 'attachments.view', 'attachments.manage'],\n },\n}\n\nexport default setup\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,QAA2B;AAAA,EACtC,qBAAqB;AAAA,IACnB,OAAO,CAAC,iBAAiB,oBAAoB,oBAAoB;AAAA,EACnE;AACF;AAEA,IAAO,gBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/modules/audit_logs/setup.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ModuleSetupConfig } from '@open-mercato/shared/modules/setup'\n\nexport const setup: ModuleSetupConfig = {\n defaultRoleFeatures: {\n admin: ['audit_logs.*'],\n employee: ['audit_logs.undo_self'],\n },\n}\n\nexport default setup\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,QAA2B;AAAA,EACtC,qBAAqB;AAAA,IACnB,OAAO,CAAC,cAAc;AAAA,IACtB,UAAU,CAAC,sBAAsB;AAAA,EACnC;AACF;AAEA,IAAO,gBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -3,11 +3,6 @@ import { Role, RoleAcl, User, UserRole } from "@open-mercato/core/modules/auth/d
|
|
|
3
3
|
import { Tenant, Organization } from "@open-mercato/core/modules/directory/data/entities";
|
|
4
4
|
import { rebuildHierarchyForTenant } from "@open-mercato/core/modules/directory/lib/hierarchy";
|
|
5
5
|
import { normalizeTenantId } from "./tenantAccess.js";
|
|
6
|
-
import { SalesSettings, SalesDocumentSequence } from "@open-mercato/core/modules/sales/data/entities";
|
|
7
|
-
import {
|
|
8
|
-
DEFAULT_ORDER_NUMBER_FORMAT,
|
|
9
|
-
DEFAULT_QUOTE_NUMBER_FORMAT
|
|
10
|
-
} from "@open-mercato/core/modules/sales/lib/documentNumberTokens";
|
|
11
6
|
import { computeEmailHash } from "@open-mercato/core/modules/auth/lib/emailHash";
|
|
12
7
|
import { isEncryptionDebugEnabled, isTenantDataEncryptionEnabled } from "@open-mercato/shared/lib/encryption/toggles";
|
|
13
8
|
import { EncryptionMap } from "@open-mercato/core/modules/entities/data/entities";
|
|
@@ -242,9 +237,14 @@ async function setupInitialTenant(em, options) {
|
|
|
242
237
|
if (!reusedExistingUser) {
|
|
243
238
|
await rebuildHierarchyForTenant(em, tenantId);
|
|
244
239
|
}
|
|
245
|
-
|
|
240
|
+
const resolvedModules = options.modules ?? tryGetModules();
|
|
241
|
+
await ensureDefaultRoleAcls(em, tenantId, resolvedModules, { includeSuperadminRole });
|
|
246
242
|
await deactivateDemoSuperAdminIfSelfOnboardingEnabled(em);
|
|
247
|
-
|
|
243
|
+
for (const mod of resolvedModules) {
|
|
244
|
+
if (mod.setup?.onTenantCreated) {
|
|
245
|
+
await mod.setup.onTenantCreated({ em, tenantId, organizationId });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
248
|
return {
|
|
249
249
|
tenantId,
|
|
250
250
|
organizationId,
|
|
@@ -263,90 +263,30 @@ async function resolvePasswordHash(input) {
|
|
|
263
263
|
if (input.password) return hash(input.password, 10);
|
|
264
264
|
return null;
|
|
265
265
|
}
|
|
266
|
-
async function ensureDefaultRoleAcls(em, tenantId, options = {}) {
|
|
266
|
+
async function ensureDefaultRoleAcls(em, tenantId, modules, options = {}) {
|
|
267
267
|
const includeSuperadminRole = options.includeSuperadminRole ?? true;
|
|
268
268
|
const roleTenantId = normalizeTenantId(tenantId) ?? null;
|
|
269
269
|
const superadminRole = includeSuperadminRole ? await findRoleByName(em, "superadmin", roleTenantId) : null;
|
|
270
270
|
const adminRole = await findRoleByName(em, "admin", roleTenantId);
|
|
271
271
|
const employeeRole = await findRoleByName(em, "employee", roleTenantId);
|
|
272
|
+
const superadminFeatures = [];
|
|
273
|
+
const adminFeatures = [];
|
|
274
|
+
const employeeFeatures = [];
|
|
275
|
+
for (const mod of modules) {
|
|
276
|
+
const roleFeatures = mod.setup?.defaultRoleFeatures;
|
|
277
|
+
if (!roleFeatures) continue;
|
|
278
|
+
if (roleFeatures.superadmin) superadminFeatures.push(...roleFeatures.superadmin);
|
|
279
|
+
if (roleFeatures.admin) adminFeatures.push(...roleFeatures.admin);
|
|
280
|
+
if (roleFeatures.employee) employeeFeatures.push(...roleFeatures.employee);
|
|
281
|
+
}
|
|
272
282
|
if (includeSuperadminRole && superadminRole) {
|
|
273
|
-
await ensureRoleAclFor(em, superadminRole, tenantId,
|
|
283
|
+
await ensureRoleAclFor(em, superadminRole, tenantId, superadminFeatures, { isSuperAdmin: true });
|
|
274
284
|
}
|
|
275
285
|
if (adminRole) {
|
|
276
|
-
|
|
277
|
-
"auth.*",
|
|
278
|
-
"entities.*",
|
|
279
|
-
"attachments.*",
|
|
280
|
-
"attachments.view",
|
|
281
|
-
"attachments.manage",
|
|
282
|
-
"query_index.*",
|
|
283
|
-
"search.*",
|
|
284
|
-
"vector.*",
|
|
285
|
-
"feature_toggles.*",
|
|
286
|
-
"configs.system_status.view",
|
|
287
|
-
"configs.cache.view",
|
|
288
|
-
"configs.cache.manage",
|
|
289
|
-
"configs.manage",
|
|
290
|
-
"catalog.*",
|
|
291
|
-
"catalog.variants.manage",
|
|
292
|
-
"catalog.pricing.manage",
|
|
293
|
-
"sales.*",
|
|
294
|
-
"audit_logs.*",
|
|
295
|
-
"directory.organizations.view",
|
|
296
|
-
"directory.organizations.manage",
|
|
297
|
-
"customers.*",
|
|
298
|
-
"customers.people.view",
|
|
299
|
-
"customers.people.manage",
|
|
300
|
-
"customers.companies.view",
|
|
301
|
-
"customers.companies.manage",
|
|
302
|
-
"customers.deals.view",
|
|
303
|
-
"customers.deals.manage",
|
|
304
|
-
"dictionaries.view",
|
|
305
|
-
"dictionaries.manage",
|
|
306
|
-
"example.*",
|
|
307
|
-
"dashboards.*",
|
|
308
|
-
"dashboards.admin.assign-widgets",
|
|
309
|
-
"analytics.view",
|
|
310
|
-
"api_keys.*",
|
|
311
|
-
"perspectives.use",
|
|
312
|
-
"perspectives.role_defaults",
|
|
313
|
-
"business_rules.*",
|
|
314
|
-
"workflows.*",
|
|
315
|
-
"currencies.*",
|
|
316
|
-
"staff.*",
|
|
317
|
-
"staff.leave_requests.manage",
|
|
318
|
-
"resources.*",
|
|
319
|
-
"planner.*"
|
|
320
|
-
];
|
|
321
|
-
await ensureRoleAclFor(em, adminRole, tenantId, adminFeatures, { remove: ["directory.organizations.*", "directory.tenants.*"] });
|
|
286
|
+
await ensureRoleAclFor(em, adminRole, tenantId, adminFeatures);
|
|
322
287
|
}
|
|
323
288
|
if (employeeRole) {
|
|
324
|
-
await ensureRoleAclFor(em, employeeRole, tenantId,
|
|
325
|
-
"customers.*",
|
|
326
|
-
"customers.people.view",
|
|
327
|
-
"customers.people.manage",
|
|
328
|
-
"customers.companies.view",
|
|
329
|
-
"customers.companies.manage",
|
|
330
|
-
"vector.*",
|
|
331
|
-
"catalog.*",
|
|
332
|
-
"catalog.variants.manage",
|
|
333
|
-
"catalog.pricing.manage",
|
|
334
|
-
"sales.*",
|
|
335
|
-
"dictionaries.view",
|
|
336
|
-
"example.*",
|
|
337
|
-
"example.widgets.*",
|
|
338
|
-
"dashboards.view",
|
|
339
|
-
"dashboards.configure",
|
|
340
|
-
"analytics.view",
|
|
341
|
-
"audit_logs.undo_self",
|
|
342
|
-
"perspectives.use",
|
|
343
|
-
"staff.leave_requests.send",
|
|
344
|
-
"staff.my_availability.view",
|
|
345
|
-
"staff.my_availability.manage",
|
|
346
|
-
"staff.my_leave_requests.view",
|
|
347
|
-
"staff.my_leave_requests.send",
|
|
348
|
-
"planner.view"
|
|
349
|
-
]);
|
|
289
|
+
await ensureRoleAclFor(em, employeeRole, tenantId, employeeFeatures);
|
|
350
290
|
}
|
|
351
291
|
}
|
|
352
292
|
async function ensureRoleAclFor(em, role, tenantId, features, options = {}) {
|
|
@@ -364,19 +304,8 @@ async function ensureRoleAclFor(em, role, tenantId, features, options = {}) {
|
|
|
364
304
|
}
|
|
365
305
|
const currentFeatures = Array.isArray(existing.featuresJson) ? existing.featuresJson : [];
|
|
366
306
|
const merged = Array.from(/* @__PURE__ */ new Set([...currentFeatures, ...features]));
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
if (removeSet.has(value)) return false;
|
|
370
|
-
for (const entry of removeSet) {
|
|
371
|
-
if (entry.endsWith(".*")) {
|
|
372
|
-
const prefix = entry.slice(0, -1);
|
|
373
|
-
if (value === entry || value.startsWith(prefix)) return false;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return true;
|
|
377
|
-
}) : merged;
|
|
378
|
-
const changed = sanitized.length !== currentFeatures.length || sanitized.some((value, index) => value !== currentFeatures[index]);
|
|
379
|
-
if (changed) existing.featuresJson = sanitized;
|
|
307
|
+
const changed = merged.length !== currentFeatures.length || merged.some((value, index) => value !== currentFeatures[index]);
|
|
308
|
+
if (changed) existing.featuresJson = merged;
|
|
380
309
|
if (options.isSuperAdmin && !existing.isSuperAdmin) {
|
|
381
310
|
existing.isSuperAdmin = true;
|
|
382
311
|
}
|
|
@@ -405,71 +334,12 @@ async function deactivateDemoSuperAdminIfSelfOnboardingEnabled(em) {
|
|
|
405
334
|
console.error("[auth.setup] failed to deactivate demo superadmin user", error);
|
|
406
335
|
}
|
|
407
336
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
tenantId: scope.tenantId,
|
|
415
|
-
organizationId: scope.organizationId
|
|
416
|
-
});
|
|
417
|
-
const exists = await findSettings();
|
|
418
|
-
if (!exists) {
|
|
419
|
-
const settings = repo?.create?.({
|
|
420
|
-
tenantId: scope.tenantId,
|
|
421
|
-
organizationId: scope.organizationId,
|
|
422
|
-
orderNumberFormat: DEFAULT_ORDER_NUMBER_FORMAT,
|
|
423
|
-
quoteNumberFormat: DEFAULT_QUOTE_NUMBER_FORMAT,
|
|
424
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
425
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
426
|
-
}) ?? em.create?.(SalesSettings, {
|
|
427
|
-
tenantId: scope.tenantId,
|
|
428
|
-
organizationId: scope.organizationId,
|
|
429
|
-
orderNumberFormat: DEFAULT_ORDER_NUMBER_FORMAT,
|
|
430
|
-
quoteNumberFormat: DEFAULT_QUOTE_NUMBER_FORMAT,
|
|
431
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
432
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
433
|
-
});
|
|
434
|
-
if (settings && em.persist) {
|
|
435
|
-
em.persist(settings);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
const sequenceRepo = em.getRepository?.(SalesDocumentSequence);
|
|
439
|
-
const kinds = ["order", "quote"];
|
|
440
|
-
for (const kind of kinds) {
|
|
441
|
-
const seq = sequenceRepo?.findOne({
|
|
442
|
-
tenantId: scope.tenantId,
|
|
443
|
-
organizationId: scope.organizationId,
|
|
444
|
-
documentKind: kind
|
|
445
|
-
}) ?? em.findOne?.(SalesDocumentSequence, {
|
|
446
|
-
tenantId: scope.tenantId,
|
|
447
|
-
organizationId: scope.organizationId,
|
|
448
|
-
documentKind: kind
|
|
449
|
-
});
|
|
450
|
-
if (!seq) {
|
|
451
|
-
const entry = sequenceRepo?.create?.({
|
|
452
|
-
tenantId: scope.tenantId,
|
|
453
|
-
organizationId: scope.organizationId,
|
|
454
|
-
documentKind: kind,
|
|
455
|
-
currentValue: 0,
|
|
456
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
457
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
458
|
-
}) ?? em.create?.(SalesDocumentSequence, {
|
|
459
|
-
tenantId: scope.tenantId,
|
|
460
|
-
organizationId: scope.organizationId,
|
|
461
|
-
documentKind: kind,
|
|
462
|
-
currentValue: 0,
|
|
463
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
464
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
465
|
-
});
|
|
466
|
-
if (entry && em.persist) {
|
|
467
|
-
em.persist(entry);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
if (em.flush) {
|
|
472
|
-
await em.flush();
|
|
337
|
+
function tryGetModules() {
|
|
338
|
+
try {
|
|
339
|
+
const { getModules } = require("@open-mercato/shared/lib/modules/registry");
|
|
340
|
+
return getModules();
|
|
341
|
+
} catch {
|
|
342
|
+
return [];
|
|
473
343
|
}
|
|
474
344
|
}
|
|
475
345
|
export {
|