@porulle/plugin-channel-connector 0.70.1 → 0.70.2
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.
- package/dist/service.js +13 -3
- package/package.json +2 -2
- package/src/service.ts +13 -2
package/dist/service.js
CHANGED
|
@@ -4226,8 +4226,12 @@ export class ChannelConnectorService {
|
|
|
4226
4226
|
await this.db.insert(channelRefundEvents).values({ organizationId: orgId, requestId: request.id, fromState: null, toState: request.state, reason: auto ? "Automatic guarded refund" : "Operator approval required", changedBy: requireUserId(actor) });
|
|
4227
4227
|
if (auto) {
|
|
4228
4228
|
const result = await this.executeRefund(request, refundLines, actor);
|
|
4229
|
-
if (!result.ok)
|
|
4230
|
-
|
|
4229
|
+
if (!result.ok) {
|
|
4230
|
+
// Nothing moved: an operator decides instead, rather than the request sticking as approved.
|
|
4231
|
+
await this.db.update(channelRefundRequests).set({ state: "requested", approvedBy: null, updatedAt: new Date() }).where(and(eq(channelRefundRequests.organizationId, orgId), eq(channelRefundRequests.id, request.id), eq(channelRefundRequests.state, "approved")));
|
|
4232
|
+
await this.db.insert(channelRefundEvents).values({ organizationId: orgId, requestId: request.id, fromState: "approved", toState: "requested", reason: `Automatic refund failed: ${result.error}`, changedBy: requireUserId(actor) });
|
|
4233
|
+
return Ok({ ...request, state: "requested" });
|
|
4234
|
+
}
|
|
4231
4235
|
}
|
|
4232
4236
|
return Ok(request);
|
|
4233
4237
|
}
|
|
@@ -4248,7 +4252,13 @@ export class ChannelConnectorService {
|
|
|
4248
4252
|
if (!request)
|
|
4249
4253
|
return PluginErr("Refund request not found or already handled.", "NOT_FOUND");
|
|
4250
4254
|
const lines = await this.refundLinesForRequest(request);
|
|
4251
|
-
|
|
4255
|
+
const executed = await this.executeRefund(request, lines, createSystemActor(orgId));
|
|
4256
|
+
if (!executed.ok) {
|
|
4257
|
+
// Nothing moved: back to `requested`, so the operator can approve again once the cause is fixed.
|
|
4258
|
+
await this.db.update(channelRefundRequests).set({ state: "requested", approvedBy: null, updatedAt: new Date() }).where(and(eq(channelRefundRequests.organizationId, orgId), eq(channelRefundRequests.id, id), eq(channelRefundRequests.state, "approved")));
|
|
4259
|
+
await this.db.insert(channelRefundEvents).values({ organizationId: orgId, requestId: id, fromState: "approved", toState: "requested", reason: `Execution failed: ${executed.error}`, changedBy: actor.userId });
|
|
4260
|
+
}
|
|
4261
|
+
return executed;
|
|
4252
4262
|
}
|
|
4253
4263
|
async rejectRefund(orgId, id, actor) {
|
|
4254
4264
|
const [request] = await this.db.update(channelRefundRequests).set({ state: "rejected", approvedBy: actor.userId, updatedAt: new Date() }).where(and(eq(channelRefundRequests.organizationId, orgId), eq(channelRefundRequests.id, id), eq(channelRefundRequests.state, "requested"))).returning();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@porulle/plugin-channel-connector",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@hono/zod-openapi": "^1.2.2",
|
|
24
24
|
"hono": "^4.12.5",
|
|
25
|
-
"@porulle/core": "0.70.
|
|
25
|
+
"@porulle/core": "0.70.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^24.5.2",
|
package/src/service.ts
CHANGED
|
@@ -5350,7 +5350,12 @@ export class ChannelConnectorService {
|
|
|
5350
5350
|
await this.db.insert(channelRefundEvents).values({ organizationId: orgId, requestId: request.id, fromState: null, toState: request.state, reason: auto ? "Automatic guarded refund" : "Operator approval required", changedBy: requireUserId(actor) });
|
|
5351
5351
|
if (auto) {
|
|
5352
5352
|
const result = await this.executeRefund(request, refundLines, actor);
|
|
5353
|
-
if (!result.ok)
|
|
5353
|
+
if (!result.ok) {
|
|
5354
|
+
// Nothing moved: an operator decides instead, rather than the request sticking as approved.
|
|
5355
|
+
await this.db.update(channelRefundRequests).set({ state: "requested", approvedBy: null, updatedAt: new Date() }).where(and(eq(channelRefundRequests.organizationId, orgId), eq(channelRefundRequests.id, request.id), eq(channelRefundRequests.state, "approved")));
|
|
5356
|
+
await this.db.insert(channelRefundEvents).values({ organizationId: orgId, requestId: request.id, fromState: "approved", toState: "requested", reason: `Automatic refund failed: ${result.error}`, changedBy: requireUserId(actor) });
|
|
5357
|
+
return Ok({ ...request, state: "requested" });
|
|
5358
|
+
}
|
|
5354
5359
|
}
|
|
5355
5360
|
return Ok(request);
|
|
5356
5361
|
}
|
|
@@ -5372,7 +5377,13 @@ export class ChannelConnectorService {
|
|
|
5372
5377
|
const [request] = await this.db.update(channelRefundRequests).set({ state: "approved", approvedBy: actor.userId, updatedAt: new Date() }).where(and(eq(channelRefundRequests.organizationId, orgId), eq(channelRefundRequests.id, id), eq(channelRefundRequests.state, "requested"))).returning();
|
|
5373
5378
|
if (!request) return PluginErr("Refund request not found or already handled.", "NOT_FOUND");
|
|
5374
5379
|
const lines = await this.refundLinesForRequest(request as ChannelRefundRequest);
|
|
5375
|
-
|
|
5380
|
+
const executed = await this.executeRefund(request as ChannelRefundRequest, lines, createSystemActor(orgId));
|
|
5381
|
+
if (!executed.ok) {
|
|
5382
|
+
// Nothing moved: back to `requested`, so the operator can approve again once the cause is fixed.
|
|
5383
|
+
await this.db.update(channelRefundRequests).set({ state: "requested", approvedBy: null, updatedAt: new Date() }).where(and(eq(channelRefundRequests.organizationId, orgId), eq(channelRefundRequests.id, id), eq(channelRefundRequests.state, "approved")));
|
|
5384
|
+
await this.db.insert(channelRefundEvents).values({ organizationId: orgId, requestId: id, fromState: "approved", toState: "requested", reason: `Execution failed: ${executed.error}`, changedBy: actor.userId });
|
|
5385
|
+
}
|
|
5386
|
+
return executed;
|
|
5376
5387
|
}
|
|
5377
5388
|
|
|
5378
5389
|
async rejectRefund(orgId: string, id: string, actor: { userId: string }): Promise<PluginResult<ChannelRefundRequest>> {
|