Initial commit: backend, storefront, vendor-panel added
This commit is contained in:
45
backend/packages/modules/algolia/package.json
Normal file
45
backend/packages/modules/algolia/package.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "@mercurjs/algolia",
|
||||
"version": "1.0.0",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"!dist/**/__tests__",
|
||||
"!dist/**/__mocks__",
|
||||
"!dist/**/__fixtures__"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsc --build",
|
||||
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "2.8.6",
|
||||
"@medusajs/test-utils": "2.8.6",
|
||||
"@mercurjs/framework": "*",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"tsc-alias": "^1.8.6",
|
||||
"typescript": "^5.6.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "2.8.6",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1"
|
||||
}
|
||||
}
|
||||
11
backend/packages/modules/algolia/src/index.ts
Normal file
11
backend/packages/modules/algolia/src/index.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Module } from "@medusajs/framework/utils";
|
||||
|
||||
import AlgoliaModuleService from "./service";
|
||||
|
||||
export const ALGOLIA_MODULE = "algolia";
|
||||
export { AlgoliaModuleService };
|
||||
export { defaultProductSettings, defaultReviewSettings } from "./service";
|
||||
|
||||
export default Module(ALGOLIA_MODULE, {
|
||||
service: AlgoliaModuleService,
|
||||
});
|
||||
142
backend/packages/modules/algolia/src/service.ts
Normal file
142
backend/packages/modules/algolia/src/service.ts
Normal file
@@ -0,0 +1,142 @@
|
||||
import {
|
||||
Action,
|
||||
Algoliasearch,
|
||||
BatchRequest,
|
||||
IndexSettings,
|
||||
algoliasearch,
|
||||
} from "algoliasearch";
|
||||
import { IndexType, AlgoliaEntity } from "@mercurjs/framework";
|
||||
|
||||
type ModuleOptions = {
|
||||
appId: string;
|
||||
apiKey: string;
|
||||
};
|
||||
|
||||
export const defaultProductSettings: IndexSettings = {
|
||||
searchableAttributes: [
|
||||
"title",
|
||||
"subtitle",
|
||||
"brand.name",
|
||||
"tags.value",
|
||||
"type.value",
|
||||
"categories.name",
|
||||
"collection.title",
|
||||
"variants.title",
|
||||
],
|
||||
};
|
||||
|
||||
export const defaultReviewSettings: IndexSettings = {
|
||||
attributesForFaceting: ["filterOnly(reference_id)", "filterOnly(reference)"],
|
||||
};
|
||||
|
||||
class AlgoliaModuleService {
|
||||
private options_: ModuleOptions;
|
||||
private algolia_: Algoliasearch;
|
||||
|
||||
constructor(_, options: ModuleOptions) {
|
||||
this.options_ = options;
|
||||
this.algolia_ = algoliasearch(this.options_.appId, this.options_.apiKey);
|
||||
}
|
||||
|
||||
getAppId() {
|
||||
return this.options_.appId;
|
||||
}
|
||||
|
||||
checkIndex(index: IndexType) {
|
||||
return this.algolia_.indexExists({
|
||||
indexName: index,
|
||||
});
|
||||
}
|
||||
|
||||
updateSettings(index: IndexType, settings: IndexSettings) {
|
||||
return this.algolia_.setSettings({
|
||||
indexName: index,
|
||||
indexSettings: settings,
|
||||
});
|
||||
}
|
||||
|
||||
batch(type: IndexType, toAdd: AlgoliaEntity[], toDelete: string[]) {
|
||||
const requests: BatchRequest[] = toAdd.map((entity) => {
|
||||
return {
|
||||
action: "addObject" as Action,
|
||||
objectID: entity.id,
|
||||
body: entity,
|
||||
};
|
||||
});
|
||||
|
||||
requests.concat(
|
||||
toDelete.map((id) => {
|
||||
return {
|
||||
action: "deleteObject" as Action,
|
||||
objectID: id,
|
||||
body: {},
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return this.algolia_.batch({
|
||||
indexName: type,
|
||||
batchWriteParams: {
|
||||
requests,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
batchUpsert(type: IndexType, entities: AlgoliaEntity[]) {
|
||||
return this.algolia_.batch({
|
||||
indexName: type,
|
||||
batchWriteParams: {
|
||||
requests: entities.map((entity) => {
|
||||
return {
|
||||
action: "addObject",
|
||||
objectID: entity.id,
|
||||
body: entity,
|
||||
};
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
batchDelete(type: IndexType, ids: string[]) {
|
||||
return this.algolia_.batch({
|
||||
indexName: type,
|
||||
batchWriteParams: {
|
||||
requests: ids.map((id) => {
|
||||
return {
|
||||
action: "deleteObject",
|
||||
objectID: id,
|
||||
body: {},
|
||||
};
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
upsert(type: IndexType, entity: AlgoliaEntity) {
|
||||
return this.algolia_.addOrUpdateObject({
|
||||
indexName: type,
|
||||
objectID: entity.id,
|
||||
body: entity,
|
||||
});
|
||||
}
|
||||
|
||||
delete(type: IndexType, id: string) {
|
||||
return this.algolia_.deleteObject({
|
||||
indexName: type,
|
||||
objectID: id,
|
||||
});
|
||||
}
|
||||
|
||||
partialUpdate(
|
||||
type: IndexType,
|
||||
entity: Partial<AlgoliaEntity> & { id: string }
|
||||
) {
|
||||
return this.algolia_.partialUpdateObject({
|
||||
indexName: type,
|
||||
objectID: entity.id,
|
||||
attributesToUpdate: { ...entity },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default AlgoliaModuleService;
|
||||
27
backend/packages/modules/algolia/tsconfig.json
Normal file
27
backend/packages/modules/algolia/tsconfig.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["ES2021"],
|
||||
"target": "ES2021",
|
||||
"outDir": "${configDir}/dist",
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"noUnusedLocals": true,
|
||||
"module": "node16",
|
||||
"moduleResolution": "node16",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"sourceMap": true,
|
||||
"noImplicitReturns": true,
|
||||
"resolveJsonModule": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"noImplicitThis": true,
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"incremental": false
|
||||
},
|
||||
"include": ["${configDir}/src"],
|
||||
"exclude": ["${configDir}/dist", "${configDir}/node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user