What:
- Definition of all Modules links
- `link-modules` package to manage the creation of all pre-defined link or custom ones
```typescript
import { initialize as iniInventory } from "@medusajs/inventory";
import { initialize as iniProduct } from "@medusajs/product";
import {
initialize as iniLinks,
runMigrations as migrateLinks
} from "@medusajs/link-modules";
await Promise.all([iniInventory(), iniProduct()]);
await migrateLinks(); // create tables based on previous loaded modules
await iniLinks(); // load link based on previous loaded modules
await iniLinks(undefined, [
{
serviceName: "product_custom_translation_service_link",
isLink: true,
databaseConfig: {
tableName: "product_transalations",
},
alias: [
{
name: "translations",
},
],
primaryKeys: ["id", "product_id", "translation_id"],
relationships: [
{
serviceName: Modules.PRODUCT,
primaryKey: "id",
foreignKey: "product_id",
alias: "product",
},
{
serviceName: "custom_translation_service",
primaryKey: "id",
foreignKey: "translation_id",
alias: "transalation",
deleteCascade: true,
},
],
extends: [
{
serviceName: Modules.PRODUCT,
relationship: {
serviceName: "product_custom_translation_service_link",
primaryKey: "product_id",
foreignKey: "id",
alias: "translations",
isList: true,
},
},
{
serviceName: "custom_translation_service",
relationship: {
serviceName: "product_custom_translation_service_link",
primaryKey: "product_id",
foreignKey: "id",
alias: "product_link",
},
},
],
},
]); // custom links
```
Remote Link
```typescript
import { RemoteLink, Modules } from "@medusajs/modules-sdk";
// [...] initialize modules and links
const remoteLink = new RemoteLink();
// upsert the relationship
await remoteLink.create({ // one (object) or many (array)
[Modules.PRODUCT]: {
variant_id: "var_abc",
},
[Modules.INVENTORY]: {
inventory_item_id: "iitem_abc",
},
data: { // optional additional fields
required_quantity: 5
}
});
// dismiss (doesn't cascade)
await remoteLink.dismiss({ // one (object) or many (array)
[Modules.PRODUCT]: {
variant_id: "var_abc",
},
[Modules.INVENTORY]: {
inventory_item_id: "iitem_abc",
},
});
// delete
await remoteLink.delete({
// every key is a module
[Modules.PRODUCT]: {
// every key is a linkable field
variant_id: "var_abc", // single or multiple values
},
});
// restore
await remoteLink.restore({
// every key is a module
[Modules.PRODUCT]: {
// every key is a linkable field
variant_id: "var_abc", // single or multiple values
},
});
```
Co-authored-by: Riqwan Thamir <5105988+riqwan@users.noreply.github.com>
40 lines
934 B
JSON
40 lines
934 B
JSON
{
|
|
"name": "@medusajs/stock-location",
|
|
"version": "1.9.1",
|
|
"description": "Stock Location Module for Medusa",
|
|
"main": "dist/index.js",
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "https://github.com/medusajs/medusa",
|
|
"directory": "packages/stock-location"
|
|
},
|
|
"publishConfig": {
|
|
"access": "public"
|
|
},
|
|
"files": [
|
|
"dist"
|
|
],
|
|
"author": "Medusa",
|
|
"license": "MIT",
|
|
"devDependencies": {
|
|
"@medusajs/types": "^1.8.8",
|
|
"cross-env": "^5.2.1",
|
|
"jest": "^29.6.3",
|
|
"rimraf": "^5.0.1",
|
|
"ts-jest": "^29.1.1",
|
|
"typescript": "^5.1.6"
|
|
},
|
|
"dependencies": {
|
|
"@medusajs/modules-sdk": "^1.8.8",
|
|
"@medusajs/utils": "^1.9.1",
|
|
"awilix": "^8.0.0",
|
|
"typeorm": "^0.3.16"
|
|
},
|
|
"scripts": {
|
|
"watch": "tsc --build --watch",
|
|
"prepublishOnly": "cross-env NODE_ENV=production tsc --build",
|
|
"build": "rimraf dist && tsc --build",
|
|
"test": "jest --passWithNoTests"
|
|
}
|
|
}
|