@vendure/mcp-plugin 3.8.2-master-202610270216 → 3.8.2-master-202610280208
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.
|
@@ -29,14 +29,23 @@ let AdjustStockTool = class AdjustStockTool {
|
|
|
29
29
|
}
|
|
30
30
|
async execute(ctx, input) {
|
|
31
31
|
var _a;
|
|
32
|
-
// The
|
|
33
|
-
//
|
|
32
|
+
// The write sets an absolute stockOnHand, so the read must hold the row lock until the tool's
|
|
33
|
+
// transaction commits. Otherwise a concurrent adjustment would be overwritten. See #5652
|
|
34
|
+
// It comes before any other read: on MySQL and MariaDB the first plain read fixes the snapshot
|
|
35
|
+
// which core's write later looks the row up in, so that snapshot must not predate the lock.
|
|
36
|
+
let current = await this.findLockedStockLevel(ctx, input);
|
|
37
|
+
// The locked stock read above and the write below are not limited to the active channel, so we
|
|
38
|
+
// check the location here to avoid silently overwriting another channel's stock.
|
|
34
39
|
const location = await this.stockLocationService.findOne(ctx, input.locationId);
|
|
35
40
|
if (!location) {
|
|
36
41
|
throw new core_1.UserInputError(`Stock location ${input.locationId} is not available in the active channel.`);
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
if (!current) {
|
|
44
|
+
// On Postgres a locked read which waited for another transaction does not return a row that
|
|
45
|
+
// transaction inserted, so the first stock at a location would be read as 0. A second read
|
|
46
|
+
// sees it. If there is still no row, core creates it with a stockOnHand of 0.
|
|
47
|
+
current = await this.findLockedStockLevel(ctx, input);
|
|
48
|
+
}
|
|
40
49
|
const stockOnHand = ((_a = current === null || current === void 0 ? void 0 : current.stockOnHand) !== null && _a !== void 0 ? _a : 0) + input.delta;
|
|
41
50
|
if (stockOnHand < mcp_sdk_1.GRAPHQL_INT_MIN || stockOnHand > mcp_sdk_1.GRAPHQL_INT_MAX) {
|
|
42
51
|
throw new core_1.UserInputError(`A delta of ${input.delta} would set stock on hand to ${stockOnHand}, outside ` +
|
|
@@ -56,6 +65,10 @@ let AdjustStockTool = class AdjustStockTool {
|
|
|
56
65
|
const updated = await this.stockLevelService.getStockLevelsForVariant(ctx, input.variantId);
|
|
57
66
|
return { stockLevels: updated.map(level => this.serializer.stockLevel(level)) };
|
|
58
67
|
}
|
|
68
|
+
async findLockedStockLevel(ctx, input) {
|
|
69
|
+
const levels = await this.stockLevelService.getLockedStockLevelsForVariant(ctx, input.variantId);
|
|
70
|
+
return levels.find(level => (0, core_1.idsAreEqual)(level.stockLocationId, input.locationId));
|
|
71
|
+
}
|
|
59
72
|
};
|
|
60
73
|
exports.AdjustStockTool = AdjustStockTool;
|
|
61
74
|
exports.AdjustStockTool = AdjustStockTool = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adjust-stock.tool.js","sourceRoot":"","sources":["../../../../src/tools/built-in/admin/adjust-stock.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,wCAQuB;AACvB,8CAO0B;AAC1B,6BAAwB;AAExB,8DAAiE;AAEjE,MAAM,gBAAgB,GAAG,OAAC,CAAC,YAAY,CAAC;IACpC,SAAS,EAAE,kBAAQ,CAAC,QAAQ,CAAC,qBAAqB,CAAC;IACnD,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC,oBAAoB,CAAC;IACnD,KAAK,EAAE,qBAAW,CAAC,QAAQ,CAAC,mEAAmE,CAAC;CACnG,CAAC,CAAC;AAuBI,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB,YACqB,qBAA4C,EAC5C,iBAAoC,EACpC,oBAA0C,EAC1C,UAAoC;QAHpC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,eAAU,GAAV,UAAU,CAA0B;IACtD,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,GAAmB,EAAE,KAAuB;;QACtD,
|
|
1
|
+
{"version":3,"file":"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J,CAAA;AAtDY,0CAAe;0BAAf,eAAe;IAnB3B,IAAA,iBAAO,EAAC;QACL,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,wDAAwD;QACrE,QAAQ,EAAE;YACN,mBAAmB;YACnB,4BAA4B;YAC5B,qBAAqB;YACrB,yBAAyB;YACzB,wBAAwB;YACxB,wBAAwB;SAC3B;QACD,wFAAwF;QACxF,uFAAuF;QACvF,WAAW,EAAE,CAAC,iBAAU,CAAC,aAAa,CAAC;QACvC,QAAQ,EAAE,aAAa;QACvB,WAAW,EAAE,gBAAgB;KAChC,CAAC;IACD,IAAA,mBAAU,GAAE;qCAGmC,4BAAqB;QACzB,wBAAiB;QACd,2BAAoB;QAC9B,6CAAwB;GALhD,eAAe,CAsD3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vendure/mcp-plugin",
|
|
3
|
-
"version": "3.8.2-master-
|
|
3
|
+
"version": "3.8.2-master-202610280208",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@modelcontextprotocol/node": "2.0.0",
|
|
33
33
|
"@modelcontextprotocol/server": "2.0.0",
|
|
34
|
-
"@vendure/mcp-sdk": "^3.8.2-master-
|
|
34
|
+
"@vendure/mcp-sdk": "^3.8.2-master-202610280208",
|
|
35
35
|
"zod": "^4.2.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@modelcontextprotocol/client": "2.0.0",
|
|
39
39
|
"@types/express": "^5.0.1",
|
|
40
|
-
"@vendure/common": "^3.8.2-master-
|
|
41
|
-
"@vendure/core": "^3.8.2-master-
|
|
40
|
+
"@vendure/common": "^3.8.2-master-202610280208",
|
|
41
|
+
"@vendure/core": "^3.8.2-master-202610280208"
|
|
42
42
|
}
|
|
43
43
|
}
|