@xuda.io/account_module 1.2.2251 → 1.2.2253
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 +65 -11
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -29,6 +29,11 @@ const account_info_properties = [
|
|
|
29
29
|
'active_account_profile_id',
|
|
30
30
|
'profile_avatar',
|
|
31
31
|
'profile_avatar_obj',
|
|
32
|
+
'is_xuda_network_ambassador',
|
|
33
|
+
'network_profile_url',
|
|
34
|
+
'network_lang',
|
|
35
|
+
'network_country_code',
|
|
36
|
+
'network_city_slug',
|
|
32
37
|
];
|
|
33
38
|
|
|
34
39
|
global._conf = (
|
|
@@ -162,6 +167,29 @@ export const update_account_info = async function (req, job_id, headers) {
|
|
|
162
167
|
if (key === 'country' && !validate_input(val, 55, false, false)) {
|
|
163
168
|
error[key] = 'Invalid country';
|
|
164
169
|
}
|
|
170
|
+
if (key === 'is_xuda_network_ambassador' && typeof val !== 'boolean') {
|
|
171
|
+
error[key] = 'Invalid ambassador flag';
|
|
172
|
+
}
|
|
173
|
+
if (key === 'network_profile_url') {
|
|
174
|
+
let url_ok = false;
|
|
175
|
+
try {
|
|
176
|
+
url_ok = new URL(val).protocol === 'https:';
|
|
177
|
+
} catch (_) {
|
|
178
|
+
/* invalid */
|
|
179
|
+
}
|
|
180
|
+
if (!url_ok) {
|
|
181
|
+
error[key] = 'Invalid network profile url';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (key === 'network_lang' && !/^[a-z]{2}$/.test(val)) {
|
|
185
|
+
error[key] = 'Invalid network lang';
|
|
186
|
+
}
|
|
187
|
+
if (key === 'network_country_code' && !/^[a-z]{2}$/.test(val)) {
|
|
188
|
+
error[key] = 'Invalid network country code';
|
|
189
|
+
}
|
|
190
|
+
if (key === 'network_city_slug' && !/^[a-z0-9-]{2,64}$/.test(val)) {
|
|
191
|
+
error[key] = 'Invalid network city slug';
|
|
192
|
+
}
|
|
165
193
|
}
|
|
166
194
|
}
|
|
167
195
|
|
|
@@ -1701,7 +1729,6 @@ export const get_account_rt_info = async function (uid) {
|
|
|
1701
1729
|
};
|
|
1702
1730
|
|
|
1703
1731
|
export const validate_account_topup = async function (uid, items = []) {
|
|
1704
|
-
debugger;
|
|
1705
1732
|
const { code, data } = await stripe_ms.get_billing_metrics({ uid });
|
|
1706
1733
|
if (code < 0) {
|
|
1707
1734
|
throw new Error(data);
|
|
@@ -1720,7 +1747,7 @@ export const validate_account_topup = async function (uid, items = []) {
|
|
|
1720
1747
|
}
|
|
1721
1748
|
|
|
1722
1749
|
if (data?.balance?.past_due) {
|
|
1723
|
-
let err = new Error(`past due ${data.balance.past_due
|
|
1750
|
+
let err = new Error(`past due ${data.balance.past_due}`);
|
|
1724
1751
|
err.code = -91;
|
|
1725
1752
|
err.billing_problem = true;
|
|
1726
1753
|
err.topup = topup + data.balance.past_due;
|
|
@@ -1753,9 +1780,32 @@ export const validate_account_topup = async function (uid, items = []) {
|
|
|
1753
1780
|
throw err;
|
|
1754
1781
|
}
|
|
1755
1782
|
|
|
1783
|
+
await release_account_billing_hold_if_current(uid);
|
|
1784
|
+
|
|
1756
1785
|
return true;
|
|
1757
1786
|
};
|
|
1758
1787
|
|
|
1788
|
+
const release_account_billing_hold_if_current = async function (uid) {
|
|
1789
|
+
const account_ret = await db_module.get_couch_doc('xuda_accounts', uid);
|
|
1790
|
+
if (account_ret.code < 0 || !account_ret.data?.account_billing_hold_status) {
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
const account_obj = account_ret.data;
|
|
1795
|
+
account_obj.account_billing_hold_status = 0;
|
|
1796
|
+
account_obj.account_billing_hold_date = Date.now();
|
|
1797
|
+
await db_module.save_couch_doc('xuda_accounts', account_obj);
|
|
1798
|
+
|
|
1799
|
+
ws_dashboard_msa.emit_message_to_dashboard({
|
|
1800
|
+
service: 'account_billing_hold_released',
|
|
1801
|
+
to: [uid],
|
|
1802
|
+
data: {
|
|
1803
|
+
account_billing_hold_status: 0,
|
|
1804
|
+
account_billing_hold_date: account_obj.account_billing_hold_date,
|
|
1805
|
+
},
|
|
1806
|
+
});
|
|
1807
|
+
};
|
|
1808
|
+
|
|
1759
1809
|
const get_prices = function (uid, item) {
|
|
1760
1810
|
let price;
|
|
1761
1811
|
|
|
@@ -1913,15 +1963,19 @@ export const onboarding_completed = async function (req, job_id, headers) {
|
|
|
1913
1963
|
account_doc.isBoarded = true;
|
|
1914
1964
|
const save_ret = await db_module.save_couch_doc('xuda_accounts', account_doc);
|
|
1915
1965
|
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1966
|
+
if (account_doc.account_info?.is_xuda_network_ambassador === true) {
|
|
1967
|
+
console.log('[onboarding_completed] suppressing welcome_aboard for xuda.network ambassador', uid, account_doc.account_info.email);
|
|
1968
|
+
} else {
|
|
1969
|
+
notification_msa.submit_notification({
|
|
1970
|
+
type: 'account',
|
|
1971
|
+
app_id: null,
|
|
1972
|
+
uid_arr: [uid],
|
|
1973
|
+
topic: 'welcome_aboard',
|
|
1974
|
+
params: { name: account_doc.account_info.first_name, email: account_doc.account_info.email, dashboard_url: 'https://xuda.ai/dashboard' },
|
|
1975
|
+
ref: null,
|
|
1976
|
+
email: null,
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1925
1979
|
|
|
1926
1980
|
return save_ret;
|
|
1927
1981
|
} catch (err) {
|