@open-mercato/core 0.11.1-develop.8567.1.a167594505 → 0.11.1-develop.8581.1.535dac92b7
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/.turbo/turbo-build.log +1 -1
- package/dist/modules/attachments/di.js +25 -0
- package/dist/modules/attachments/di.js.map +2 -2
- package/dist/modules/catalog/lib/productScopeReindex.js +1 -1
- package/dist/modules/catalog/lib/productScopeReindex.js.map +2 -2
- package/dist/modules/dictionaries/api/[dictionaryId]/entries/[entryId]/route.js +1 -1
- package/dist/modules/dictionaries/api/[dictionaryId]/entries/[entryId]/route.js.map +2 -2
- package/dist/modules/dictionaries/api/[dictionaryId]/entries/route.js +2 -1
- package/dist/modules/dictionaries/api/[dictionaryId]/entries/route.js.map +2 -2
- package/dist/modules/dictionaries/api/context.js +11 -8
- package/dist/modules/dictionaries/api/context.js.map +2 -2
- package/dist/modules/dictionaries/api/route.js +2 -1
- package/dist/modules/dictionaries/api/route.js.map +2 -2
- package/dist/modules/dictionaries/commands/entries.js +30 -4
- package/dist/modules/dictionaries/commands/entries.js.map +2 -2
- package/dist/modules/entities/api/relations/options.js +85 -5
- package/dist/modules/entities/api/relations/options.js.map +2 -2
- package/dist/modules/payment_gateways/lib/gateway-service.js +1 -1
- package/dist/modules/payment_gateways/lib/gateway-service.js.map +2 -2
- package/dist/modules/query_index/api/purge.js +1 -1
- package/dist/modules/query_index/api/purge.js.map +2 -2
- package/dist/modules/query_index/api/reindex.js +1 -1
- package/dist/modules/query_index/api/reindex.js.map +2 -2
- package/dist/modules/query_index/cli.js +2 -2
- package/dist/modules/query_index/cli.js.map +2 -2
- package/dist/modules/query_index/lib/engine.js +5 -1
- package/dist/modules/query_index/lib/engine.js.map +2 -2
- package/dist/modules/query_index/subscribers/purge.js +3 -3
- package/dist/modules/query_index/subscribers/purge.js.map +2 -2
- package/dist/modules/query_index/subscribers/reindex.js +11 -13
- package/dist/modules/query_index/subscribers/reindex.js.map +2 -2
- package/dist/modules/staff/api/interceptors.js +28 -24
- package/dist/modules/staff/api/interceptors.js.map +2 -2
- package/dist/modules/staff/di.js +23 -0
- package/dist/modules/staff/di.js.map +2 -2
- package/dist/modules/workflows/components/fields/ActivityConfigFields.js +2 -0
- package/dist/modules/workflows/components/fields/ActivityConfigFields.js.map +2 -2
- package/dist/modules/workflows/events.js +13 -0
- package/dist/modules/workflows/events.js.map +2 -2
- package/dist/modules/workflows/lib/activity-executor.js +13 -8
- package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/attachments/di.ts +29 -0
- package/src/modules/catalog/lib/productScopeReindex.ts +1 -1
- package/src/modules/dictionaries/api/[dictionaryId]/entries/[entryId]/route.ts +1 -1
- package/src/modules/dictionaries/api/[dictionaryId]/entries/route.ts +2 -1
- package/src/modules/dictionaries/api/context.ts +11 -8
- package/src/modules/dictionaries/api/route.ts +1 -0
- package/src/modules/dictionaries/commands/entries.ts +40 -3
- package/src/modules/entities/api/relations/options.ts +88 -6
- package/src/modules/payment_gateways/lib/gateway-service.ts +2 -2
- package/src/modules/query_index/api/purge.ts +1 -1
- package/src/modules/query_index/api/reindex.ts +1 -1
- package/src/modules/query_index/cli.ts +2 -2
- package/src/modules/query_index/lib/engine.ts +5 -1
- package/src/modules/query_index/subscribers/purge.ts +5 -4
- package/src/modules/query_index/subscribers/reindex.ts +14 -15
- package/src/modules/staff/api/interceptors.ts +33 -26
- package/src/modules/staff/di.ts +25 -0
- package/src/modules/workflows/components/fields/ActivityConfigFields.tsx +2 -0
- package/src/modules/workflows/events.ts +14 -0
- package/src/modules/workflows/lib/activity-executor.ts +16 -10
|
@@ -7,12 +7,30 @@ import {
|
|
|
7
7
|
ensureDictionaryEntryScope,
|
|
8
8
|
registerDictionaryEntryCommands
|
|
9
9
|
} from "@open-mercato/core/modules/dictionaries/commands/factory";
|
|
10
|
-
import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
|
|
10
|
+
import { CrudHttpError, forbidden } from "@open-mercato/shared/lib/crud/errors";
|
|
11
11
|
import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
12
|
-
|
|
12
|
+
function normalizeScopeId(value) {
|
|
13
|
+
if (typeof value !== "string") return null;
|
|
14
|
+
const trimmed = value.trim();
|
|
15
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
16
|
+
}
|
|
17
|
+
function resolveSelectedOrganizationId(ctx) {
|
|
18
|
+
return normalizeScopeId(ctx.selectedOrganizationId ?? ctx.organizationScope?.selectedId ?? null);
|
|
19
|
+
}
|
|
20
|
+
function resolveContextTenantId(ctx) {
|
|
21
|
+
return normalizeScopeId(ctx.organizationScope?.tenantId ?? ctx.auth?.tenantId ?? null);
|
|
22
|
+
}
|
|
23
|
+
async function ensureDictionary(em, id, ctx) {
|
|
24
|
+
if (ctx.organizationScope?.selectionRejected) {
|
|
25
|
+
throw forbidden();
|
|
26
|
+
}
|
|
27
|
+
const tenantId = resolveContextTenantId(ctx);
|
|
28
|
+
const organizationId = resolveSelectedOrganizationId(ctx);
|
|
13
29
|
const dictionary = await em.findOne(Dictionary, {
|
|
14
30
|
id,
|
|
15
|
-
deletedAt: null
|
|
31
|
+
deletedAt: null,
|
|
32
|
+
...tenantId ? { tenantId } : {},
|
|
33
|
+
...organizationId ? { organizationId } : {}
|
|
16
34
|
});
|
|
17
35
|
if (!dictionary) {
|
|
18
36
|
throw new CrudHttpError(404, { error: "Dictionary not found" });
|
|
@@ -28,16 +46,24 @@ registerDictionaryEntryCommands({
|
|
|
28
46
|
ensureScope: ensureDictionaryEntryScope,
|
|
29
47
|
duplicateError: "An entry with this value already exists.",
|
|
30
48
|
resolveDictionaryForCreate: async ({ em, ctx, parsed }) => {
|
|
31
|
-
const dictionary = await ensureDictionary(em, parsed.dictionaryId);
|
|
49
|
+
const dictionary = await ensureDictionary(em, parsed.dictionaryId, ctx);
|
|
32
50
|
const scope = { tenantId: dictionary.tenantId, organizationId: dictionary.organizationId };
|
|
33
51
|
ensureDictionaryEntryScope(ctx, scope);
|
|
34
52
|
return { dictionary, scope };
|
|
35
53
|
},
|
|
36
54
|
resolveEntry: async ({ em, ctx, id }) => {
|
|
55
|
+
if (ctx.organizationScope?.selectionRejected) {
|
|
56
|
+
throw forbidden();
|
|
57
|
+
}
|
|
37
58
|
const entry = await findOneWithDecryption(em, DictionaryEntry, id, { populate: ["dictionary"] });
|
|
38
59
|
if (!entry) {
|
|
39
60
|
throw new CrudHttpError(404, { error: "Dictionary entry not found" });
|
|
40
61
|
}
|
|
62
|
+
const tenantId = resolveContextTenantId(ctx);
|
|
63
|
+
const selectedOrganizationId = resolveSelectedOrganizationId(ctx);
|
|
64
|
+
if (tenantId && entry.tenantId !== tenantId || selectedOrganizationId && entry.organizationId !== selectedOrganizationId) {
|
|
65
|
+
throw new CrudHttpError(404, { error: "Dictionary entry not found" });
|
|
66
|
+
}
|
|
41
67
|
if (entry.dictionary.deletedAt) {
|
|
42
68
|
throw new CrudHttpError(404, { error: "Dictionary not found" });
|
|
43
69
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/dictionaries/commands/entries.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { Dictionary, DictionaryEntry } from '@open-mercato/core/modules/dictionaries/data/entities'\nimport {\n dictionaryEntryCommandCreateSchema,\n dictionaryEntryCommandUpdateSchema,\n} from '@open-mercato/core/modules/dictionaries/data/validators'\nimport {\n ensureDictionaryEntryScope,\n registerDictionaryEntryCommands,\n} from '@open-mercato/core/modules/dictionaries/commands/factory'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\n\nasync function ensureDictionary(em: EntityManager
|
|
5
|
-
"mappings": "AACA,SAAS,YAAY,uBAAuB;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { Dictionary, DictionaryEntry } from '@open-mercato/core/modules/dictionaries/data/entities'\nimport {\n dictionaryEntryCommandCreateSchema,\n dictionaryEntryCommandUpdateSchema,\n} from '@open-mercato/core/modules/dictionaries/data/validators'\nimport {\n ensureDictionaryEntryScope,\n registerDictionaryEntryCommands,\n} from '@open-mercato/core/modules/dictionaries/commands/factory'\nimport type { CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { CrudHttpError, forbidden } from '@open-mercato/shared/lib/crud/errors'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\n\nfunction normalizeScopeId(value: unknown): string | null {\n if (typeof value !== 'string') return null\n const trimmed = value.trim()\n return trimmed.length > 0 ? trimmed : null\n}\n\nfunction resolveSelectedOrganizationId(ctx: CommandRuntimeContext): string | null {\n return normalizeScopeId(ctx.selectedOrganizationId ?? ctx.organizationScope?.selectedId ?? null)\n}\n\nfunction resolveContextTenantId(ctx: CommandRuntimeContext): string | null {\n return normalizeScopeId(ctx.organizationScope?.tenantId ?? ctx.auth?.tenantId ?? null)\n}\n\nasync function ensureDictionary(\n em: EntityManager,\n id: string,\n ctx: CommandRuntimeContext,\n): Promise<Dictionary> {\n if (ctx.organizationScope?.selectionRejected) {\n throw forbidden()\n }\n const tenantId = resolveContextTenantId(ctx)\n const organizationId = resolveSelectedOrganizationId(ctx)\n const dictionary = await em.findOne(Dictionary, {\n id,\n deletedAt: null,\n ...(tenantId ? { tenantId } : {}),\n ...(organizationId ? { organizationId } : {}),\n })\n if (!dictionary) {\n throw new CrudHttpError(404, { error: 'Dictionary not found' })\n }\n return dictionary\n}\n\nregisterDictionaryEntryCommands({\n commandPrefix: 'dictionaries.entries',\n resourceKind: 'dictionaries.entry',\n translationKeyPrefix: 'dictionaries.entries',\n createSchema: dictionaryEntryCommandCreateSchema,\n updateSchema: dictionaryEntryCommandUpdateSchema,\n ensureScope: ensureDictionaryEntryScope,\n duplicateError: 'An entry with this value already exists.',\n resolveDictionaryForCreate: async ({ em, ctx, parsed }) => {\n const dictionary = await ensureDictionary(em, parsed.dictionaryId, ctx)\n const scope = { tenantId: dictionary.tenantId, organizationId: dictionary.organizationId }\n ensureDictionaryEntryScope(ctx, scope)\n return { dictionary, scope }\n },\n resolveEntry: async ({ em, ctx, id }) => {\n if (ctx.organizationScope?.selectionRejected) {\n throw forbidden()\n }\n const entry = await findOneWithDecryption(em, DictionaryEntry, id, { populate: ['dictionary'] })\n if (!entry) {\n throw new CrudHttpError(404, { error: 'Dictionary entry not found' })\n }\n const tenantId = resolveContextTenantId(ctx)\n const selectedOrganizationId = resolveSelectedOrganizationId(ctx)\n if (\n (tenantId && entry.tenantId !== tenantId) ||\n (selectedOrganizationId && entry.organizationId !== selectedOrganizationId)\n ) {\n throw new CrudHttpError(404, { error: 'Dictionary entry not found' })\n }\n if (entry.dictionary.deletedAt) {\n throw new CrudHttpError(404, { error: 'Dictionary not found' })\n }\n const scope = { tenantId: entry.tenantId, organizationId: entry.organizationId }\n ensureDictionaryEntryScope(ctx, scope)\n return { entry, dictionary: entry.dictionary, scope }\n },\n ensureDictionaryForUndo: async ({ em, snapshot }) => {\n return em.findOne(Dictionary, snapshot.dictionaryId, { filters: false })\n },\n})\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,YAAY,uBAAuB;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,eAAe,iBAAiB;AACzC,SAAS,6BAA6B;AAEtC,SAAS,iBAAiB,OAA+B;AACvD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,UAAU,MAAM,KAAK;AAC3B,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,SAAS,8BAA8B,KAA2C;AAChF,SAAO,iBAAiB,IAAI,0BAA0B,IAAI,mBAAm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,EAAE,OAAO,6BAA6B,CAAC;AAAA,IACtE;AACA,UAAM,WAAW,uBAAuB,GAAG;AAC3C,UAAM,yBAAyB,8BAA8B,GAAG;AAChE,QACG,YAAY,MAAM,aAAa,YAC/B,0BAA0B,MAAM,mBAAmB,wBACpD;AACA,YAAM,IAAI,cAAc,KAAK,EAAE,OAAO,6BAA6B,CAAC;AAAA,IACtE;AACA,QAAI,MAAM,WAAW,WAAW;AAC9B,YAAM,IAAI,cAAc,KAAK,EAAE,OAAO,uBAAuB,CAAC;AAAA,IAChE;AACA,UAAM,QAAQ,EAAE,UAAU,MAAM,UAAU,gBAAgB,MAAM,eAAe;AAC/E,+BAA2B,KAAK,KAAK;AACrC,WAAO,EAAE,OAAO,YAAY,MAAM,YAAY,MAAM;AAAA,EACtD;AAAA,EACA,yBAAyB,OAAO,EAAE,IAAI,SAAS,MAAM;AACnD,WAAO,GAAG,QAAQ,YAAY,SAAS,cAAc,EAAE,SAAS,MAAM,CAAC;AAAA,EACzE;AACF,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,10 +3,13 @@ import { z } from "zod";
|
|
|
3
3
|
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
4
4
|
import { getAuthFromRequest } from "@open-mercato/shared/lib/auth/server";
|
|
5
5
|
import { CustomEntity } from "@open-mercato/core/modules/entities/data/entities";
|
|
6
|
+
import { SortDir } from "@open-mercato/shared/lib/query/types";
|
|
7
|
+
import { relationOptionAccessKey } from "@open-mercato/shared/lib/query/relationOptionAccess";
|
|
8
|
+
import { Organization } from "@open-mercato/core/modules/directory/data/entities";
|
|
6
9
|
import { escapeLikePattern } from "@open-mercato/shared/lib/db/escapeLikePattern";
|
|
7
10
|
import { listEntityMetadata } from "@open-mercato/shared/lib/db/entityMetadata";
|
|
8
11
|
import { resolveRegisteredEntityTableName } from "@open-mercato/shared/lib/query/engine";
|
|
9
|
-
import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
12
|
+
import { findOneWithDecryption, findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
10
13
|
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
11
14
|
import { getModules, resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
12
15
|
import { isCrudHttpError } from "@open-mercato/shared/lib/crud/errors";
|
|
@@ -19,6 +22,13 @@ const metadata = {
|
|
|
19
22
|
GET: { requireAuth: true, requireFeatures: ["entities.definitions.view"] }
|
|
20
23
|
};
|
|
21
24
|
const ALLOWED_ROUTE_CONTEXT_FIELDS = /* @__PURE__ */ new Set(["kind", "entity_id", "product_id"]);
|
|
25
|
+
const RECORD_POLICY_TARGETS = /* @__PURE__ */ new Map([
|
|
26
|
+
["attachments", "attachments:attachment"],
|
|
27
|
+
["staff_time_entries", "staff:staff_time_entry"],
|
|
28
|
+
["staff_time_projects", "staff:staff_time_project"],
|
|
29
|
+
["staff_time_reports", "staff:staff_time_report"],
|
|
30
|
+
["staff_time_tasks", "staff:staff_time_task"]
|
|
31
|
+
]);
|
|
22
32
|
const DEFAULT_LABEL_FIELDS = ["name", "title", "code", "email", "id"];
|
|
23
33
|
const logger = createLogger("entities");
|
|
24
34
|
async function GET(req) {
|
|
@@ -67,6 +77,8 @@ async function GET(req) {
|
|
|
67
77
|
logger.warn("Relation options requested for an unresolvable entity id", { entityId });
|
|
68
78
|
return NextResponse.json({ items: [] });
|
|
69
79
|
}
|
|
80
|
+
const policyTarget = classification.kind === "system" && registeredTable ? RECORD_POLICY_TARGETS.get(registeredTable) : void 0;
|
|
81
|
+
if (policyTarget && policyTarget !== entityId) return forbidden();
|
|
70
82
|
const rbac = container.resolve("rbacService");
|
|
71
83
|
if (classification.kind === "custom" && !await rbac.userHasAllFeatures(
|
|
72
84
|
auth.sub,
|
|
@@ -86,6 +98,8 @@ async function GET(req) {
|
|
|
86
98
|
if (isCrudHttpError(error)) return NextResponse.json(error.body, { status: error.status });
|
|
87
99
|
throw error;
|
|
88
100
|
}
|
|
101
|
+
const resolveAccess = policyTarget ? container.resolve(relationOptionAccessKey(policyTarget), { allowUnregistered: true }) : void 0;
|
|
102
|
+
if (policyTarget && !resolveAccess) return forbidden();
|
|
89
103
|
const customEntity = await findOneWithDecryption(em, CustomEntity, {
|
|
90
104
|
entityId,
|
|
91
105
|
isActive: true,
|
|
@@ -119,15 +133,81 @@ async function GET(req) {
|
|
|
119
133
|
else if (ids.length > 1) filters.id = { $in: ids };
|
|
120
134
|
if (q) filters[labelField] = { $ilike: `%${escapeLikePattern(q)}%` };
|
|
121
135
|
const fields = Array.from(/* @__PURE__ */ new Set(["id", labelField, ...routeContextFields]));
|
|
122
|
-
const
|
|
136
|
+
const pageSize = Math.min(ids.length || 50, 100);
|
|
137
|
+
const queryOptions = {
|
|
123
138
|
tenantId: scope.tenantId,
|
|
124
139
|
...scope.organizationId ? { organizationId: scope.organizationId } : Array.isArray(organizationScope.filterIds) ? { organizationIds: organizationScope.filterIds } : {},
|
|
125
140
|
fields,
|
|
126
141
|
filters,
|
|
127
142
|
...classification.kind === "custom" ? { forceCustomEntityStorage: true } : {},
|
|
128
|
-
page: { page: 1, pageSize
|
|
129
|
-
}
|
|
130
|
-
|
|
143
|
+
page: { page: 1, pageSize }
|
|
144
|
+
};
|
|
145
|
+
let rows;
|
|
146
|
+
if (resolveAccess) {
|
|
147
|
+
const tenantId = scope.tenantId;
|
|
148
|
+
const organizationIds = scope.organizationId ? [scope.organizationId] : organizationScope.filterIds ?? (await findWithDecryption(
|
|
149
|
+
em,
|
|
150
|
+
Organization,
|
|
151
|
+
{ tenant: tenantId, deletedAt: null },
|
|
152
|
+
{ fields: ["id"] },
|
|
153
|
+
{ tenantId }
|
|
154
|
+
)).map((organization) => organization.id);
|
|
155
|
+
rows = [];
|
|
156
|
+
try {
|
|
157
|
+
for (const organizationId of organizationIds) {
|
|
158
|
+
if (requirement && !await rbac.userHasAllFeatures(auth.sub, requirement.view, { tenantId, organizationId })) continue;
|
|
159
|
+
const access = await resolveAccess({ auth: scopedAuth, container, tenantId, organizationId });
|
|
160
|
+
if (!access) continue;
|
|
161
|
+
const scopedOptions = {
|
|
162
|
+
...queryOptions,
|
|
163
|
+
organizationId,
|
|
164
|
+
organizationIds: void 0,
|
|
165
|
+
omitAutomaticTenantOrgScope: true
|
|
166
|
+
};
|
|
167
|
+
const scopeFilters = { tenant_id: tenantId, organization_id: organizationId };
|
|
168
|
+
const remaining = pageSize - rows.length;
|
|
169
|
+
if (access.authorizeIds) {
|
|
170
|
+
const candidateFilters = ids.length ? { id: { $in: ids } } : {};
|
|
171
|
+
let lastId;
|
|
172
|
+
while (rows.length < pageSize) {
|
|
173
|
+
const candidates = await qe.query(entityId, {
|
|
174
|
+
...scopedOptions,
|
|
175
|
+
fields: ["id"],
|
|
176
|
+
filters: { $and: [scopeFilters, candidateFilters, ...lastId ? [{ id: { $gt: lastId } }] : []] },
|
|
177
|
+
sort: [{ field: "id", dir: SortDir.Asc }],
|
|
178
|
+
page: { page: 1, pageSize: 100 }
|
|
179
|
+
});
|
|
180
|
+
if (candidates.items.length === 0) break;
|
|
181
|
+
const authorizedIds = await access.authorizeIds(candidates.items.map(({ id }) => id));
|
|
182
|
+
if (authorizedIds.length) {
|
|
183
|
+
const result = await qe.query(entityId, {
|
|
184
|
+
...scopedOptions,
|
|
185
|
+
filters: { $and: [scopeFilters, filters, { id: { $in: authorizedIds } }] },
|
|
186
|
+
page: { page: 1, pageSize: pageSize - rows.length }
|
|
187
|
+
});
|
|
188
|
+
rows.push(...result.items);
|
|
189
|
+
}
|
|
190
|
+
if (candidates.items.length < 100) break;
|
|
191
|
+
lastId = candidates.items.at(-1)?.id;
|
|
192
|
+
}
|
|
193
|
+
} else if (access.filters) {
|
|
194
|
+
const result = await qe.query(entityId, {
|
|
195
|
+
...scopedOptions,
|
|
196
|
+
filters: { $and: [scopeFilters, filters, access.filters] },
|
|
197
|
+
page: { page: 1, pageSize: remaining }
|
|
198
|
+
});
|
|
199
|
+
rows.push(...result.items);
|
|
200
|
+
}
|
|
201
|
+
if (rows.length >= pageSize) break;
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (isCrudHttpError(error)) return NextResponse.json(error.body, { status: error.status });
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
} else {
|
|
208
|
+
rows = (await qe.query(entityId, queryOptions)).items ?? [];
|
|
209
|
+
}
|
|
210
|
+
const items = rows.map((it) => {
|
|
131
211
|
const routeContext = routeContextFields.reduce((acc, field) => {
|
|
132
212
|
if (it[field] !== void 0) {
|
|
133
213
|
acc[field] = it[field];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/entities/api/relations/options.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { CustomEntity } from '@open-mercato/core/modules/entities/data/entities'\nimport type { CustomEntitySpec } from '@open-mercato/shared/modules/entities'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { QueryEngine } from '@open-mercato/shared/lib/query/types'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { escapeLikePattern } from '@open-mercato/shared/lib/db/escapeLikePattern'\nimport { listEntityMetadata } from '@open-mercato/shared/lib/db/entityMetadata'\nimport { resolveRegisteredEntityTableName } from '@open-mercato/shared/lib/query/engine'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\nimport { getModules, resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { classifyRecordsEntity } from '../../lib/entityClassification'\nimport { assertEntityAclForRequest, resolveEntityAclRequirement } from '../../lib/entityAcl'\nimport type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'\nimport { getSelectedOrganizationFromRequest, resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'\nimport { isAllOrganizationsSelection } from '@open-mercato/core/modules/directory/constants'\nimport { isExplicitlyEmptyOrganizationScope } from '@open-mercato/shared/lib/auth/organizationScope'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['entities.definitions.view'] },\n}\n\nconst ALLOWED_ROUTE_CONTEXT_FIELDS = new Set(['kind', 'entity_id', 'product_id'])\nconst DEFAULT_LABEL_FIELDS = ['name', 'title', 'code', 'email', 'id']\n\nconst logger = createLogger('entities')\n\nexport async function GET(req: Request) {\n const url = new URL(req.url)\n const entityId = url.searchParams.get('entityId') || ''\n const requestedLabelField = url.searchParams.get('labelField') || ''\n const q = url.searchParams.get('q') || ''\n const ids = Array.from(\n new Set(\n (url.searchParams.get('ids') || '')\n .split(',')\n .map((entry) => entry.trim())\n .filter((entry) => entry.length > 0),\n ),\n )\n const routeContextFields = Array.from(\n new Set(\n (url.searchParams.get('routeContextFields') || '')\n .split(',')\n .map((entry) => entry.trim())\n .filter((entry) => ALLOWED_ROUTE_CONTEXT_FIELDS.has(entry)),\n ),\n )\n const { translate } = await resolveTranslations()\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId || (!auth.orgId && !auth.isSuperAdmin)) return NextResponse.json({ error: translate('api.errors.unauthorized', 'Unauthorized') }, { status: 401 })\n if (!entityId) return NextResponse.json({ items: [] })\n const parsed = relationOptionsQuerySchema.safeParse({\n entityId,\n labelField: requestedLabelField,\n q,\n ids: url.searchParams.get('ids') ?? undefined,\n routeContextFields: url.searchParams.get('routeContextFields') ?? undefined,\n })\n if (!parsed.success) return NextResponse.json({ error: translate('api.errors.badRequest', 'Bad request') }, { status: 400 })\n\n const container = await createRequestContainer()\n const qe = container.resolve('queryEngine') as QueryEngine\n const em = container.resolve('em') as EntityManager\n\n const organizationScope = await resolveOrganizationScopeForRequest({ container, auth, request: req })\n const forbidden = () => NextResponse.json({ error: translate('api.errors.forbidden', 'Forbidden') }, { status: 403 })\n if (!organizationScope.tenantId || organizationScope.selectionRejected || isExplicitlyEmptyOrganizationScope(organizationScope)) return forbidden()\n const requestedOrganizationId = getSelectedOrganizationFromRequest(req)?.trim()\n if (requestedOrganizationId && !isAllOrganizationsSelection(requestedOrganizationId) && organizationScope.selectedId !== requestedOrganizationId) return forbidden()\n const scope = { tenantId: organizationScope.tenantId, organizationId: organizationScope.selectedId }\n const scopedAuth = { ...auth, tenantId: scope.tenantId, orgId: scope.organizationId }\n const classification = await classifyRecordsEntity(em, entityId, scope)\n const declared = getModules().flatMap((entry) => entry.customEntities ?? []).find((entry) => entry.id === entityId) as CustomEntitySpec | undefined\n const requirement = resolveEntityAclRequirement(entityId)\n const registeredTable = resolveRegisteredEntityTableName(em, entityId)\n\n if (requirement?.platformOnly || (classification.kind === 'system' && !requirement && !declared)) return forbidden()\n if (classification.kind === 'unknown' || (classification.kind === 'system' && !registeredTable)) {\n logger.warn('Relation options requested for an unresolvable entity id', { entityId })\n return NextResponse.json({ items: [] })\n }\n\n const rbac = container.resolve('rbacService') as RbacService\n if (classification.kind === 'custom' && !(await rbac.userHasAllFeatures(\n auth.sub,\n ['entities.records.view'],\n scope,\n ))) return forbidden()\n\n try {\n await assertEntityAclForRequest({\n auth: scopedAuth,\n entityId,\n action: 'view',\n isCustomEntity: classification.kind === 'custom',\n isRestricted: classification.restricted || declared?.accessRestricted === true,\n rbac,\n })\n } catch (error) {\n if (isCrudHttpError(error)) return NextResponse.json(error.body, { status: error.status })\n throw error\n }\n\n const customEntity = await findOneWithDecryption(em, CustomEntity, {\n entityId,\n isActive: true,\n deletedAt: null,\n $or: [\n { tenantId: scope.tenantId, organizationId: scope.organizationId },\n { tenantId: scope.tenantId, organizationId: null },\n { tenantId: null, organizationId: null },\n ],\n }, { orderBy: { tenantId: 'desc nulls last', organizationId: 'desc nulls last' } }, scope)\n const declaredLabel = declared?.labelField\n const configuredLabel = classification.kind === 'custom' ? customEntity?.labelField : undefined\n const labelCandidates = [declaredLabel, configuredLabel, ...DEFAULT_LABEL_FIELDS]\n .filter((field): field is string => Boolean(field))\n const metadata = registeredTable\n ? listEntityMetadata(em).find((entry) => entry.tableName === registeredTable)\n : undefined\n const columnsByLabel = new Map<string, string>()\n for (const property of Object.values(metadata?.properties ?? {})) {\n if (property.fieldNames?.length !== 1) continue\n const [column] = property.fieldNames\n if (!labelCandidates.includes(property.name) && !labelCandidates.includes(column)) continue\n columnsByLabel.set(property.name, column)\n columnsByLabel.set(column, column)\n }\n const customLabelAliases = classification.kind === 'custom'\n ? labelCandidates.map((field) => field.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toLowerCase())\n : []\n if (requestedLabelField && !labelCandidates.includes(requestedLabelField) &&\n !columnsByLabel.has(requestedLabelField) && !customLabelAliases.includes(requestedLabelField)) {\n return NextResponse.json({ error: translate('api.errors.badRequest', 'Bad request') }, { status: 400 })\n }\n const systemLabel = [requestedLabelField, ...labelCandidates]\n .map((field) => columnsByLabel.get(field))\n .find((column) => column !== undefined)\n const labelField = classification.kind === 'custom'\n ? requestedLabelField || configuredLabel || declaredLabel || 'id'\n : systemLabel ?? 'id'\n const filters: Record<string, unknown> = {}\n if (ids.length === 1) filters.id = ids[0]\n else if (ids.length > 1) filters.id = { $in: ids }\n if (q) filters[labelField] = { $ilike: `%${escapeLikePattern(q)}%` }\n const fields = Array.from(new Set(['id', labelField, ...routeContextFields]))\n const res = await qe.query<Record<string, unknown>>(entityId, {\n tenantId: scope.tenantId,\n ...(scope.organizationId\n ? { organizationId: scope.organizationId }\n : Array.isArray(organizationScope.filterIds) ? { organizationIds: organizationScope.filterIds } : {}),\n fields,\n filters,\n ...(classification.kind === 'custom' ? { forceCustomEntityStorage: true } : {}),\n page: { page: 1, pageSize: Math.min(ids.length || 50, 100) },\n })\n const items = (res.items || []).map((it: Record<string, unknown>) => {\n const routeContext = routeContextFields.reduce<Record<string, unknown>>((acc, field) => {\n if (it[field] !== undefined) {\n acc[field] = it[field]\n }\n return acc\n }, {})\n return {\n value: String(it.id),\n label: String(it[labelField] ?? it.id),\n ...(Object.keys(routeContext).length > 0 ? { routeContext } : {}),\n }\n })\n return NextResponse.json({ items })\n}\n\nconst relationOptionsQuerySchema = z.object({\n entityId: z.string().min(1),\n labelField: z.string().optional(),\n q: z.string().optional(),\n ids: z.string().optional(),\n routeContextFields: z.string().optional(),\n})\n\nconst relationOptionsResponseSchema = z.object({\n items: z.array(\n z.object({\n value: z.string(),\n label: z.string(),\n routeContext: z.record(z.string(), z.unknown()).optional(),\n })\n ),\n})\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Entities',\n summary: 'Relation options lookup',\n methods: {\n GET: {\n summary: 'List relation options',\n description: 'Returns up to 100 option entries for populating relation dropdowns, requiring target read access and accepting only declared or fixed safe label fields. An entityId that matches neither an active custom entity nor a registered ORM entity yields an empty option list.',\n query: relationOptionsQuerySchema,\n responses: [\n {\n status: 200,\n description: 'Option list',\n schema: relationOptionsResponseSchema,\n },\n {\n status: 400,\n description: 'Unsafe label selector',\n schema: z.object({ error: z.string() }),\n },\n {\n status: 403,\n description: 'Target entity access denied',\n schema: z.object({ error: z.string() }),\n },\n {\n status: 401,\n description: 'Missing authentication',\n schema: z.object({ error: z.string() }),\n },\n ],\n },\n },\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { CustomEntity } from '@open-mercato/core/modules/entities/data/entities'\nimport type { CustomEntitySpec } from '@open-mercato/shared/modules/entities'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { SortDir, type QueryEngine, type QueryOptions } from '@open-mercato/shared/lib/query/types'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { relationOptionAccessKey, type RelationOptionAccess } from '@open-mercato/shared/lib/query/relationOptionAccess'\nimport { Organization } from '@open-mercato/core/modules/directory/data/entities'\nimport { escapeLikePattern } from '@open-mercato/shared/lib/db/escapeLikePattern'\nimport { listEntityMetadata } from '@open-mercato/shared/lib/db/entityMetadata'\nimport { resolveRegisteredEntityTableName } from '@open-mercato/shared/lib/query/engine'\nimport { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\nimport { getModules, resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { classifyRecordsEntity } from '../../lib/entityClassification'\nimport { assertEntityAclForRequest, resolveEntityAclRequirement } from '../../lib/entityAcl'\nimport type { RbacService } from '@open-mercato/core/modules/auth/services/rbacService'\nimport { getSelectedOrganizationFromRequest, resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'\nimport { isAllOrganizationsSelection } from '@open-mercato/core/modules/directory/constants'\nimport { isExplicitlyEmptyOrganizationScope } from '@open-mercato/shared/lib/auth/organizationScope'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['entities.definitions.view'] },\n}\n\nconst ALLOWED_ROUTE_CONTEXT_FIELDS = new Set(['kind', 'entity_id', 'product_id'])\nconst RECORD_POLICY_TARGETS = new Map([\n ['attachments', 'attachments:attachment'],\n ['staff_time_entries', 'staff:staff_time_entry'],\n ['staff_time_projects', 'staff:staff_time_project'],\n ['staff_time_reports', 'staff:staff_time_report'],\n ['staff_time_tasks', 'staff:staff_time_task'],\n])\nconst DEFAULT_LABEL_FIELDS = ['name', 'title', 'code', 'email', 'id']\n\nconst logger = createLogger('entities')\n\nexport async function GET(req: Request) {\n const url = new URL(req.url)\n const entityId = url.searchParams.get('entityId') || ''\n const requestedLabelField = url.searchParams.get('labelField') || ''\n const q = url.searchParams.get('q') || ''\n const ids = Array.from(\n new Set(\n (url.searchParams.get('ids') || '')\n .split(',')\n .map((entry) => entry.trim())\n .filter((entry) => entry.length > 0),\n ),\n )\n const routeContextFields = Array.from(\n new Set(\n (url.searchParams.get('routeContextFields') || '')\n .split(',')\n .map((entry) => entry.trim())\n .filter((entry) => ALLOWED_ROUTE_CONTEXT_FIELDS.has(entry)),\n ),\n )\n const { translate } = await resolveTranslations()\n const auth = await getAuthFromRequest(req)\n if (!auth || !auth.tenantId || (!auth.orgId && !auth.isSuperAdmin)) return NextResponse.json({ error: translate('api.errors.unauthorized', 'Unauthorized') }, { status: 401 })\n if (!entityId) return NextResponse.json({ items: [] })\n const parsed = relationOptionsQuerySchema.safeParse({\n entityId,\n labelField: requestedLabelField,\n q,\n ids: url.searchParams.get('ids') ?? undefined,\n routeContextFields: url.searchParams.get('routeContextFields') ?? undefined,\n })\n if (!parsed.success) return NextResponse.json({ error: translate('api.errors.badRequest', 'Bad request') }, { status: 400 })\n\n const container = await createRequestContainer()\n const qe = container.resolve('queryEngine') as QueryEngine\n const em = container.resolve('em') as EntityManager\n\n const organizationScope = await resolveOrganizationScopeForRequest({ container, auth, request: req })\n const forbidden = () => NextResponse.json({ error: translate('api.errors.forbidden', 'Forbidden') }, { status: 403 })\n if (!organizationScope.tenantId || organizationScope.selectionRejected || isExplicitlyEmptyOrganizationScope(organizationScope)) return forbidden()\n const requestedOrganizationId = getSelectedOrganizationFromRequest(req)?.trim()\n if (requestedOrganizationId && !isAllOrganizationsSelection(requestedOrganizationId) && organizationScope.selectedId !== requestedOrganizationId) return forbidden()\n const scope = { tenantId: organizationScope.tenantId, organizationId: organizationScope.selectedId }\n const scopedAuth = { ...auth, tenantId: scope.tenantId, orgId: scope.organizationId }\n const classification = await classifyRecordsEntity(em, entityId, scope)\n const declared = getModules().flatMap((entry) => entry.customEntities ?? []).find((entry) => entry.id === entityId) as CustomEntitySpec | undefined\n const requirement = resolveEntityAclRequirement(entityId)\n const registeredTable = resolveRegisteredEntityTableName(em, entityId)\n\n if (requirement?.platformOnly || (classification.kind === 'system' && !requirement && !declared)) return forbidden()\n if (classification.kind === 'unknown' || (classification.kind === 'system' && !registeredTable)) {\n logger.warn('Relation options requested for an unresolvable entity id', { entityId })\n return NextResponse.json({ items: [] })\n }\n const policyTarget = classification.kind === 'system' && registeredTable\n ? RECORD_POLICY_TARGETS.get(registeredTable)\n : undefined\n if (policyTarget && policyTarget !== entityId) return forbidden()\n\n const rbac = container.resolve('rbacService') as RbacService\n if (classification.kind === 'custom' && !(await rbac.userHasAllFeatures(\n auth.sub,\n ['entities.records.view'],\n scope,\n ))) return forbidden()\n\n try {\n await assertEntityAclForRequest({\n auth: scopedAuth,\n entityId,\n action: 'view',\n isCustomEntity: classification.kind === 'custom',\n isRestricted: classification.restricted || declared?.accessRestricted === true,\n rbac,\n })\n } catch (error) {\n if (isCrudHttpError(error)) return NextResponse.json(error.body, { status: error.status })\n throw error\n }\n\n const resolveAccess = policyTarget\n ? container.resolve<RelationOptionAccess>(relationOptionAccessKey(policyTarget), { allowUnregistered: true })\n : undefined\n if (policyTarget && !resolveAccess) return forbidden()\n\n const customEntity = await findOneWithDecryption(em, CustomEntity, {\n entityId,\n isActive: true,\n deletedAt: null,\n $or: [\n { tenantId: scope.tenantId, organizationId: scope.organizationId },\n { tenantId: scope.tenantId, organizationId: null },\n { tenantId: null, organizationId: null },\n ],\n }, { orderBy: { tenantId: 'desc nulls last', organizationId: 'desc nulls last' } }, scope)\n const declaredLabel = declared?.labelField\n const configuredLabel = classification.kind === 'custom' ? customEntity?.labelField : undefined\n const labelCandidates = [declaredLabel, configuredLabel, ...DEFAULT_LABEL_FIELDS]\n .filter((field): field is string => Boolean(field))\n const metadata = registeredTable\n ? listEntityMetadata(em).find((entry) => entry.tableName === registeredTable)\n : undefined\n const columnsByLabel = new Map<string, string>()\n for (const property of Object.values(metadata?.properties ?? {})) {\n if (property.fieldNames?.length !== 1) continue\n const [column] = property.fieldNames\n if (!labelCandidates.includes(property.name) && !labelCandidates.includes(column)) continue\n columnsByLabel.set(property.name, column)\n columnsByLabel.set(column, column)\n }\n const customLabelAliases = classification.kind === 'custom'\n ? labelCandidates.map((field) => field.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toLowerCase())\n : []\n if (requestedLabelField && !labelCandidates.includes(requestedLabelField) &&\n !columnsByLabel.has(requestedLabelField) && !customLabelAliases.includes(requestedLabelField)) {\n return NextResponse.json({ error: translate('api.errors.badRequest', 'Bad request') }, { status: 400 })\n }\n const systemLabel = [requestedLabelField, ...labelCandidates]\n .map((field) => columnsByLabel.get(field))\n .find((column) => column !== undefined)\n const labelField = classification.kind === 'custom'\n ? requestedLabelField || configuredLabel || declaredLabel || 'id'\n : systemLabel ?? 'id'\n const filters: Record<string, unknown> = {}\n if (ids.length === 1) filters.id = ids[0]\n else if (ids.length > 1) filters.id = { $in: ids }\n if (q) filters[labelField] = { $ilike: `%${escapeLikePattern(q)}%` }\n const fields = Array.from(new Set(['id', labelField, ...routeContextFields]))\n const pageSize = Math.min(ids.length || 50, 100)\n const queryOptions: QueryOptions = {\n tenantId: scope.tenantId,\n ...(scope.organizationId\n ? { organizationId: scope.organizationId }\n : Array.isArray(organizationScope.filterIds) ? { organizationIds: organizationScope.filterIds } : {}),\n fields,\n filters,\n ...(classification.kind === 'custom' ? { forceCustomEntityStorage: true } : {}),\n page: { page: 1, pageSize },\n }\n let rows: Record<string, unknown>[]\n if (resolveAccess) {\n const tenantId = scope.tenantId\n const organizationIds = scope.organizationId\n ? [scope.organizationId]\n : organizationScope.filterIds ?? (await findWithDecryption(\n em, Organization, { tenant: tenantId, deletedAt: null }, { fields: ['id'] }, { tenantId },\n )).map((organization) => organization.id)\n rows = []\n try {\n for (const organizationId of organizationIds) {\n if (requirement && !(await rbac.userHasAllFeatures(auth.sub, requirement.view, { tenantId, organizationId }))) continue\n const access = await resolveAccess({ auth: scopedAuth, container, tenantId, organizationId })\n if (!access) continue\n const scopedOptions = {\n ...queryOptions,\n organizationId,\n organizationIds: undefined,\n omitAutomaticTenantOrgScope: true,\n }\n const scopeFilters = { tenant_id: tenantId, organization_id: organizationId }\n const remaining = pageSize - rows.length\n if (access.authorizeIds) {\n const candidateFilters = ids.length ? { id: { $in: ids } } : {}\n let lastId: string | undefined\n while (rows.length < pageSize) {\n const candidates = await qe.query<{ id: string }>(entityId, {\n ...scopedOptions,\n fields: ['id'],\n filters: { $and: [scopeFilters, candidateFilters, ...(lastId ? [{ id: { $gt: lastId } }] : [])] },\n sort: [{ field: 'id', dir: SortDir.Asc }],\n page: { page: 1, pageSize: 100 },\n })\n if (candidates.items.length === 0) break\n const authorizedIds = await access.authorizeIds(candidates.items.map(({ id }) => id))\n if (authorizedIds.length) {\n const result = await qe.query<Record<string, unknown>>(entityId, {\n ...scopedOptions,\n filters: { $and: [scopeFilters, filters, { id: { $in: authorizedIds } }] },\n page: { page: 1, pageSize: pageSize - rows.length },\n })\n rows.push(...result.items)\n }\n if (candidates.items.length < 100) break\n lastId = candidates.items.at(-1)?.id\n }\n } else if (access.filters) {\n const result = await qe.query<Record<string, unknown>>(entityId, {\n ...scopedOptions,\n filters: { $and: [scopeFilters, filters, access.filters] },\n page: { page: 1, pageSize: remaining },\n })\n rows.push(...result.items)\n }\n if (rows.length >= pageSize) break\n }\n } catch (error) {\n if (isCrudHttpError(error)) return NextResponse.json(error.body, { status: error.status })\n throw error\n }\n } else {\n rows = (await qe.query<Record<string, unknown>>(entityId, queryOptions)).items ?? []\n }\n const items = rows.map((it) => {\n const routeContext = routeContextFields.reduce<Record<string, unknown>>((acc, field) => {\n if (it[field] !== undefined) {\n acc[field] = it[field]\n }\n return acc\n }, {})\n return {\n value: String(it.id),\n label: String(it[labelField] ?? it.id),\n ...(Object.keys(routeContext).length > 0 ? { routeContext } : {}),\n }\n })\n return NextResponse.json({ items })\n}\n\nconst relationOptionsQuerySchema = z.object({\n entityId: z.string().min(1),\n labelField: z.string().optional(),\n q: z.string().optional(),\n ids: z.string().optional(),\n routeContextFields: z.string().optional(),\n})\n\nconst relationOptionsResponseSchema = z.object({\n items: z.array(\n z.object({\n value: z.string(),\n label: z.string(),\n routeContext: z.record(z.string(), z.unknown()).optional(),\n })\n ),\n})\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Entities',\n summary: 'Relation options lookup',\n methods: {\n GET: {\n summary: 'List relation options',\n description: 'Returns up to 100 option entries for populating relation dropdowns, requiring target read access and accepting only declared or fixed safe label fields. An entityId that matches neither an active custom entity nor a registered ORM entity yields an empty option list.',\n query: relationOptionsQuerySchema,\n responses: [\n {\n status: 200,\n description: 'Option list',\n schema: relationOptionsResponseSchema,\n },\n {\n status: 400,\n description: 'Unsafe label selector',\n schema: z.object({ error: z.string() }),\n },\n {\n status: 403,\n description: 'Target entity access denied',\n schema: z.object({ error: z.string() }),\n },\n {\n status: 401,\n description: 'Missing authentication',\n schema: z.object({ error: z.string() }),\n },\n ],\n },\n },\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAClB,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAG7B,SAAS,eAAoD;AAE7D,SAAS,+BAA0D;AACnE,SAAS,oBAAoB;AAC7B,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AACnC,SAAS,wCAAwC;AACjD,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,oBAAoB;AAC7B,SAAS,YAAY,2BAA2B;AAChD,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,2BAA2B,mCAAmC;AAEvE,SAAS,oCAAoC,0CAA0C;AACvF,SAAS,mCAAmC;AAC5C,SAAS,0CAA0C;AAE5C,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,2BAA2B,EAAE;AAC3E;AAEA,MAAM,+BAA+B,oBAAI,IAAI,CAAC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I,CAAC;AAAA,EAC1B,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,GAAG,EAAE,OAAO,EAAE,SAAS;AAAA,EACvB,KAAK,EAAE,OAAO,EAAE,SAAS;AAAA,EACzB,oBAAoB,EAAE,OAAO,EAAE,SAAS;AAC1C,CAAC;AAED,MAAM,gCAAgC,EAAE,OAAO;AAAA,EAC7C,OAAO,EAAE;AAAA,IACP,EAAE,OAAO;AAAA,MACP,OAAO,EAAE,OAAO;AAAA,MAChB,OAAO,EAAE,OAAO;AAAA,MAChB,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,IAC3D,CAAC;AAAA,EACH;AACF,CAAC;AAEM,MAAM,UAA2B;AAAA,EACtC,KAAK;AAAA,EACL,SAAS;AAAA,EACT,SAAS;AAAA,IACP,KAAK;AAAA,MACH,SAAS;AAAA,MACT,aAAa;AAAA,MACb,OAAO;AAAA,MACP,WAAW;AAAA,QACT;AAAA,UACE,QAAQ;AAAA,UACR,aAAa;AAAA,UACb,QAAQ;AAAA,QACV;AAAA,QACA;AAAA,UACE,QAAQ;AAAA,UACR,aAAa;AAAA,UACb,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAAA,QACxC;AAAA,QACA;AAAA,UACE,QAAQ;AAAA,UACR,aAAa;AAAA,UACb,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAAA,QACxC;AAAA,QACA;AAAA,UACE,QAAQ;AAAA,UACR,aAAa;AAAA,UACb,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["metadata"]
|
|
7
7
|
}
|
|
@@ -114,7 +114,7 @@ function createPaymentGatewayService(deps) {
|
|
|
114
114
|
};
|
|
115
115
|
const eventId = eventMap[status];
|
|
116
116
|
if (!eventId) return;
|
|
117
|
-
await emitPaymentGatewayEvent(eventId, payload);
|
|
117
|
+
await emitPaymentGatewayEvent(eventId, payload, { tenantId: payload.tenantId, organizationId: payload.organizationId });
|
|
118
118
|
}
|
|
119
119
|
async function writeTransactionLog(providerKey, scope, transactionId, level, message, payload, code) {
|
|
120
120
|
if (!integrationLogService) return;
|