@xuda.io/account_module 1.2.2287 → 1.2.2288
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/index.mjs +34 -3
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -6382,6 +6382,37 @@ const _nl_ensure_storage = async () => {
|
|
|
6382
6382
|
if (save.code < 0) console.error('[newsletter] replicator ensure failed:', save.data);
|
|
6383
6383
|
};
|
|
6384
6384
|
|
|
6385
|
+
// The admin panel is served from whatever region CF routes the superuser to, but
|
|
6386
|
+
// xuda_newsletter lives on master + master2 only. So the read-side methods must
|
|
6387
|
+
// resolve MASTER's couch when running on a region (reachable over the WG hub at
|
|
6388
|
+
// 10.8.0.1), and read the local couch on master itself and on dev (standalone,
|
|
6389
|
+
// is_debug). Returns a DSN for the _custom read helpers, or null = local couch.
|
|
6390
|
+
const _nl_read_dsn = () => {
|
|
6391
|
+
if (_conf.is_debug) return null;
|
|
6392
|
+
if (process.env.XUDA_HOSTNAME === 'master.xuda.ai') return null;
|
|
6393
|
+
const m = _conf.couchdb_control_database?.['master.xuda.ai'];
|
|
6394
|
+
if (!m?.db_server_location) return null;
|
|
6395
|
+
return `${m.db_server_http}://${m.db_server_username}:${m.db_server_password}@${m.db_server_location}`;
|
|
6396
|
+
};
|
|
6397
|
+
|
|
6398
|
+
// Mango query against xuda_newsletter wherever it actually lives (master from a
|
|
6399
|
+
// region, local on master/dev). Same {docs} shape either way.
|
|
6400
|
+
const _nl_find = async (selector, extra = {}) => {
|
|
6401
|
+
const dsn = _nl_read_dsn();
|
|
6402
|
+
if (dsn) return await db_module.find_couch_query_custom(NEWSLETTER_DB, dsn, { selector, ...extra });
|
|
6403
|
+
return await db_module.find_couch_query(NEWSLETTER_DB, { selector, ...extra }, true);
|
|
6404
|
+
};
|
|
6405
|
+
|
|
6406
|
+
// Fetch one issue by _id from the same source. Returns {code, data} like
|
|
6407
|
+
// get_couch_doc so callers stay unchanged.
|
|
6408
|
+
const _nl_get = async (id) => {
|
|
6409
|
+
const dsn = _nl_read_dsn();
|
|
6410
|
+
if (!dsn) return await db_module.get_couch_doc(NEWSLETTER_DB, id);
|
|
6411
|
+
const ret = await db_module.find_couch_query_custom(NEWSLETTER_DB, dsn, { selector: { _id: id }, limit: 1 });
|
|
6412
|
+
const doc = (ret.docs || [])[0];
|
|
6413
|
+
return doc ? { code: 1, data: doc } : { code: -1, data: 'issue not found' };
|
|
6414
|
+
};
|
|
6415
|
+
|
|
6385
6416
|
// Next issue number = max(existing) + 1. Read-only projection (never PUT these).
|
|
6386
6417
|
const _nl_next_number = async () => {
|
|
6387
6418
|
try {
|
|
@@ -6811,7 +6842,7 @@ export const newsletter_generate = async function (req = {}) {
|
|
|
6811
6842
|
export const newsletter_list_issues = async function (req = {}) {
|
|
6812
6843
|
try {
|
|
6813
6844
|
if (!_ops_is_super(req)) return { code: -403, data: 'superuser only' };
|
|
6814
|
-
const ret = await
|
|
6845
|
+
const ret = await _nl_find({ docType: 'newsletter_issue' }, { limit: 500 });
|
|
6815
6846
|
const rows = (ret.docs || [])
|
|
6816
6847
|
.sort((a, b) => (b.issue_number || 0) - (a.issue_number || 0))
|
|
6817
6848
|
.map((d) => ({ id: d._id, issue_number: d.issue_number, status: d.status, subject: d.subject, created_ts: d.created_ts, published_ts: d.published_ts || null, coupon: d.content && d.content.coupon ? d.content.coupon.promo_code : null, sent: d.sent || { count: 0, failed: 0 } }));
|
|
@@ -6825,7 +6856,7 @@ export const newsletter_preview = async function (req = {}) {
|
|
|
6825
6856
|
try {
|
|
6826
6857
|
if (!_ops_is_super(req)) return { code: -403, data: 'superuser only' };
|
|
6827
6858
|
const id = req.id || `nl_issue_${req.issue_number}`;
|
|
6828
|
-
const ret = await
|
|
6859
|
+
const ret = await _nl_get(id);
|
|
6829
6860
|
if (ret.code < 0 || !ret.data) return { code: -1, data: 'issue not found' };
|
|
6830
6861
|
const host = _ops_host();
|
|
6831
6862
|
const [fpool, ppool] = await Promise.all([_nl_fashion_pool(), _nl_partner_pool()]);
|
|
@@ -6844,7 +6875,7 @@ export const newsletter_send_sample = async function (req = {}) {
|
|
|
6844
6875
|
try {
|
|
6845
6876
|
if (!_ops_is_super(req)) return { code: -403, data: 'superuser only' };
|
|
6846
6877
|
const id = req.id || `nl_issue_${req.issue_number}`;
|
|
6847
|
-
const ret = await
|
|
6878
|
+
const ret = await _nl_get(id);
|
|
6848
6879
|
if (ret.code < 0 || !ret.data) return { code: -1, data: 'issue not found' };
|
|
6849
6880
|
const to = req.email || 'info@xuda.ai';
|
|
6850
6881
|
const sr = await _newsletter_send_sample_internal(ret.data, to, req.theme);
|