feat(medusa-plugin-meilisearch): Update + improve Meilisearch plugin (#3377)

* feat(medusa-plugin-meilisearch): Upgrade meilisearch deps + migrate plugin to TS

* fix version

* Remove transaction base service from search service

* Create .changeset/strange-mails-pump.md

* Backward compatibility

* Address PR feedback

* Fix folder structure

* Update readme

* Move types

* fix deps

* Change version in changeset

---------

Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
This commit is contained in:
Oliver Windall Juhlandadrien2p authored and GitHub committed 2023-03-16 16:15:29 +01:00
1 parent 4213326fe8
commit 7e17e0ddc2
21 files changed
+377 -217

No files matched your search

@@ -1,4 +1,3 @@
import { TransactionBaseService } from "./transaction-base-service"
import { SearchService } from "medusa-interfaces"
export interface ISearchService {
@@ -72,10 +71,7 @@ export interface ISearchService {
updateSettings(indexName: string, settings: unknown): unknown
}
export abstract class AbstractSearchService
extends TransactionBaseService
implements ISearchService
{
export abstract class AbstractSearchService implements ISearchService {
abstract readonly isDefault
protected readonly options_: Record<string, unknown>
@@ -84,7 +80,6 @@ export abstract class AbstractSearchService
}
protected constructor(container, options) {
super(container, options)
this.options_ = options
}
-3
View File
@@ -10,8 +10,6 @@ type InjectedDependencies = {
export default class DefaultSearchService extends AbstractSearchService {
isDefault = true
protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined
protected readonly logger_: Logger
protected readonly options_: Record<string, unknown>
@@ -25,7 +23,6 @@ export default class DefaultSearchService extends AbstractSearchService {
this.options_ = options
this.logger_ = logger
this.manager_ = manager
}
async createIndex(indexName: string, options: unknown): Promise<void> {
@@ -1,29 +1,35 @@
import EventBusService from "../services/event-bus"
import { SEARCH_INDEX_EVENT } from "../loaders/search-index"
import ProductService from "../services/product"
import { indexTypes } from "medusa-core-utils"
import { Product } from "../models"
import { ISearchService } from "../interfaces"
import ProductCategoryFeatureFlag from "../loaders/feature-flags/product-categories"
import { SEARCH_INDEX_EVENT } from "../loaders/search-index"
import { Product } from "../models"
import EventBusService from "../services/event-bus"
import ProductService from "../services/product"
import { FlagRouter } from "../utils/flag-router"
type InjectedDependencies = {
eventBusService: EventBusService
searchService: ISearchService
productService: ProductService
featureFlagRouter: FlagRouter
}
class SearchIndexingSubscriber {
private readonly eventBusService_: EventBusService
private readonly searchService_: ISearchService
private readonly productService_: ProductService
private readonly featureFlagRouter_: FlagRouter
constructor({
eventBusService,
searchService,
productService,
featureFlagRouter,
}: InjectedDependencies) {
this.eventBusService_ = eventBusService
this.searchService_ = searchService
this.productService_ = productService
this.featureFlagRouter_ = featureFlagRouter
this.eventBusService_.subscribe(SEARCH_INDEX_EVENT, this.indexDocuments)
}
@@ -54,36 +60,27 @@ class SearchIndexingSubscriber {
lastSeenId: string,
take: number
): Promise<Product[]> {
const relations = [
"variants",
"tags",
"type",
"collection",
"variants.prices",
"images",
"variants.options",
"options",
]
if (
this.featureFlagRouter_.isFeatureEnabled(ProductCategoryFeatureFlag.key)
) {
relations.push("categories")
}
return await this.productService_.list(
{ id: { gt: lastSeenId } },
{
select: [
"id",
"title",
"status",
"subtitle",
"description",
"handle",
"is_giftcard",
"discountable",
"thumbnail",
"profile_id",
"collection_id",
"type_id",
"origin_country",
"created_at",
"updated_at",
],
relations: [
"variants",
"tags",
"type",
"collection",
"variants.prices",
"images",
"variants.options",
"options",
],
relations,
take: take,
order: { id: "ASC" },
}