@infuro/cms-core 1.0.64 → 1.0.65
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/admin.cjs +1 -1
- package/dist/admin.js +1 -1
- package/dist/api.cjs +36 -36
- package/dist/api.js +4 -4
- package/dist/{chunk-OJAYCNE5.js → chunk-ACBN6UWZ.js} +218 -39
- package/dist/chunk-BXAKL2TF.cjs +84 -0
- package/dist/{chunk-M25DGZ5J.cjs → chunk-NIRYYJIJ.cjs} +220 -41
- package/dist/{chunk-DXERXWBR.js → chunk-RDEVZMO5.js} +36 -20
- package/dist/{chunk-K6C3ZSBZ.js → chunk-SANKKGB3.js} +28 -18
- package/dist/chunk-THL5JDWJ.cjs +101 -0
- package/dist/{chunk-PX3BSCIG.cjs → chunk-V6EYAC7X.cjs} +38 -22
- package/dist/chunk-XJNNOSJR.js +98 -0
- package/dist/chunk-YEAXE4U2.js +77 -0
- package/dist/{chunk-FF45VZMM.cjs → chunk-YHEITFHR.cjs} +56 -46
- package/dist/{emit-order-notification-trigger-ZRRGCQGB.cjs → emit-order-notification-trigger-DR74TQXN.cjs} +4 -4
- package/dist/{emit-order-notification-trigger-MFCBAE7L.js → emit-order-notification-trigger-UCKJHDQK.js} +2 -2
- package/dist/index.cjs +224 -224
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +8 -8
- package/dist/{order-completion-otp-handlers-3W5I3LON.js → order-completion-otp-handlers-CH22ZRAI.js} +2 -2
- package/dist/{order-completion-otp-handlers-RF3DLNV7.cjs → order-completion-otp-handlers-RW5RSXH3.cjs} +3 -3
- package/dist/{order-notification-dispatcher-ID2PDEXD.js → order-notification-dispatcher-3TXUAJ7L.js} +2 -2
- package/dist/{order-notification-dispatcher-RNEQB3V7.cjs → order-notification-dispatcher-Y7NZAALH.cjs} +7 -7
- package/dist/{pg-boss-service-L6MTF4EQ.cjs → pg-boss-service-BDGOKM2T.cjs} +3 -3
- package/dist/pg-boss-service-WCBJD4JB.js +2 -0
- package/package.json +1 -1
- package/dist/chunk-AYWDQFJZ.js +0 -27
- package/dist/chunk-GO7PPYNU.js +0 -76
- package/dist/chunk-UEE4PTTB.cjs +0 -30
- package/dist/chunk-XQ3QUHWR.cjs +0 -83
- package/dist/pg-boss-service-4XF2TQ2E.js +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { normalizePhoneE164, generateNumericOtp, createOtpChallenge, queueSms, verifyAndConsumeOtpChallenge } from './chunk-OVTOP42W.js';
|
|
2
|
-
import { JOB_RUNNER_QUEUE } from './chunk-
|
|
2
|
+
import { JOB_RUNNER_QUEUE } from './chunk-XJNNOSJR.js';
|
|
3
3
|
import { validateInventoryForConfirmedOrderLines, orderStatusHoldsStock, reconcileOrderInventoryBetweenSnapshots, orderInventorySnapshotFromRow, validateInventoryForOrderBecomingConfirmed } from './chunk-3K5AIEIZ.js';
|
|
4
|
-
import { resolveChatEmailToolSettings, CHAT_EMAIL_LOG, detectChatLeadIntent, parseIntentRecipientEmails, sendChatLeadEmail, buildTranscriptForLeadEmail, buildChatbotSystemPromptWithEmailTool, validateFcmCredentials, sendFcmPushNotification, parseEmailRecipientsFromConfig, isWhatsAppPluginEnabled, WhatsAppService, emailPlugin, initWhatsappTriggerDispatcher } from './chunk-
|
|
4
|
+
import { resolveChatEmailToolSettings, CHAT_EMAIL_LOG, detectChatLeadIntent, parseIntentRecipientEmails, sendChatLeadEmail, buildTranscriptForLeadEmail, buildChatbotSystemPromptWithEmailTool, validateFcmCredentials, sendFcmPushNotification, parseEmailRecipientsFromConfig, isWhatsAppPluginEnabled, WhatsAppService, emailPlugin, initWhatsappTriggerDispatcher } from './chunk-ACBN6UWZ.js';
|
|
5
5
|
import { registerWhatsAppQueueProcessor } from './chunk-GWDI752Q.js';
|
|
6
6
|
import { inviteStatusForActivation } from './chunk-JXF23MPG.js';
|
|
7
7
|
import { queueEmail, queueVendorOnboardEmails, registerEmailQueueProcessor } from './chunk-TU23GJPJ.js';
|
|
@@ -5229,7 +5229,7 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
5229
5229
|
const orderIdForNotify = created.id;
|
|
5230
5230
|
const finalCreatedStatus = String(created.status ?? createdStatus ?? "pending").toLowerCase();
|
|
5231
5231
|
const initialPayStatus = String(persistBody.paymentStatus ?? body.paymentStatus ?? "unpaid").toLowerCase();
|
|
5232
|
-
void import('./emit-order-notification-trigger-
|
|
5232
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
5233
5233
|
if (finalCreatedStatus === "pending") {
|
|
5234
5234
|
if (initialPayStatus === "failed") {
|
|
5235
5235
|
fireOrderNotificationTrigger("payment_failed", orderIdForNotify, {
|
|
@@ -6309,7 +6309,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6309
6309
|
const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
|
|
6310
6310
|
const assigneeUpdated = Boolean(rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0 && Number(rawBody.assignedUserId) > 0 && Number(rawBody.assignedUserId) !== Number(existingOrderRow?.assignedUserId));
|
|
6311
6311
|
if (assigneeUpdated) {
|
|
6312
|
-
void import('./emit-order-notification-trigger-
|
|
6312
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
6313
6313
|
fireOrderNotificationTrigger("order_assigned", updatedOrder.id, {
|
|
6314
6314
|
dataSource,
|
|
6315
6315
|
entityMap
|
|
@@ -6326,7 +6326,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6326
6326
|
const payments = Array.isArray(updatedOrder.payments) ? updatedOrder.payments : [];
|
|
6327
6327
|
const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
|
|
6328
6328
|
const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
|
|
6329
|
-
void import('./emit-order-notification-trigger-
|
|
6329
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
6330
6330
|
if (newStatus === "pending") {
|
|
6331
6331
|
if (curPayStatus === "failed") {
|
|
6332
6332
|
fireOrderNotificationTrigger("payment_failed", updatedOrder.id, {
|
|
@@ -6980,7 +6980,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6980
6980
|
});
|
|
6981
6981
|
}
|
|
6982
6982
|
if (ordStatus === "pending" || ordStatus === "confirmed") {
|
|
6983
|
-
void import('./emit-order-notification-trigger-
|
|
6983
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
6984
6984
|
fireOrderNotificationTrigger("order_placed", pOrder, {
|
|
6985
6985
|
dataSource,
|
|
6986
6986
|
entityMap
|
|
@@ -6994,7 +6994,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6994
6994
|
}
|
|
6995
6995
|
}
|
|
6996
6996
|
} else if (newPayStatus === "failed") {
|
|
6997
|
-
void import('./emit-order-notification-trigger-
|
|
6997
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
6998
6998
|
fireOrderNotificationTrigger("payment_failed", pOrder, {
|
|
6999
6999
|
dataSource,
|
|
7000
7000
|
entityMap
|
|
@@ -7002,7 +7002,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
7002
7002
|
}).catch(() => {
|
|
7003
7003
|
});
|
|
7004
7004
|
} else if (newPayStatus === "refunded") {
|
|
7005
|
-
void import('./emit-order-notification-trigger-
|
|
7005
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
7006
7006
|
fireOrderNotificationTrigger("payment_refund_initiated", pOrder, {
|
|
7007
7007
|
dataSource,
|
|
7008
7008
|
entityMap
|
|
@@ -7129,7 +7129,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
7129
7129
|
const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
|
|
7130
7130
|
const assigneeUpdated = Boolean(rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0 && Number(rawBody.assignedUserId) > 0 && Number(rawBody.assignedUserId) !== Number(existingOrderRow?.assignedUserId));
|
|
7131
7131
|
if (assigneeUpdated) {
|
|
7132
|
-
void import('./emit-order-notification-trigger-
|
|
7132
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
7133
7133
|
fireOrderNotificationTrigger("order_assigned", ord.id, {
|
|
7134
7134
|
dataSource,
|
|
7135
7135
|
entityMap
|
|
@@ -7146,7 +7146,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
7146
7146
|
const payments = Array.isArray(ord.payments) ? ord.payments : [];
|
|
7147
7147
|
const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
|
|
7148
7148
|
const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
|
|
7149
|
-
void import('./emit-order-notification-trigger-
|
|
7149
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
7150
7150
|
if (newStatus === "pending") {
|
|
7151
7151
|
if (curPayStatus === "failed") {
|
|
7152
7152
|
fireOrderNotificationTrigger("payment_failed", ord.id, {
|
|
@@ -27485,7 +27485,7 @@ async function queueJobScheduleNow(cms, scheduleId) {
|
|
|
27485
27485
|
if (!boss) {
|
|
27486
27486
|
throw new Error("pg-boss is not configured (DATABASE_URL required)");
|
|
27487
27487
|
}
|
|
27488
|
-
const { JOB_RUNNER_QUEUE: JOB_RUNNER_QUEUE2 } = await import('./pg-boss-service-
|
|
27488
|
+
const { JOB_RUNNER_QUEUE: JOB_RUNNER_QUEUE2 } = await import('./pg-boss-service-WCBJD4JB.js');
|
|
27489
27489
|
await boss.send(JOB_RUNNER_QUEUE2, {
|
|
27490
27490
|
scheduleId,
|
|
27491
27491
|
triggeredBy: "manual"
|
|
@@ -30713,7 +30713,7 @@ function createCmsApiHandler(config) {
|
|
|
30713
30713
|
status: 400
|
|
30714
30714
|
});
|
|
30715
30715
|
}
|
|
30716
|
-
const { resendOrderNotification } = await import('./order-notification-dispatcher-
|
|
30716
|
+
const { resendOrderNotification } = await import('./order-notification-dispatcher-3TXUAJ7L.js');
|
|
30717
30717
|
const result = await resendOrderNotification(triggerKey, orderId, {
|
|
30718
30718
|
dataSource,
|
|
30719
30719
|
entityMap,
|
|
@@ -30812,7 +30812,7 @@ function createCmsApiHandler(config) {
|
|
|
30812
30812
|
status: "cancelled"
|
|
30813
30813
|
});
|
|
30814
30814
|
const fireOrderCancelledNotification = /* @__PURE__ */ __name((refundAmount) => {
|
|
30815
|
-
void import('./emit-order-notification-trigger-
|
|
30815
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
30816
30816
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
30817
30817
|
dataSource,
|
|
30818
30818
|
entityMap
|
|
@@ -31057,7 +31057,7 @@ function createCmsApiHandler(config) {
|
|
|
31057
31057
|
}, {
|
|
31058
31058
|
status: 400
|
|
31059
31059
|
});
|
|
31060
|
-
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-
|
|
31060
|
+
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-CH22ZRAI.js');
|
|
31061
31061
|
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
|
|
31062
31062
|
return handlers.getChannels(req, orderId);
|
|
31063
31063
|
}
|
|
@@ -31072,7 +31072,7 @@ function createCmsApiHandler(config) {
|
|
|
31072
31072
|
}, {
|
|
31073
31073
|
status: 400
|
|
31074
31074
|
});
|
|
31075
|
-
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-
|
|
31075
|
+
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-CH22ZRAI.js');
|
|
31076
31076
|
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
|
|
31077
31077
|
return handlers.sendOtp(req, orderId);
|
|
31078
31078
|
}
|
|
@@ -31087,7 +31087,7 @@ function createCmsApiHandler(config) {
|
|
|
31087
31087
|
}, {
|
|
31088
31088
|
status: 400
|
|
31089
31089
|
});
|
|
31090
|
-
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-
|
|
31090
|
+
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-CH22ZRAI.js');
|
|
31091
31091
|
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
|
|
31092
31092
|
return handlers.verifyOtp(req, orderId);
|
|
31093
31093
|
}
|
|
@@ -31719,20 +31719,26 @@ function createStorefrontApiHandler(config) {
|
|
|
31719
31719
|
const otpPepper = config.otpPepper;
|
|
31720
31720
|
const defaultPhoneCc = config.defaultPhoneCountryCode;
|
|
31721
31721
|
function fireOrderPlacedNotification(orderId, isPaid) {
|
|
31722
|
-
void import('./emit-order-notification-trigger-
|
|
31722
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
31723
31723
|
fireOrderNotificationTrigger("order_placed", orderId, {
|
|
31724
31724
|
dataSource,
|
|
31725
31725
|
entityMap
|
|
31726
|
+
}, {
|
|
31727
|
+
source: "storefront"
|
|
31726
31728
|
});
|
|
31727
31729
|
if (isPaid) {
|
|
31728
31730
|
fireOrderNotificationTrigger("payment_success", orderId, {
|
|
31729
31731
|
dataSource,
|
|
31730
31732
|
entityMap
|
|
31733
|
+
}, {
|
|
31734
|
+
source: "storefront"
|
|
31731
31735
|
});
|
|
31732
31736
|
} else {
|
|
31733
31737
|
fireOrderNotificationTrigger("payment_failed", orderId, {
|
|
31734
31738
|
dataSource,
|
|
31735
31739
|
entityMap
|
|
31740
|
+
}, {
|
|
31741
|
+
source: "storefront"
|
|
31736
31742
|
});
|
|
31737
31743
|
}
|
|
31738
31744
|
}).catch((err) => console.error("[notification-triggers] import failed", err));
|
|
@@ -34656,14 +34662,18 @@ function createStorefrontApiHandler(config) {
|
|
|
34656
34662
|
} catch {
|
|
34657
34663
|
}
|
|
34658
34664
|
try {
|
|
34659
|
-
void import('./emit-order-notification-trigger-
|
|
34665
|
+
void import('./emit-order-notification-trigger-UCKJHDQK.js').then(({ fireOrderNotificationTrigger }) => {
|
|
34660
34666
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
34661
34667
|
dataSource,
|
|
34662
34668
|
entityMap
|
|
34669
|
+
}, {
|
|
34670
|
+
source: "storefront"
|
|
34663
34671
|
});
|
|
34664
34672
|
fireOrderNotificationTrigger("payment_failed", orderId, {
|
|
34665
34673
|
dataSource,
|
|
34666
34674
|
entityMap
|
|
34675
|
+
}, {
|
|
34676
|
+
source: "storefront"
|
|
34667
34677
|
});
|
|
34668
34678
|
}).catch(() => {
|
|
34669
34679
|
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
|
|
4
|
+
|
|
5
|
+
// src/plugins/pg-boss/pg-boss-service.ts
|
|
6
|
+
var JOB_RUNNER_QUEUE = "job-runner";
|
|
7
|
+
var PgBossService = class {
|
|
8
|
+
static {
|
|
9
|
+
chunkUSNT2KNT_cjs.__name(this, "PgBossService");
|
|
10
|
+
}
|
|
11
|
+
connectionString;
|
|
12
|
+
schema;
|
|
13
|
+
boss = null;
|
|
14
|
+
bossPromise = null;
|
|
15
|
+
started = false;
|
|
16
|
+
workRegistered = /* @__PURE__ */ new Set();
|
|
17
|
+
constructor(connectionString, schema) {
|
|
18
|
+
this.connectionString = connectionString;
|
|
19
|
+
this.schema = schema?.trim() ? schema.trim() : void 0;
|
|
20
|
+
}
|
|
21
|
+
async getBoss() {
|
|
22
|
+
if (this.boss) return this.boss;
|
|
23
|
+
if (this.bossPromise) return this.bossPromise;
|
|
24
|
+
this.bossPromise = (async () => {
|
|
25
|
+
const mod = await import('pg-boss');
|
|
26
|
+
const PgBossClass = mod?.PgBoss ?? mod?.default ?? mod;
|
|
27
|
+
const instance = new PgBossClass({
|
|
28
|
+
connectionString: this.connectionString,
|
|
29
|
+
...this.schema ? {
|
|
30
|
+
schema: this.schema
|
|
31
|
+
} : {},
|
|
32
|
+
schedule: true
|
|
33
|
+
});
|
|
34
|
+
instance.on("error", (err) => {
|
|
35
|
+
console.error("[pg-boss]", err);
|
|
36
|
+
});
|
|
37
|
+
this.boss = instance;
|
|
38
|
+
return instance;
|
|
39
|
+
})();
|
|
40
|
+
return this.bossPromise;
|
|
41
|
+
}
|
|
42
|
+
async start() {
|
|
43
|
+
if (this.started) return;
|
|
44
|
+
const boss = await this.getBoss();
|
|
45
|
+
await boss.start();
|
|
46
|
+
await this.ensureQueue(JOB_RUNNER_QUEUE);
|
|
47
|
+
this.started = true;
|
|
48
|
+
}
|
|
49
|
+
async stop() {
|
|
50
|
+
if (!this.started || !this.boss) return;
|
|
51
|
+
await this.boss.stop({
|
|
52
|
+
graceful: true,
|
|
53
|
+
timeout: 1e4
|
|
54
|
+
});
|
|
55
|
+
this.started = false;
|
|
56
|
+
this.workRegistered.clear();
|
|
57
|
+
}
|
|
58
|
+
get raw() {
|
|
59
|
+
return this.boss;
|
|
60
|
+
}
|
|
61
|
+
async ensureQueue(name) {
|
|
62
|
+
const boss = await this.getBoss();
|
|
63
|
+
const existing = await boss.getQueue(name);
|
|
64
|
+
if (!existing) {
|
|
65
|
+
await boss.createQueue(name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async send(queue, data) {
|
|
69
|
+
await this.ensureQueue(queue);
|
|
70
|
+
const boss = await this.getBoss();
|
|
71
|
+
return boss.send(queue, data, {
|
|
72
|
+
retryLimit: 2
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async schedule(name, cron, data, options) {
|
|
76
|
+
await this.ensureQueue(name);
|
|
77
|
+
const boss = await this.getBoss();
|
|
78
|
+
await boss.schedule(name, cron, data, options);
|
|
79
|
+
}
|
|
80
|
+
async unschedule(name) {
|
|
81
|
+
try {
|
|
82
|
+
const boss = await this.getBoss();
|
|
83
|
+
await boss.unschedule(name);
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async registerWork(queue, handler) {
|
|
88
|
+
if (this.workRegistered.has(queue)) return;
|
|
89
|
+
await this.ensureQueue(queue);
|
|
90
|
+
const boss = await this.getBoss();
|
|
91
|
+
await boss.work(queue, async (jobs) => {
|
|
92
|
+
for (const job of jobs) {
|
|
93
|
+
await handler(job.data);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
this.workRegistered.add(queue);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
exports.JOB_RUNNER_QUEUE = JOB_RUNNER_QUEUE;
|
|
101
|
+
exports.PgBossService = PgBossService;
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkBXAKL2TF_cjs = require('./chunk-BXAKL2TF.cjs');
|
|
4
4
|
var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
|
|
5
5
|
|
|
6
6
|
// src/lib/emit-order-notification-trigger.ts
|
|
7
|
-
function maskPhone(raw) {
|
|
8
|
-
const digits = String(raw ?? "").replace(/\D/g, "");
|
|
9
|
-
if (digits.length <= 4) return "(none)";
|
|
10
|
-
return `***${digits.slice(-4)}`;
|
|
11
|
-
}
|
|
12
|
-
chunkUSNT2KNT_cjs.__name(maskPhone, "maskPhone");
|
|
13
7
|
async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
|
|
14
8
|
if (!deps.entityMap.orders) {
|
|
15
|
-
|
|
9
|
+
chunkBXAKL2TF_cjs.notifyLog.skip("TRIGGER", "orders entity missing from entityMap", {
|
|
16
10
|
triggerKey,
|
|
17
11
|
orderId
|
|
18
12
|
});
|
|
19
13
|
return;
|
|
20
14
|
}
|
|
21
|
-
const listenerCount =
|
|
15
|
+
const listenerCount = chunkBXAKL2TF_cjs.notificationTriggerEmitter.listenerCount("__any__");
|
|
22
16
|
if (listenerCount === 0) {
|
|
23
|
-
|
|
17
|
+
chunkBXAKL2TF_cjs.notifyLog.skip("TRIGGER", "no dispatcher listener \u2014 will try direct dispatch (pass getCms to createCmsApiHandler)", {
|
|
18
|
+
triggerKey,
|
|
19
|
+
orderId
|
|
20
|
+
});
|
|
24
21
|
}
|
|
25
22
|
const orderRepo = deps.dataSource.getRepository(deps.entityMap.orders);
|
|
26
23
|
const fullOrder = await orderRepo.findOne({
|
|
@@ -33,7 +30,7 @@ async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
|
|
|
33
30
|
]
|
|
34
31
|
});
|
|
35
32
|
if (!fullOrder) {
|
|
36
|
-
|
|
33
|
+
chunkBXAKL2TF_cjs.notifyLog.skip("TRIGGER", "order not found", {
|
|
37
34
|
triggerKey,
|
|
38
35
|
orderId
|
|
39
36
|
});
|
|
@@ -41,15 +38,18 @@ async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
|
|
|
41
38
|
}
|
|
42
39
|
const fo = fullOrder;
|
|
43
40
|
const phone = fo.contact?.phone ?? null;
|
|
44
|
-
|
|
41
|
+
chunkBXAKL2TF_cjs.notifyLog.trigger("emit", {
|
|
45
42
|
triggerKey,
|
|
46
43
|
orderId,
|
|
47
44
|
orderNumber: fo.orderNumber ?? null,
|
|
48
|
-
phone:
|
|
49
|
-
listeners: listenerCount
|
|
45
|
+
phone: chunkBXAKL2TF_cjs.maskNotifyPhone(phone),
|
|
46
|
+
listeners: listenerCount,
|
|
47
|
+
vendorId: fo.vendorId ?? null,
|
|
48
|
+
source: extra?.source ?? "api"
|
|
50
49
|
});
|
|
51
50
|
if (!phone?.trim()) {
|
|
52
|
-
|
|
51
|
+
chunkBXAKL2TF_cjs.notifyLog.skip("WHATSAPP", "order contact has no phone", {
|
|
52
|
+
triggerKey,
|
|
53
53
|
orderId
|
|
54
54
|
});
|
|
55
55
|
}
|
|
@@ -91,28 +91,44 @@ async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
|
|
|
91
91
|
refundAmount: resolvedRefundAmount
|
|
92
92
|
};
|
|
93
93
|
if (listenerCount === 0) {
|
|
94
|
+
chunkBXAKL2TF_cjs.notifyLog.trigger("direct dispatch (no in-process listener)", {
|
|
95
|
+
triggerKey,
|
|
96
|
+
orderId
|
|
97
|
+
});
|
|
94
98
|
try {
|
|
95
|
-
const { dispatchOrderNotificationDirectly } = await import('./order-notification-dispatcher-
|
|
99
|
+
const { dispatchOrderNotificationDirectly } = await import('./order-notification-dispatcher-Y7NZAALH.cjs');
|
|
96
100
|
await dispatchOrderNotificationDirectly(triggerKey, triggerPayload, deps.dataSource, deps.entityMap);
|
|
97
101
|
} catch (err) {
|
|
98
|
-
|
|
102
|
+
chunkBXAKL2TF_cjs.notifyLog.error("TRIGGER", "direct dispatch failed", {
|
|
99
103
|
triggerKey,
|
|
100
104
|
orderId,
|
|
101
|
-
err
|
|
105
|
+
error: err instanceof Error ? err.message : String(err),
|
|
106
|
+
stack: err instanceof Error ? err.stack : void 0
|
|
102
107
|
});
|
|
103
108
|
}
|
|
104
109
|
} else {
|
|
105
|
-
|
|
110
|
+
chunkBXAKL2TF_cjs.notifyLog.trigger("emit to dispatcher listener", {
|
|
111
|
+
triggerKey,
|
|
112
|
+
orderId,
|
|
113
|
+
listeners: listenerCount
|
|
114
|
+
});
|
|
115
|
+
chunkBXAKL2TF_cjs.notificationTriggerEmitter.emitTrigger(triggerKey, triggerPayload);
|
|
106
116
|
}
|
|
107
117
|
}
|
|
108
118
|
chunkUSNT2KNT_cjs.__name(emitOrderNotificationTrigger, "emitOrderNotificationTrigger");
|
|
109
119
|
function fireOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
|
|
110
|
-
|
|
120
|
+
chunkBXAKL2TF_cjs.notifyLog.trigger("FIRE", {
|
|
111
121
|
triggerKey,
|
|
112
|
-
orderId
|
|
122
|
+
orderId,
|
|
123
|
+
source: extra?.source ?? "api"
|
|
113
124
|
});
|
|
114
125
|
void emitOrderNotificationTrigger(triggerKey, orderId, deps, extra).catch((err) => {
|
|
115
|
-
|
|
126
|
+
chunkBXAKL2TF_cjs.notifyLog.error("TRIGGER", "fire failed", {
|
|
127
|
+
triggerKey,
|
|
128
|
+
orderId,
|
|
129
|
+
error: err instanceof Error ? err.message : String(err),
|
|
130
|
+
stack: err instanceof Error ? err.stack : void 0
|
|
131
|
+
});
|
|
116
132
|
});
|
|
117
133
|
}
|
|
118
134
|
chunkUSNT2KNT_cjs.__name(fireOrderNotificationTrigger, "fireOrderNotificationTrigger");
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
// src/plugins/pg-boss/pg-boss-service.ts
|
|
4
|
+
var JOB_RUNNER_QUEUE = "job-runner";
|
|
5
|
+
var PgBossService = class {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "PgBossService");
|
|
8
|
+
}
|
|
9
|
+
connectionString;
|
|
10
|
+
schema;
|
|
11
|
+
boss = null;
|
|
12
|
+
bossPromise = null;
|
|
13
|
+
started = false;
|
|
14
|
+
workRegistered = /* @__PURE__ */ new Set();
|
|
15
|
+
constructor(connectionString, schema) {
|
|
16
|
+
this.connectionString = connectionString;
|
|
17
|
+
this.schema = schema?.trim() ? schema.trim() : void 0;
|
|
18
|
+
}
|
|
19
|
+
async getBoss() {
|
|
20
|
+
if (this.boss) return this.boss;
|
|
21
|
+
if (this.bossPromise) return this.bossPromise;
|
|
22
|
+
this.bossPromise = (async () => {
|
|
23
|
+
const mod = await import('pg-boss');
|
|
24
|
+
const PgBossClass = mod?.PgBoss ?? mod?.default ?? mod;
|
|
25
|
+
const instance = new PgBossClass({
|
|
26
|
+
connectionString: this.connectionString,
|
|
27
|
+
...this.schema ? {
|
|
28
|
+
schema: this.schema
|
|
29
|
+
} : {},
|
|
30
|
+
schedule: true
|
|
31
|
+
});
|
|
32
|
+
instance.on("error", (err) => {
|
|
33
|
+
console.error("[pg-boss]", err);
|
|
34
|
+
});
|
|
35
|
+
this.boss = instance;
|
|
36
|
+
return instance;
|
|
37
|
+
})();
|
|
38
|
+
return this.bossPromise;
|
|
39
|
+
}
|
|
40
|
+
async start() {
|
|
41
|
+
if (this.started) return;
|
|
42
|
+
const boss = await this.getBoss();
|
|
43
|
+
await boss.start();
|
|
44
|
+
await this.ensureQueue(JOB_RUNNER_QUEUE);
|
|
45
|
+
this.started = true;
|
|
46
|
+
}
|
|
47
|
+
async stop() {
|
|
48
|
+
if (!this.started || !this.boss) return;
|
|
49
|
+
await this.boss.stop({
|
|
50
|
+
graceful: true,
|
|
51
|
+
timeout: 1e4
|
|
52
|
+
});
|
|
53
|
+
this.started = false;
|
|
54
|
+
this.workRegistered.clear();
|
|
55
|
+
}
|
|
56
|
+
get raw() {
|
|
57
|
+
return this.boss;
|
|
58
|
+
}
|
|
59
|
+
async ensureQueue(name) {
|
|
60
|
+
const boss = await this.getBoss();
|
|
61
|
+
const existing = await boss.getQueue(name);
|
|
62
|
+
if (!existing) {
|
|
63
|
+
await boss.createQueue(name);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async send(queue, data) {
|
|
67
|
+
await this.ensureQueue(queue);
|
|
68
|
+
const boss = await this.getBoss();
|
|
69
|
+
return boss.send(queue, data, {
|
|
70
|
+
retryLimit: 2
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async schedule(name, cron, data, options) {
|
|
74
|
+
await this.ensureQueue(name);
|
|
75
|
+
const boss = await this.getBoss();
|
|
76
|
+
await boss.schedule(name, cron, data, options);
|
|
77
|
+
}
|
|
78
|
+
async unschedule(name) {
|
|
79
|
+
try {
|
|
80
|
+
const boss = await this.getBoss();
|
|
81
|
+
await boss.unschedule(name);
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async registerWork(queue, handler) {
|
|
86
|
+
if (this.workRegistered.has(queue)) return;
|
|
87
|
+
await this.ensureQueue(queue);
|
|
88
|
+
const boss = await this.getBoss();
|
|
89
|
+
await boss.work(queue, async (jobs) => {
|
|
90
|
+
for (const job of jobs) {
|
|
91
|
+
await handler(job.data);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
this.workRegistered.add(queue);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export { JOB_RUNNER_QUEUE, PgBossService };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
|
|
4
|
+
var KNOWN_NOTIFICATION_TRIGGERS = {
|
|
5
|
+
ORDER_PENDING: "order_pending",
|
|
6
|
+
ORDER_PROCESSING: "order_processing",
|
|
7
|
+
ORDER_COMPLETED: "order_completed",
|
|
8
|
+
ORDER_PLACED: "order_placed",
|
|
9
|
+
ORDER_CANCELLED: "order_cancelled",
|
|
10
|
+
PAYMENT_SUCCESS: "payment_success",
|
|
11
|
+
PAYMENT_FAILED: "payment_failed",
|
|
12
|
+
PAYMENT_REFUND_INITIATED: "payment_refund_initiated"
|
|
13
|
+
};
|
|
14
|
+
var NotificationTriggerEmitter = class NotificationTriggerEmitter2 extends EventEmitter {
|
|
15
|
+
static {
|
|
16
|
+
__name(this, "NotificationTriggerEmitter");
|
|
17
|
+
}
|
|
18
|
+
emitTrigger(triggerKey, payload) {
|
|
19
|
+
this.emit("__any__", triggerKey, payload);
|
|
20
|
+
}
|
|
21
|
+
onAnyTrigger(listener) {
|
|
22
|
+
this.on("__any__", listener);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var notificationTriggerEmitter = new NotificationTriggerEmitter();
|
|
26
|
+
|
|
27
|
+
// src/lib/notify-log.ts
|
|
28
|
+
function maskTail(raw, keep = 6) {
|
|
29
|
+
const s = String(raw ?? "").trim();
|
|
30
|
+
if (!s) return "(none)";
|
|
31
|
+
if (s.length <= keep) return "***";
|
|
32
|
+
return `***${s.slice(-keep)}`;
|
|
33
|
+
}
|
|
34
|
+
__name(maskTail, "maskTail");
|
|
35
|
+
function maskNotifyPhone(raw) {
|
|
36
|
+
const digits = String(raw ?? "").replace(/\D/g, "");
|
|
37
|
+
if (digits.length <= 4) return "(none)";
|
|
38
|
+
return `***${digits.slice(-4)}`;
|
|
39
|
+
}
|
|
40
|
+
__name(maskNotifyPhone, "maskNotifyPhone");
|
|
41
|
+
function maskNotifyEmail(raw) {
|
|
42
|
+
const e = String(raw ?? "").trim();
|
|
43
|
+
if (!e || !e.includes("@")) return "(none)";
|
|
44
|
+
const [user, domain] = e.split("@");
|
|
45
|
+
const u = user.length <= 2 ? "**" : `${user.slice(0, 2)}***`;
|
|
46
|
+
return `${u}@${domain}`;
|
|
47
|
+
}
|
|
48
|
+
__name(maskNotifyEmail, "maskNotifyEmail");
|
|
49
|
+
function maskNotifyToken(raw) {
|
|
50
|
+
return maskTail(raw, 8);
|
|
51
|
+
}
|
|
52
|
+
__name(maskNotifyToken, "maskNotifyToken");
|
|
53
|
+
function write(level, channel, message, data) {
|
|
54
|
+
const banner = `========== [NOTIFY] ${channel} | ${message} ==========`;
|
|
55
|
+
const payload = data ?? {};
|
|
56
|
+
if (level === "error") {
|
|
57
|
+
console.error(`
|
|
58
|
+
${banner}`, payload);
|
|
59
|
+
} else if (level === "warn") {
|
|
60
|
+
console.warn(`
|
|
61
|
+
${banner}`, payload);
|
|
62
|
+
} else {
|
|
63
|
+
console.info(`
|
|
64
|
+
${banner}`, payload);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
__name(write, "write");
|
|
68
|
+
var notifyLog = {
|
|
69
|
+
trigger: /* @__PURE__ */ __name((message, data) => write("info", "TRIGGER", message, data), "trigger"),
|
|
70
|
+
email: /* @__PURE__ */ __name((message, data) => write("info", "EMAIL", message, data), "email"),
|
|
71
|
+
whatsapp: /* @__PURE__ */ __name((message, data) => write("info", "WHATSAPP", message, data), "whatsapp"),
|
|
72
|
+
push: /* @__PURE__ */ __name((message, data) => write("info", "PUSH", message, data), "push"),
|
|
73
|
+
skip: /* @__PURE__ */ __name((channel, message, data) => write("warn", `SKIP ${channel}`, message, data), "skip"),
|
|
74
|
+
error: /* @__PURE__ */ __name((channel, message, data) => write("error", channel, message, data), "error")
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { KNOWN_NOTIFICATION_TRIGGERS, maskNotifyEmail, maskNotifyPhone, maskNotifyToken, notificationTriggerEmitter, notifyLog };
|