feat(translation,fulfillment,customer,product,region,tax,core-flows,medusa,types): Implement dynamic translation settings management (#14536)
* Add is_active field to translation_settings model * Types * Workflows * Api layer * Tests * Add changeset * Add comment * Hook to create or deactivate translatable entities on startup * Cleanup old code * Configure translatable option for core entities * Validation step and snake case correction * Cleanup * Tests * Comment in PR * Update changeset * Mock DmlEntity.getTranslatableEntities * Move validation to module service layer * Remove validation from remaining workflow * Return object directly * Type improvements * Remove .only from tests * Apply snakeCase * Fix tests * Fix tests * Remove unnecessary map and use set instead * Fix tests * Comments * Include translatable product properties * Avoid race condition in translations tests * Update test
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
import { CreateTranslationSettingsDTO } from "@medusajs/types"
|
||||
|
||||
export const createTranslationSettingsStepId = "create-translation-settings"
|
||||
|
||||
export type CreateTranslationSettingsStepInput =
|
||||
| CreateTranslationSettingsDTO
|
||||
| CreateTranslationSettingsDTO[]
|
||||
|
||||
export const createTranslationSettingsStep = createStep(
|
||||
createTranslationSettingsStepId,
|
||||
async (data: CreateTranslationSettingsStepInput, { container }) => {
|
||||
const service = container.resolve(Modules.TRANSLATION)
|
||||
|
||||
const normalizedInput = Array.isArray(data) ? data : [data]
|
||||
|
||||
const created = await service.createTranslationSettings(normalizedInput)
|
||||
|
||||
return new StepResponse(
|
||||
created,
|
||||
created.map((translationSettings) => translationSettings.id)
|
||||
)
|
||||
},
|
||||
async (createdIds, { container }) => {
|
||||
if (!createdIds?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve(Modules.TRANSLATION)
|
||||
|
||||
await service.deleteTranslationSettings(createdIds)
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
export const deleteTranslationSettingsStepId = "delete-translation-settings"
|
||||
|
||||
export const deleteTranslationSettingsStep = createStep(
|
||||
deleteTranslationSettingsStepId,
|
||||
async (data: string[], { container }) => {
|
||||
const service = container.resolve(Modules.TRANSLATION)
|
||||
|
||||
const previous = await service.listTranslationSettings({
|
||||
id: data,
|
||||
})
|
||||
|
||||
await service.deleteTranslationSettings(data)
|
||||
|
||||
return new StepResponse(void 0, previous)
|
||||
},
|
||||
async (previous, { container }) => {
|
||||
if (!previous?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve(Modules.TRANSLATION)
|
||||
|
||||
await service.createTranslationSettings(previous)
|
||||
}
|
||||
)
|
||||
@@ -2,3 +2,6 @@ export * from "./create-translations"
|
||||
export * from "./delete-translations"
|
||||
export * from "./update-translations"
|
||||
export * from "./validate-translations"
|
||||
export * from "./create-translation-settings"
|
||||
export * from "./update-translation-settings"
|
||||
export * from "./delete-translation-settings"
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
import { UpdateTranslationSettingsDTO } from "@medusajs/types"
|
||||
|
||||
export const updateTranslationSettingsStepId = "update-translation-settings"
|
||||
|
||||
export type UpdateTranslationSettingsStepInput =
|
||||
| UpdateTranslationSettingsDTO
|
||||
| UpdateTranslationSettingsDTO[]
|
||||
|
||||
export const updateTranslationSettingsStep = createStep(
|
||||
updateTranslationSettingsStepId,
|
||||
async (data: UpdateTranslationSettingsStepInput, { container }) => {
|
||||
const service = container.resolve(Modules.TRANSLATION)
|
||||
|
||||
const normalizedInput = Array.isArray(data) ? data : [data]
|
||||
|
||||
const previous = await service.listTranslationSettings({
|
||||
id: normalizedInput.map((d) => d.id),
|
||||
})
|
||||
|
||||
const updated = await service.updateTranslationSettings(normalizedInput)
|
||||
|
||||
return new StepResponse(updated, previous)
|
||||
},
|
||||
async (previous, { container }) => {
|
||||
if (!previous?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve(Modules.TRANSLATION)
|
||||
|
||||
await service.updateTranslationSettings(previous)
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import {
|
||||
UpdateTranslationSettingsDTO,
|
||||
CreateTranslationSettingsDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
createTranslationSettingsStep,
|
||||
deleteTranslationSettingsStep,
|
||||
updateTranslationSettingsStep,
|
||||
} from "../steps"
|
||||
|
||||
export const batchTranslationSettingsWorkflowId = "batch-translation-settings"
|
||||
|
||||
export interface BatchTranslationSettingsWorkflowInput {
|
||||
create: CreateTranslationSettingsDTO[]
|
||||
update: UpdateTranslationSettingsDTO[]
|
||||
delete: string[]
|
||||
}
|
||||
|
||||
export const batchTranslationSettingsWorkflow = createWorkflow(
|
||||
batchTranslationSettingsWorkflowId,
|
||||
(input: BatchTranslationSettingsWorkflowInput) => {
|
||||
const [created, updated, deleted] = parallelize(
|
||||
createTranslationSettingsStep(input.create),
|
||||
updateTranslationSettingsStep(input.update),
|
||||
deleteTranslationSettingsStep(input.delete)
|
||||
)
|
||||
|
||||
return new WorkflowResponse({ created, updated, deleted })
|
||||
}
|
||||
)
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { emitEventStep } from "../../common/steps/emit-event"
|
||||
import { createTranslationsStep } from "../steps"
|
||||
import { validateTranslationsStep } from "../steps"
|
||||
import { TranslationWorkflowEvents } from "@medusajs/framework/utils"
|
||||
|
||||
/**
|
||||
@@ -27,7 +26,7 @@ export const createTranslationsWorkflowId = "create-translations"
|
||||
*
|
||||
* You can use this workflow within your own customizations or custom workflows, allowing you
|
||||
* to create translations in your custom flows.
|
||||
*
|
||||
*
|
||||
* @since 2.12.3
|
||||
* @featureFlag translation
|
||||
*
|
||||
@@ -55,7 +54,6 @@ export const createTranslationsWorkflow = createWorkflow(
|
||||
(
|
||||
input: WorkflowData<CreateTranslationsWorkflowInput>
|
||||
): WorkflowResponse<TranslationDTO[]> => {
|
||||
validateTranslationsStep(input.translations)
|
||||
const translations = createTranslationsStep(input.translations)
|
||||
|
||||
const translationIdEvents = transform(
|
||||
|
||||
@@ -2,3 +2,4 @@ export * from "./create-translations"
|
||||
export * from "./delete-translations"
|
||||
export * from "./update-translations"
|
||||
export * from "./batch-translations"
|
||||
export * from "./batch-translation-settings"
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { emitEventStep } from "../../common/steps/emit-event"
|
||||
import { updateTranslationsStep, UpdateTranslationsStepInput } from "../steps"
|
||||
import { validateTranslationsStep } from "../steps"
|
||||
import { TranslationWorkflowEvents } from "@medusajs/framework/utils"
|
||||
|
||||
/**
|
||||
@@ -22,13 +21,13 @@ export const updateTranslationsWorkflowId = "update-translations"
|
||||
*
|
||||
* You can use this workflow within your own customizations or custom workflows, allowing you
|
||||
* to update translations in your custom flows.
|
||||
*
|
||||
*
|
||||
* @since 2.12.3
|
||||
* @featureFlag translation
|
||||
*
|
||||
* @example
|
||||
* To update translations by their IDs:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* const { result } = await updateTranslationsWorkflow(container)
|
||||
* .run({
|
||||
@@ -61,11 +60,6 @@ export const updateTranslationsWorkflow = createWorkflow(
|
||||
(
|
||||
input: WorkflowData<UpdateTranslationsWorkflowInput>
|
||||
): WorkflowResponse<TranslationDTO[]> => {
|
||||
const validateInput = transform(input, (input) => {
|
||||
return "translations" in input ? input.translations : [input.update]
|
||||
})
|
||||
validateTranslationsStep(validateInput)
|
||||
|
||||
const translations = updateTranslationsStep(input)
|
||||
|
||||
const translationIdEvents = transform(
|
||||
|
||||
@@ -6,7 +6,7 @@ export interface AdminTranslation {
|
||||
|
||||
/**
|
||||
* The ID of the entity being translated.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "prod_123"
|
||||
*/
|
||||
@@ -14,7 +14,7 @@ export interface AdminTranslation {
|
||||
|
||||
/**
|
||||
* The name of the table that the translation belongs to.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "product"
|
||||
*/
|
||||
@@ -22,7 +22,7 @@ export interface AdminTranslation {
|
||||
|
||||
/**
|
||||
* The BCP 47 language tag code for this translation.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "en-US"
|
||||
*/
|
||||
@@ -31,7 +31,7 @@ export interface AdminTranslation {
|
||||
/**
|
||||
* The translations of the resource.
|
||||
* The object's keys are the field names of the data model, and its value is the translated value.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* {
|
||||
* "title": "Product Title",
|
||||
@@ -55,3 +55,34 @@ export interface AdminTranslation {
|
||||
*/
|
||||
deleted_at: Date | string | null
|
||||
}
|
||||
|
||||
export interface AdminTranslationSettings {
|
||||
/**
|
||||
* The ID of the settings.
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* The date and time the settings were created.
|
||||
*/
|
||||
created_at: Date | string
|
||||
/**
|
||||
* The date and time the settings were last updated.
|
||||
*/
|
||||
updated_at: Date | string
|
||||
/**
|
||||
* The date and time the settings were deleted.
|
||||
*/
|
||||
deleted_at: Date | string | null
|
||||
/**
|
||||
* The entity type.
|
||||
*/
|
||||
entity_type: string
|
||||
/**
|
||||
* The translatable fields.
|
||||
*/
|
||||
fields: string[]
|
||||
/**
|
||||
* Whether the entity translatable status is enabled.
|
||||
*/
|
||||
is_active: boolean
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { AdminTranslation } from "./entities"
|
||||
import { AdminTranslation, AdminTranslationSettings } from "./entities"
|
||||
|
||||
export interface AdminTranslationsResponse {
|
||||
/**
|
||||
@@ -100,6 +100,25 @@ export interface AdminTranslationSettingsResponse {
|
||||
translatable_fields: Record<string, string[]>
|
||||
}
|
||||
|
||||
export interface AdminBatchTranslationSettingsResponse {
|
||||
/**
|
||||
* The created settings.
|
||||
*/
|
||||
created: AdminTranslationSettings[]
|
||||
/**
|
||||
* The updated settings.
|
||||
*/
|
||||
updated: AdminTranslationSettings[]
|
||||
/**
|
||||
* The deleted settings.
|
||||
*/
|
||||
deleted: {
|
||||
ids: string[]
|
||||
object: "translation_settings"
|
||||
deleted: boolean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Response for translation entities endpoint.
|
||||
* Returns paginated entities with only their translatable fields and all their translations.
|
||||
|
||||
@@ -99,6 +99,11 @@ export interface TranslationSettingsDTO {
|
||||
*/
|
||||
fields: string[]
|
||||
|
||||
/**
|
||||
* Whether the entity translatable status is enabled.
|
||||
*/
|
||||
is_active: boolean
|
||||
|
||||
/**
|
||||
* The date and time the settings were created.
|
||||
*/
|
||||
@@ -168,13 +173,30 @@ export interface FilterableTranslationProps
|
||||
locale_code?: string | string[] | OperatorMap<string>
|
||||
}
|
||||
|
||||
export interface FilterableTranslationSettingsProps
|
||||
extends BaseFilterable<FilterableTranslationSettingsProps> {
|
||||
/**
|
||||
* The IDs to filter the translation settings by.
|
||||
*/
|
||||
id?: string[] | string | OperatorMap<string | string[]>
|
||||
|
||||
/**
|
||||
* Filter translation settings by entity type.
|
||||
*/
|
||||
entity_type?: string | string[] | OperatorMap<string | string[]>
|
||||
/**
|
||||
* Filter translation settings by active status.
|
||||
*/
|
||||
is_active?: boolean | OperatorMap<boolean>
|
||||
}
|
||||
|
||||
/**
|
||||
* Input for getStatistics method.
|
||||
*/
|
||||
export interface TranslationStatisticsInput {
|
||||
/**
|
||||
* Locales to check translations for.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* ["en-US", "fr-FR"]
|
||||
*/
|
||||
@@ -183,15 +205,18 @@ export interface TranslationStatisticsInput {
|
||||
/**
|
||||
* Key-value pairs of entity types and their configurations.
|
||||
*/
|
||||
entities: Record<string, {
|
||||
/**
|
||||
* Total number of records for the entity type.
|
||||
* For example, total number of products.
|
||||
*
|
||||
* This is necessary to compute expected translation counts.
|
||||
*/
|
||||
count: number
|
||||
}>
|
||||
entities: Record<
|
||||
string,
|
||||
{
|
||||
/**
|
||||
* Total number of records for the entity type.
|
||||
* For example, total number of products.
|
||||
*
|
||||
* This is necessary to compute expected translation counts.
|
||||
*/
|
||||
count: number
|
||||
}
|
||||
>
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,7 @@ export interface CreateLocaleDTO {
|
||||
|
||||
/**
|
||||
* The BCP 47 language tag code of the locale.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "en-US"
|
||||
*/
|
||||
@@ -17,7 +17,7 @@ export interface CreateLocaleDTO {
|
||||
|
||||
/**
|
||||
* The human-readable name of the locale.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "English (United States)"
|
||||
*/
|
||||
@@ -30,7 +30,7 @@ export interface CreateLocaleDTO {
|
||||
export interface UpdateLocaleDataDTO {
|
||||
/**
|
||||
* The BCP 47 language tag code of the locale.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "en-US"
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ export interface UpdateLocaleDataDTO {
|
||||
|
||||
/**
|
||||
* The human-readable name of the locale.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "English (United States)"
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ export interface UpsertLocaleDTO {
|
||||
|
||||
/**
|
||||
* The BCP 47 language tag code of the locale.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "en-US"
|
||||
*/
|
||||
@@ -74,7 +74,7 @@ export interface UpsertLocaleDTO {
|
||||
|
||||
/**
|
||||
* The human-readable name of the locale.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "English (United States)"
|
||||
*/
|
||||
@@ -87,7 +87,7 @@ export interface UpsertLocaleDTO {
|
||||
export interface CreateTranslationDTO {
|
||||
/**
|
||||
* The ID of the data model being translated.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "prod_123"
|
||||
*/
|
||||
@@ -95,7 +95,7 @@ export interface CreateTranslationDTO {
|
||||
|
||||
/**
|
||||
* The name of the table that the translation belongs to.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "product"
|
||||
*/
|
||||
@@ -103,7 +103,7 @@ export interface CreateTranslationDTO {
|
||||
|
||||
/**
|
||||
* The BCP 47 language tag code for this translation.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "en-US"
|
||||
*/
|
||||
@@ -111,7 +111,7 @@ export interface CreateTranslationDTO {
|
||||
|
||||
/**
|
||||
* The translated fields as key-value pairs.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* {
|
||||
* "title": "Product Title",
|
||||
@@ -127,7 +127,7 @@ export interface CreateTranslationDTO {
|
||||
export interface UpdateTranslationDataDTO {
|
||||
/**
|
||||
* The ID of the data model being translated.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "prod_123"
|
||||
*/
|
||||
@@ -135,7 +135,7 @@ export interface UpdateTranslationDataDTO {
|
||||
|
||||
/**
|
||||
* The name of the table that the translation belongs to.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "product"
|
||||
*/
|
||||
@@ -143,7 +143,7 @@ export interface UpdateTranslationDataDTO {
|
||||
|
||||
/**
|
||||
* The BCP 47 language tag code for this translation.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "en-US"
|
||||
*/
|
||||
@@ -151,7 +151,7 @@ export interface UpdateTranslationDataDTO {
|
||||
|
||||
/**
|
||||
* The translated fields as key-value pairs.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* {
|
||||
* "title": "Product Title",
|
||||
@@ -182,7 +182,7 @@ export interface UpsertTranslationDTO {
|
||||
|
||||
/**
|
||||
* The ID of the data model being translated.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "prod_123"
|
||||
*/
|
||||
@@ -190,7 +190,7 @@ export interface UpsertTranslationDTO {
|
||||
|
||||
/**
|
||||
* The name of the table that the translation belongs to.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "product"
|
||||
*/
|
||||
@@ -198,7 +198,7 @@ export interface UpsertTranslationDTO {
|
||||
|
||||
/**
|
||||
* The BCP 47 language tag code for this translation.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* "en-US"
|
||||
*/
|
||||
@@ -206,7 +206,7 @@ export interface UpsertTranslationDTO {
|
||||
|
||||
/**
|
||||
* The translated fields as key-value pairs.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* {
|
||||
* "title": "Product Title",
|
||||
@@ -215,3 +215,52 @@ export interface UpsertTranslationDTO {
|
||||
*/
|
||||
translations?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface CreateTranslationSettingsDTO {
|
||||
/**
|
||||
* The entity type.
|
||||
*
|
||||
* @example
|
||||
* "product"
|
||||
*/
|
||||
entity_type: string
|
||||
/**
|
||||
* The translatable fields.
|
||||
*
|
||||
* @example
|
||||
* ["title", "description", "material"]
|
||||
*/
|
||||
fields: string[]
|
||||
/**
|
||||
* Whether the entity translatable status is enabled.
|
||||
*/
|
||||
is_active?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* The translation settings to be created or updated.
|
||||
*/
|
||||
export interface UpdateTranslationSettingsDTO {
|
||||
/**
|
||||
* The ID of the translation settings to update.
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* The entity type.
|
||||
*
|
||||
* @example
|
||||
* "product"
|
||||
*/
|
||||
entity_type?: string
|
||||
/**
|
||||
* The translatable fields.
|
||||
*
|
||||
* @example
|
||||
* ["title", "description", "material"]
|
||||
*/
|
||||
fields?: string[]
|
||||
/**
|
||||
* Whether the entity translatable status is enabled.
|
||||
*/
|
||||
is_active?: boolean
|
||||
}
|
||||
|
||||
@@ -5,23 +5,27 @@ import { Context } from "../shared-context"
|
||||
import {
|
||||
FilterableLocaleProps,
|
||||
FilterableTranslationProps,
|
||||
FilterableTranslationSettingsProps,
|
||||
LocaleDTO,
|
||||
TranslationDTO,
|
||||
TranslationSettingsDTO,
|
||||
TranslationStatisticsInput,
|
||||
TranslationStatisticsOutput,
|
||||
} from "./common"
|
||||
import {
|
||||
CreateLocaleDTO,
|
||||
CreateTranslationDTO,
|
||||
CreateTranslationSettingsDTO,
|
||||
UpdateLocaleDTO,
|
||||
UpdateLocaleDataDTO,
|
||||
UpdateTranslationDTO,
|
||||
UpdateTranslationDataDTO,
|
||||
UpdateTranslationSettingsDTO,
|
||||
} from "./mutations"
|
||||
|
||||
/**
|
||||
* The main service interface for the Translation Module.
|
||||
*
|
||||
*
|
||||
* @privateRemarks
|
||||
* Method signatures match what MedusaService generates.
|
||||
*/
|
||||
@@ -43,12 +47,12 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* ```
|
||||
*
|
||||
* To specify relations that should be retrieved:
|
||||
*
|
||||
*
|
||||
* :::note
|
||||
*
|
||||
*
|
||||
* You can only retrieve data models defined in the same module. To retrieve linked data models
|
||||
* from other modules, use [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query) instead.
|
||||
*
|
||||
*
|
||||
* :::
|
||||
*
|
||||
* ```ts
|
||||
@@ -82,12 +86,12 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* ```
|
||||
*
|
||||
* To specify relations that should be retrieved within the locales:
|
||||
*
|
||||
*
|
||||
* :::note
|
||||
*
|
||||
*
|
||||
* You can only retrieve data models defined in the same module. To retrieve linked data models
|
||||
* from other modules, use [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query) instead.
|
||||
*
|
||||
*
|
||||
* :::
|
||||
*
|
||||
* ```ts
|
||||
@@ -141,12 +145,12 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* ```
|
||||
*
|
||||
* To specify relations that should be retrieved within the locales:
|
||||
*
|
||||
*
|
||||
* :::note
|
||||
*
|
||||
*
|
||||
* You can only retrieve data models defined in the same module. To retrieve linked data models
|
||||
* from other modules, use [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query) instead.
|
||||
*
|
||||
*
|
||||
* :::
|
||||
*
|
||||
* ```ts
|
||||
@@ -250,7 +254,7 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
*
|
||||
* @example
|
||||
* To update locales by their IDs:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* const locales = await translationModuleService.updateLocales([
|
||||
* {
|
||||
@@ -265,7 +269,7 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* ```
|
||||
*
|
||||
* To update locales by a selector:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* const locales = await translationModuleService.updateLocales({
|
||||
* selector: {
|
||||
@@ -299,7 +303,7 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* @param {string | object | string[] | object[]} primaryKeyValues - The IDs or objects with IDs identifying the locales to delete.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<void>} Resolves when the locales are deleted.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* await translationModuleService.deleteLocales(["loc_123", "loc_321"])
|
||||
*/
|
||||
@@ -336,7 +340,7 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* @returns {Promise<Record<string, string[]> | void>} An object that includes the IDs of related records that were restored.
|
||||
*
|
||||
* If there are no related records restored, the promise resolves to `void`.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* await translationModuleService.restoreLocales(["loc_123", "loc_321"])
|
||||
*/
|
||||
@@ -362,12 +366,12 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* ```
|
||||
*
|
||||
* To specify relations that should be retrieved:
|
||||
*
|
||||
*
|
||||
* :::note
|
||||
*
|
||||
*
|
||||
* You can only retrieve data models defined in the same module. To retrieve linked data models
|
||||
* from other modules, use [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query) instead.
|
||||
*
|
||||
*
|
||||
* :::
|
||||
*
|
||||
* ```ts
|
||||
@@ -401,12 +405,12 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* ```
|
||||
*
|
||||
* To specify relations that should be retrieved within the translations:
|
||||
*
|
||||
*
|
||||
* :::note
|
||||
*
|
||||
*
|
||||
* You can only retrieve data models defined in the same module. To retrieve linked data models
|
||||
* from other modules, use [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query) instead.
|
||||
*
|
||||
*
|
||||
* :::
|
||||
*
|
||||
* ```ts
|
||||
@@ -419,7 +423,7 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* }
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||
*
|
||||
* ```ts
|
||||
@@ -460,12 +464,12 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* ```
|
||||
*
|
||||
* To specify relations that should be retrieved within the translations:
|
||||
*
|
||||
*
|
||||
* :::note
|
||||
*
|
||||
*
|
||||
* You can only retrieve data models defined in the same module. To retrieve linked data models
|
||||
* from other modules, use [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query) instead.
|
||||
*
|
||||
*
|
||||
* :::
|
||||
*
|
||||
* ```ts
|
||||
@@ -478,7 +482,7 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* }
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||
*
|
||||
* ```ts
|
||||
@@ -618,7 +622,7 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* @param {string | object | string[] | object[]} primaryKeyValues - The IDs or objects with IDs identifying the translations to delete.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<void>} Resolves when the translations are deleted.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* await translationModuleService.deleteTranslations("tra_123")
|
||||
*/
|
||||
@@ -635,7 +639,7 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<Record<string, string[]> | void>} An object that includes the IDs of related records that were also soft deleted.
|
||||
* If there are no related records, the promise resolves to `void`.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* await translationModuleService.softDeleteTranslations(["tra_123", "tra_321"])
|
||||
*/
|
||||
@@ -667,7 +671,7 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
/**
|
||||
* This method retrieves translation statistics for the specified entities and locales.
|
||||
* It's useful to understand the translation coverage of different entities across various locales.
|
||||
*
|
||||
*
|
||||
* You can use this method to get insights into how many fields are translated, missing translations,
|
||||
* and the expected number of translations based on the entities and locales provided.
|
||||
*
|
||||
@@ -731,4 +735,189 @@ export interface ITranslationModuleService extends IModuleService {
|
||||
entityType?: string,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]>>
|
||||
|
||||
/**
|
||||
* This method creates a translation setting.
|
||||
*
|
||||
* @param {CreateTranslationSettingsDTO} data - The translation setting to be created.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<TranslationSettingsDTO>} The created translation setting.
|
||||
*
|
||||
* @example
|
||||
* const translationSetting = await translationModuleService.createTranslationSettings({
|
||||
* entity_type: "product",
|
||||
* fields: ["title", "description"],
|
||||
* is_active: true,
|
||||
* })
|
||||
*/
|
||||
createTranslationSettings(
|
||||
data: CreateTranslationSettingsDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<TranslationSettingsDTO>
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data - The translation settings to be created.
|
||||
* @param sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<TranslationSettingsDTO[]>} The created translation settings.
|
||||
*
|
||||
* @example
|
||||
* const translationSettings = await translationModuleService.createTranslationSettings([
|
||||
* {
|
||||
* entity_type: "product",
|
||||
* fields: ["title", "description"],
|
||||
* is_active: true,
|
||||
* },
|
||||
* ])
|
||||
*/
|
||||
createTranslationSettings(
|
||||
data: CreateTranslationSettingsDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<TranslationSettingsDTO[]>
|
||||
|
||||
/**
|
||||
* This method updates an existent translation setting. The ID should be included in the data object.
|
||||
}
|
||||
* @param {UpdateTranslationSettingsDTO} data - The attributes to update in the translation setting (including id).
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<TranslationSettingsDTO>} The updated translation setting.
|
||||
*
|
||||
* @example
|
||||
* const translationSettings = await translationModuleService.updateTranslationSettings([
|
||||
* {
|
||||
* id: "ts_123",
|
||||
* entity_type: "product_collection",
|
||||
* fields: ["title"],
|
||||
* is_active: true,
|
||||
* },
|
||||
* ])
|
||||
*/
|
||||
updateTranslationSettings(
|
||||
data: UpdateTranslationSettingsDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<TranslationSettingsDTO>
|
||||
|
||||
/**
|
||||
* This method updates one or more existent translation settings.
|
||||
* @param {UpdateTranslationSettingsDTO[]} data - The translation settings to update.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<TranslationSettingsDTO[]>} The updated translation settings.
|
||||
*
|
||||
* @example
|
||||
* const translationSettings = await translationModuleService.updateTranslationSettings([
|
||||
* {
|
||||
* id: "ts_123",
|
||||
* entity_type: "product_collection",
|
||||
* fields: ["title"],
|
||||
* is_active: true,
|
||||
* },
|
||||
* ])
|
||||
*/
|
||||
updateTranslationSettings(
|
||||
data: UpdateTranslationSettingsDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<TranslationSettingsDTO[]>
|
||||
|
||||
/**
|
||||
* This method deletes one or more translation settings.
|
||||
*
|
||||
* @param {string[]} input - The IDs of the translation settings to delete.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<void>} Resolves when the translation settings are deleted.
|
||||
*
|
||||
* @example
|
||||
* await translationModuleService.deleteTranslationSettings([
|
||||
* "ts_123",
|
||||
* "ts_321",
|
||||
* ])
|
||||
*/
|
||||
deleteTranslationSettings(
|
||||
input: string[],
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
|
||||
/**
|
||||
* This method retrieves a paginated list of translation settings based on optional filters and configuration.
|
||||
*
|
||||
* @param {FilterableTranslationSettingsProps} filters - The filters to apply on the retrieved translation settings.
|
||||
* @param {FindConfig<TranslationSettingsDTO>} config - The configurations determining how the translation settings are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||
* attributes or relations associated with a translation settings.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<TranslationSettingsDTO[]>} The list of translation settings.
|
||||
*
|
||||
* @example
|
||||
* const translationSettings = await translationModuleService.listTranslationSettings({
|
||||
* entity_type: "product",
|
||||
* is_active: true,
|
||||
* })
|
||||
* // Returns: [
|
||||
* // {
|
||||
* // id: "ts_123",
|
||||
* // entity_type: "product",
|
||||
* // fields: ["title", "description"],
|
||||
* // is_active: true,
|
||||
* // },
|
||||
* // ]
|
||||
*/
|
||||
listTranslationSettings(
|
||||
filters?: FilterableTranslationSettingsProps,
|
||||
config?: FindConfig<TranslationSettingsDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<TranslationSettingsDTO[]>
|
||||
|
||||
/**
|
||||
* This method retrieves a paginated list of translation settings based on optional filters and configuration, along with the total count.
|
||||
*
|
||||
* @param {FilterableTranslationSettingsProps} filters - The filters to apply on the retrieved translation settings.
|
||||
* @param {FindConfig<TranslationSettingsDTO>} config - The configurations determining how the translation settings are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||
* attributes or relations associated with a translation settings.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<[TranslationSettingsDTO[], number]>} The list of translation settings along with their total count.
|
||||
*
|
||||
* @example
|
||||
* const [translationSettings, count] = await translationModuleService.listAndCountTranslationSettings({
|
||||
* entity_type: "product",
|
||||
* is_active: true,
|
||||
* })
|
||||
* // Returns: [
|
||||
* // [
|
||||
* // {
|
||||
* // id: "ts_123",
|
||||
* // entity_type: "product",
|
||||
* // fields: ["title", "description"],
|
||||
* // is_active: true,
|
||||
* // },
|
||||
* // ],
|
||||
* // 1,
|
||||
* // ]
|
||||
*/
|
||||
listAndCountTranslationSettings(
|
||||
filters?: FilterableTranslationSettingsProps,
|
||||
config?: FindConfig<TranslationSettingsDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<[TranslationSettingsDTO[], number]>
|
||||
|
||||
/**
|
||||
* This method retrieves a translation setting by its ID.
|
||||
*
|
||||
* @param {string} id - The ID of the translation setting to retrieve.
|
||||
* @param {FindConfig<TranslationSettingsDTO>} config - The configurations determining how the translation setting is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||
* attributes or relations associated with a translation settings.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<TranslationSettingsDTO>} The retrieved translation setting.
|
||||
*
|
||||
* @example
|
||||
* const translationSetting = await translationModuleService.retrieveTranslationSettings("ts_123")
|
||||
* // Returns: {
|
||||
* // id: "ts_123",
|
||||
* // entity_type: "product",
|
||||
* // fields: ["title", "description"],
|
||||
* // is_active: true,
|
||||
* // }
|
||||
*/
|
||||
retrieveTranslationSettings(
|
||||
id: string,
|
||||
config?: FindConfig<TranslationSettingsDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<TranslationSettingsDTO>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user