@open-mercato/sync-akeneo 0.11.1-develop.8843.1.b02f9b125d → 0.11.1-develop.8880.1.3acdbfc734
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/sync_akeneo/api/discovery/route.js +2 -1
- package/dist/modules/sync_akeneo/api/discovery/route.js.map +2 -2
- package/dist/modules/sync_akeneo/lib/catalog-importer.js +35 -7
- package/dist/modules/sync_akeneo/lib/catalog-importer.js.map +2 -2
- package/dist/modules/sync_akeneo/lib/client.js +70 -33
- package/dist/modules/sync_akeneo/lib/client.js.map +3 -3
- package/dist/modules/sync_akeneo/lib/preset.js +2 -1
- package/dist/modules/sync_akeneo/lib/preset.js.map +2 -2
- package/dist/modules/sync_akeneo/lib/salesChannelsAvailability.js +10 -0
- package/dist/modules/sync_akeneo/lib/salesChannelsAvailability.js.map +7 -0
- package/package.json +7 -7
- package/src/modules/sync_akeneo/__tests__/catalog-importer.media-limits.test.ts +187 -2
- package/src/modules/sync_akeneo/__tests__/catalog-importer.prices.test.ts +21 -0
- package/src/modules/sync_akeneo/__tests__/client.response-limits.test.ts +1 -0
- package/src/modules/sync_akeneo/__tests__/sales-channels-availability.test.ts +33 -0
- package/src/modules/sync_akeneo/__tests__/sales-optional.test.ts +37 -0
- package/src/modules/sync_akeneo/api/discovery/route.ts +2 -1
- package/src/modules/sync_akeneo/lib/catalog-importer.ts +56 -10
- package/src/modules/sync_akeneo/lib/client.ts +106 -45
- package/src/modules/sync_akeneo/lib/preset.ts +2 -1
- package/src/modules/sync_akeneo/lib/salesChannelsAvailability.ts +8 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
[build:sync-akeneo] found
|
|
1
|
+
[build:sync-akeneo] found 30 entry points
|
|
2
2
|
[build:sync-akeneo] built successfully
|
|
@@ -4,6 +4,7 @@ import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
|
4
4
|
import { findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
5
5
|
import { CatalogPriceKind } from "@open-mercato/core/modules/catalog/data/entities";
|
|
6
6
|
import { SalesChannel } from "@open-mercato/core/modules/sales/data/entities";
|
|
7
|
+
import { areSalesChannelsAvailable } from "../../lib/salesChannelsAvailability.js";
|
|
7
8
|
import { createAkeneoClient } from "../../lib/client.js";
|
|
8
9
|
import { akeneoDiscoveryQuerySchema, akeneoDiscoveryResponseSchema } from "../../data/validators.js";
|
|
9
10
|
const metadata = {
|
|
@@ -27,7 +28,7 @@ async function GET(req) {
|
|
|
27
28
|
const container = await createRequestContainer();
|
|
28
29
|
const credentialsService = container.resolve("integrationCredentialsService");
|
|
29
30
|
const em = container.resolve("em");
|
|
30
|
-
const salesChannelsAvailable = em
|
|
31
|
+
const salesChannelsAvailable = areSalesChannelsAvailable(em);
|
|
31
32
|
const [localChannels, priceKinds] = await Promise.all([
|
|
32
33
|
salesChannelsAvailable ? findWithDecryption(em, SalesChannel, {
|
|
33
34
|
organizationId: auth.orgId,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/sync_akeneo/api/discovery/route.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { CredentialsService } from '@open-mercato/core/modules/integrations/lib/credentials-service'\nimport { CatalogPriceKind } from '@open-mercato/core/modules/catalog/data/entities'\nimport { SalesChannel } from '@open-mercato/core/modules/sales/data/entities'\nimport { createAkeneoClient } from '../../lib/client'\nimport { akeneoDiscoveryQuerySchema, akeneoDiscoveryResponseSchema } from '../../data/validators'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['data_sync.configure'] },\n}\n\nexport const openApi = {\n tags: ['Akeneo'],\n summary: 'Load Akeneo discovery metadata for field mapping',\n}\n\nexport async function GET(req: Request) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ ok: false, message: 'Unauthorized' }, { status: 401 })\n }\n\n const parsed = akeneoDiscoveryQuerySchema.safeParse({\n refresh: new URL(req.url).searchParams.get('refresh') ?? undefined,\n })\n if (!parsed.success) {\n return NextResponse.json({ ok: false, message: 'Invalid query' }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const credentialsService = container.resolve('integrationCredentialsService') as CredentialsService\n const em = container.resolve('em') as EntityManager\n // Audited for #3386 rollout (P3): both orderBy fields are non-encrypted.\n // SalesChannel.name is absent from the sales:sales_channel encryption map\n // (only address/contact fields are encrypted). CatalogPriceKind has no\n // encryption map at all. This is a discovery endpoint with no pagination,\n // so the #3278 two-phase encrypted-sort does not apply. Covered by\n // __tests__/discovery-route.test.ts.\n const salesChannelsAvailable = em
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AAEnC,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,4BAA4B,qCAAqC;AAEnE,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,qBAAqB,EAAE;AACrE;AAEO,MAAM,UAAU;AAAA,EACrB,MAAM,CAAC,QAAQ;AAAA,EACf,SAAS;AACX;AAEA,eAAsB,IAAI,KAAc;AACtC,QAAM,OAAO,MAAM,mBAAmB,GAAG;AACzC,MAAI,CAAC,MAAM,YAAY,CAAC,KAAK,OAAO;AAClC,WAAO,aAAa,KAAK,EAAE,IAAI,OAAO,SAAS,eAAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAClF;AAEA,QAAM,SAAS,2BAA2B,UAAU;AAAA,IAClD,SAAS,IAAI,IAAI,IAAI,GAAG,EAAE,aAAa,IAAI,SAAS,KAAK;AAAA,EAC3D,CAAC;AACD,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,aAAa,KAAK,EAAE,IAAI,OAAO,SAAS,gBAAgB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACnF;AAEA,QAAM,YAAY,MAAM,uBAAuB;AAC/C,QAAM,qBAAqB,UAAU,QAAQ,+BAA+B;AAC5E,QAAM,KAAK,UAAU,QAAQ,IAAI;AAOjC,QAAM,yBAAyB,
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { CredentialsService } from '@open-mercato/core/modules/integrations/lib/credentials-service'\nimport { CatalogPriceKind } from '@open-mercato/core/modules/catalog/data/entities'\nimport { SalesChannel } from '@open-mercato/core/modules/sales/data/entities'\nimport { areSalesChannelsAvailable } from '../../lib/salesChannelsAvailability'\nimport { createAkeneoClient } from '../../lib/client'\nimport { akeneoDiscoveryQuerySchema, akeneoDiscoveryResponseSchema } from '../../data/validators'\n\nexport const metadata = {\n GET: { requireAuth: true, requireFeatures: ['data_sync.configure'] },\n}\n\nexport const openApi = {\n tags: ['Akeneo'],\n summary: 'Load Akeneo discovery metadata for field mapping',\n}\n\nexport async function GET(req: Request) {\n const auth = await getAuthFromRequest(req)\n if (!auth?.tenantId || !auth.orgId) {\n return NextResponse.json({ ok: false, message: 'Unauthorized' }, { status: 401 })\n }\n\n const parsed = akeneoDiscoveryQuerySchema.safeParse({\n refresh: new URL(req.url).searchParams.get('refresh') ?? undefined,\n })\n if (!parsed.success) {\n return NextResponse.json({ ok: false, message: 'Invalid query' }, { status: 400 })\n }\n\n const container = await createRequestContainer()\n const credentialsService = container.resolve('integrationCredentialsService') as CredentialsService\n const em = container.resolve('em') as EntityManager\n // Audited for #3386 rollout (P3): both orderBy fields are non-encrypted.\n // SalesChannel.name is absent from the sales:sales_channel encryption map\n // (only address/contact fields are encrypted). CatalogPriceKind has no\n // encryption map at all. This is a discovery endpoint with no pagination,\n // so the #3278 two-phase encrypted-sort does not apply. Covered by\n // __tests__/discovery-route.test.ts.\n const salesChannelsAvailable = areSalesChannelsAvailable(em)\n const [localChannels, priceKinds] = await Promise.all([\n salesChannelsAvailable\n ? findWithDecryption(em, SalesChannel, {\n organizationId: auth.orgId,\n tenantId: auth.tenantId,\n deletedAt: null,\n isActive: true,\n }, {\n fields: ['code', 'name'],\n orderBy: { name: 'asc' },\n }, {\n organizationId: auth.orgId as string,\n tenantId: auth.tenantId,\n })\n : Promise.resolve<SalesChannel[]>([]),\n findWithDecryption(em, CatalogPriceKind, {\n tenantId: auth.tenantId,\n deletedAt: null,\n isActive: true,\n }, {\n fields: ['code', 'title', 'displayMode'],\n orderBy: { title: 'asc' },\n }, {\n organizationId: auth.orgId as string,\n tenantId: auth.tenantId,\n }),\n ])\n const credentials = await credentialsService.resolve('sync_akeneo', {\n organizationId: auth.orgId as string,\n tenantId: auth.tenantId,\n })\n\n if (!credentials) {\n const payload = akeneoDiscoveryResponseSchema.parse({\n ok: false,\n locales: [],\n channels: [],\n attributes: [],\n families: [],\n familyVariants: [],\n localChannels: localChannels\n .filter((channel) => typeof channel.code === 'string' && channel.code.trim().length > 0)\n .map((channel) => ({ code: String(channel.code), name: channel.name })),\n priceKinds: priceKinds.map((priceKind) => ({\n code: priceKind.code,\n title: priceKind.title,\n displayMode: priceKind.displayMode,\n })),\n message: 'Save Akeneo credentials before loading remote fields.',\n })\n return NextResponse.json(payload, { status: 200 })\n }\n\n try {\n const client = createAkeneoClient(credentials)\n const discovery = await client.collectDiscoveryData()\n const payload = akeneoDiscoveryResponseSchema.parse({\n ok: true,\n locales: discovery.locales,\n channels: discovery.channels,\n attributes: discovery.attributes,\n families: discovery.families,\n familyVariants: discovery.familyVariants,\n localChannels: localChannels\n .filter((channel) => typeof channel.code === 'string' && channel.code.trim().length > 0)\n .map((channel) => ({ code: String(channel.code), name: channel.name })),\n priceKinds: priceKinds.map((priceKind) => ({\n code: priceKind.code,\n title: priceKind.title,\n displayMode: priceKind.displayMode,\n })),\n message: discovery.version ? `Akeneo ${discovery.version}` : undefined,\n })\n return NextResponse.json(payload)\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Failed to load Akeneo metadata'\n const payload = akeneoDiscoveryResponseSchema.parse({\n ok: false,\n locales: [],\n channels: [],\n attributes: [],\n families: [],\n familyVariants: [],\n localChannels: localChannels\n .filter((channel) => typeof channel.code === 'string' && channel.code.trim().length > 0)\n .map((channel) => ({ code: String(channel.code), name: channel.name })),\n priceKinds: priceKinds.map((priceKind) => ({\n code: priceKind.code,\n title: priceKind.title,\n displayMode: priceKind.displayMode,\n })),\n message,\n })\n return NextResponse.json(payload, { status: 200 })\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AAEnC,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAC7B,SAAS,iCAAiC;AAC1C,SAAS,0BAA0B;AACnC,SAAS,4BAA4B,qCAAqC;AAEnE,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM,iBAAiB,CAAC,qBAAqB,EAAE;AACrE;AAEO,MAAM,UAAU;AAAA,EACrB,MAAM,CAAC,QAAQ;AAAA,EACf,SAAS;AACX;AAEA,eAAsB,IAAI,KAAc;AACtC,QAAM,OAAO,MAAM,mBAAmB,GAAG;AACzC,MAAI,CAAC,MAAM,YAAY,CAAC,KAAK,OAAO;AAClC,WAAO,aAAa,KAAK,EAAE,IAAI,OAAO,SAAS,eAAe,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACl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AC;AACD,WAAO,aAAa,KAAK,OAAO;AAAA,EAClC,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;AACzD,UAAM,UAAU,8BAA8B,MAAM;AAAA,MAClD,IAAI;AAAA,MACJ,SAAS,CAAC;AAAA,MACV,UAAU,CAAC;AAAA,MACX,YAAY,CAAC;AAAA,MACb,UAAU,CAAC;AAAA,MACX,gBAAgB,CAAC;AAAA,MACjB,eAAe,cACZ,OAAO,CAAC,YAAY,OAAO,QAAQ,SAAS,YAAY,QAAQ,KAAK,KAAK,EAAE,SAAS,CAAC,EACtF,IAAI,CAAC,aAAa,EAAE,MAAM,OAAO,QAAQ,IAAI,GAAG,MAAM,QAAQ,KAAK,EAAE;AAAA,MACxE,YAAY,WAAW,IAAI,CAAC,eAAe;AAAA,QACzC,MAAM,UAAU;AAAA,QAChB,OAAO,UAAU;AAAA,QACjB,aAAa,UAAU;AAAA,MACzB,EAAE;AAAA,MACF;AAAA,IACF,CAAC;AACD,WAAO,aAAa,KAAK,SAAS,EAAE,QAAQ,IAAI,CAAC;AAAA,EACnD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { randomUUID } from "crypto";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
3
3
|
import { emitCrudSideEffects, setCustomFieldsIfAny } from "@open-mercato/shared/lib/commands/helpers";
|
|
4
4
|
import { loadCustomFieldSnapshot } from "@open-mercato/shared/lib/commands/customFieldSnapshots";
|
|
@@ -26,9 +26,11 @@ import { buildAttachmentFileUrl, buildAttachmentImageUrl, slugifyAttachmentFileN
|
|
|
26
26
|
import {
|
|
27
27
|
isScopedAttachmentUploadError
|
|
28
28
|
} from "@open-mercato/core/modules/attachments/lib/scoped-upload-service";
|
|
29
|
+
import { resolveAttachmentMaxBytes } from "@open-mercato/core/modules/attachments/lib/upload-limits";
|
|
29
30
|
import { attachmentCrudEvents, attachmentCrudIndexer } from "@open-mercato/core/modules/attachments/lib/crud";
|
|
30
31
|
import { emitCatalogQueryIndexEvent } from "@open-mercato/core/modules/catalog/commands/shared";
|
|
31
32
|
import { SalesChannel } from "@open-mercato/core/modules/sales/data/entities";
|
|
33
|
+
import { areSalesChannelsAvailable } from "./salesChannelsAvailability.js";
|
|
32
34
|
import {
|
|
33
35
|
buildAkeneoFieldsetCode,
|
|
34
36
|
buildProductFieldMappings,
|
|
@@ -38,7 +40,9 @@ import {
|
|
|
38
40
|
slugifyAkeneoCode,
|
|
39
41
|
buildDefaultAkeneoMapping
|
|
40
42
|
} from "./shared.js";
|
|
41
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
isAkeneoResponseTooLargeError
|
|
45
|
+
} from "./client.js";
|
|
42
46
|
import { inferAkeneoProductMapping } from "./inference.js";
|
|
43
47
|
import { normalizeMarkdownText } from "./markdown.js";
|
|
44
48
|
import { decimalToString, parseDecimal } from "@open-mercato/shared/lib/decimal";
|
|
@@ -47,6 +51,11 @@ const REJECTED_MEDIA_UPLOAD_CODES = /* @__PURE__ */ new Set([
|
|
|
47
51
|
"max_upload_size",
|
|
48
52
|
"active_content"
|
|
49
53
|
]);
|
|
54
|
+
const MEDIA_REJECTION_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
55
|
+
function isCachedMediaRejection(value) {
|
|
56
|
+
const rejection = safeRecord(value);
|
|
57
|
+
return rejection !== null && typeof rejection.resource === "string" && (rejection.etag === null || typeof rejection.etag === "string") && (rejection.contentType === null || typeof rejection.contentType === "string") && typeof rejection.recheckContentType === "boolean";
|
|
58
|
+
}
|
|
50
59
|
const PRODUCT_ENTITY_ID = "catalog:catalog_product";
|
|
51
60
|
const VARIANT_ENTITY_ID = "catalog:catalog_product_variant";
|
|
52
61
|
function readPreferredAkeneoValue(values, attributeCode, locale, channel) {
|
|
@@ -506,7 +515,7 @@ async function createAkeneoImporter(client, scope) {
|
|
|
506
515
|
const preferredPriceKindCodeCache = /* @__PURE__ */ new Map();
|
|
507
516
|
const attributeOptionLabelCache = /* @__PURE__ */ new Map();
|
|
508
517
|
const defaultProductSettings = buildDefaultAkeneoMapping("products").settings?.products;
|
|
509
|
-
const salesChannelsAvailable = em
|
|
518
|
+
const salesChannelsAvailable = areSalesChannelsAvailable(em);
|
|
510
519
|
let salesChannelsUnavailableReported = false;
|
|
511
520
|
function buildCommandContext() {
|
|
512
521
|
return {
|
|
@@ -1796,7 +1805,7 @@ async function createAkeneoImporter(client, scope) {
|
|
|
1796
1805
|
}
|
|
1797
1806
|
}
|
|
1798
1807
|
}
|
|
1799
|
-
async function recordRejectedMedia(asset, reason) {
|
|
1808
|
+
async function recordRejectedMedia(asset, reason, rejectionKey, revision) {
|
|
1800
1809
|
const integrationLogService = container.resolve("integrationLogService");
|
|
1801
1810
|
await integrationLogService.write({
|
|
1802
1811
|
integrationId: "sync_akeneo",
|
|
@@ -1812,18 +1821,37 @@ async function createAkeneoImporter(client, scope) {
|
|
|
1812
1821
|
reason
|
|
1813
1822
|
}
|
|
1814
1823
|
}, scope);
|
|
1824
|
+
if (rejectionKey && revision) {
|
|
1825
|
+
await cacheService?.set?.(rejectionKey, {
|
|
1826
|
+
...revision,
|
|
1827
|
+
recheckContentType: reason === "active_content" && asset.remote.mimeTypeHint === null
|
|
1828
|
+
}, {
|
|
1829
|
+
ttl: MEDIA_REJECTION_TTL_MS,
|
|
1830
|
+
tags: [`tenant:${scope.tenantId}`, `sync_akeneo:media-rejections:${scope.tenantId}:${scope.organizationId}`]
|
|
1831
|
+
}).catch(() => void 0);
|
|
1832
|
+
}
|
|
1815
1833
|
}
|
|
1816
1834
|
async function upsertAsset(asset) {
|
|
1817
1835
|
const existingAttachmentId = await externalIdMappingService.lookupLocalId("sync_akeneo", "attachment", asset.externalId, scope);
|
|
1818
1836
|
if (existingAttachmentId) return existingAttachmentId;
|
|
1837
|
+
const rejectionKey = cacheService?.get && cacheService.set ? `${scope.tenantId}:${scope.organizationId}:sync_akeneo:media-rejection:${createHash("sha256").update(JSON.stringify([
|
|
1838
|
+
client.credentials.apiUrl,
|
|
1839
|
+
asset.remote.codeOrUrl,
|
|
1840
|
+
asset.remote.fileNameHint,
|
|
1841
|
+
asset.remote.mimeTypeHint,
|
|
1842
|
+
resolveAttachmentMaxBytes()
|
|
1843
|
+
])).digest("hex")}` : null;
|
|
1844
|
+
const cachedRejection = rejectionKey ? await cacheService?.get?.(rejectionKey).catch(() => null) : null;
|
|
1845
|
+
const rejection = isCachedMediaRejection(cachedRejection) ? cachedRejection : null;
|
|
1819
1846
|
let binary;
|
|
1820
1847
|
try {
|
|
1821
|
-
binary = await client.downloadMediaFile(asset.remote.codeOrUrl);
|
|
1848
|
+
binary = await client.downloadMediaFile(asset.remote.codeOrUrl, rejection);
|
|
1822
1849
|
} catch (error) {
|
|
1823
1850
|
if (!isAkeneoResponseTooLargeError(error)) throw error;
|
|
1824
|
-
await recordRejectedMedia(asset, "max_upload_size");
|
|
1851
|
+
await recordRejectedMedia(asset, "max_upload_size", rejectionKey, error.revision);
|
|
1825
1852
|
return null;
|
|
1826
1853
|
}
|
|
1854
|
+
if (!binary) return null;
|
|
1827
1855
|
const fileName = asset.remote.fileNameHint ?? binary.fileName ?? `akeneo-${randomUUID().slice(0, 8)}`;
|
|
1828
1856
|
const uploadService = container.resolve("attachmentScopedUploadService");
|
|
1829
1857
|
let attachment;
|
|
@@ -1840,7 +1868,7 @@ async function createAkeneoImporter(client, scope) {
|
|
|
1840
1868
|
} catch (error) {
|
|
1841
1869
|
if (!isScopedAttachmentUploadError(error)) throw error;
|
|
1842
1870
|
if (REJECTED_MEDIA_UPLOAD_CODES.has(error.code)) {
|
|
1843
|
-
await recordRejectedMedia(asset, error.code);
|
|
1871
|
+
await recordRejectedMedia(asset, error.code, rejectionKey, binary.revision ?? null);
|
|
1844
1872
|
return null;
|
|
1845
1873
|
}
|
|
1846
1874
|
const { translate } = await resolveTranslations();
|