@xuda.io/account_module 1.2.2052 → 1.2.2053

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.
Files changed (2) hide show
  1. package/index_ms.mjs +78 -148
  2. package/package.json +1 -1
package/index_ms.mjs CHANGED
@@ -3,373 +3,303 @@
3
3
  // Queue target : account_module
4
4
  // =====================================================
5
5
 
6
- import amqplib from 'amqplib';
7
- import { randomUUID } from 'crypto';
8
-
9
- let queue = {};
10
-
11
- // --- AMQP Connection & Channel ---
12
- const conn = await amqplib.connect('amqp://localhost');
13
- const channel = await conn.createChannel();
14
- await channel.assertQueue(`_account_module-${global.module_in}_ch`, { durable: false });
15
-
16
- channel.consume(`_account_module-${global.module_in}_ch`, async (msg) => {
17
- try {
18
- if (msg === null) {
19
- console.log('Consumer cancelled by server');
20
- return;
21
- }
22
-
23
- const content = JSON.parse(msg.content.toString());
24
-
25
- queue[content.queue_id].resolve(content.ret);
26
-
27
- channel.ack(msg);
28
- } catch (err) {
29
- channel.ack(msg); // Acknowledge to prevent requeue loops on error
30
- console.error(module_in, content.method, err.message, err);
31
- // debugger;
32
- }
33
- });
34
-
35
- const send_to_queue = async function (ms_method, ...args) {
36
- const queue_id = randomUUID();
37
- return new Promise((resolve, reject) => {
38
- queue[queue_id] = { resolve, reject };
39
-
40
- // Set timeout to prevent hanging
41
- const timeout = setTimeout(() => {
42
- delete queue[queue_id];
43
- reject(new Error(`Queue timeout for ${ms_method}`));
44
- }, 300000); // 300 second timeout
45
-
46
- // Wrap resolve to clean up
47
- queue[queue_id].resolve = (value) => {
48
- clearTimeout(timeout);
49
- delete queue[queue_id];
50
- resolve(value);
51
- };
52
-
53
- // Wrap reject to clean up
54
- queue[queue_id].reject = (error) => {
55
- clearTimeout(timeout);
56
- delete queue[queue_id];
57
- reject(error);
58
- };
59
-
60
- try {
61
- global[`_${global.module_in}_ch`].sendToQueue(
62
- 'account_module',
63
- Buffer.from(
64
- JSON.stringify({
65
- ms_method,
66
- data: args,
67
- cb: `_account_module-${global.module_in}_ch`,
68
- queue_id,
69
- }),
70
- ),
71
- );
72
- } catch (err) {
73
- debugger;
74
- }
75
- });
76
- };
77
-
78
- // You must define this somewhere before using these wrappers:
79
- const module_name = 'account_module';
6
+ import path from 'node:path';
7
+
8
+ global.queueName = 'account_module';
9
+ const _ms_broker = await import(path.join(process.env.XUDA_HOME, 'common', 'ms_broker.mjs'));
80
10
 
81
11
  export const update_account_info = async function (...args) {
82
- return await send_to_queue('update_account_info', ...args);
12
+ return await _ms_broker.send_to_queue('update_account_info', ...args);
83
13
  };
84
14
 
85
15
  export const update_account_preferences = async function (...args) {
86
- return await send_to_queue('update_account_preferences', ...args);
16
+ return await _ms_broker.send_to_queue('update_account_preferences', ...args);
87
17
  };
88
18
 
89
19
  export const save_admin_presets = async function (...args) {
90
- return await send_to_queue('save_admin_presets', ...args);
20
+ return await _ms_broker.send_to_queue('save_admin_presets', ...args);
91
21
  };
92
22
 
93
23
  export const increment_account_usage = async function (...args) {
94
- return await send_to_queue('increment_account_usage', ...args);
24
+ return await _ms_broker.send_to_queue('increment_account_usage', ...args);
95
25
  };
96
26
 
97
27
  export const get_account_data = async function (...args) {
98
- return await send_to_queue('get_account_data', ...args);
28
+ return await _ms_broker.send_to_queue('get_account_data', ...args);
99
29
  };
100
30
 
101
31
  export const get_account_projects = async function (...args) {
102
- return await send_to_queue('get_account_projects', ...args);
32
+ return await _ms_broker.send_to_queue('get_account_projects', ...args);
103
33
  };
104
34
 
105
35
  export const get_account_datacenters = async function (...args) {
106
- return await send_to_queue('get_account_datacenters', ...args);
36
+ return await _ms_broker.send_to_queue('get_account_datacenters', ...args);
107
37
  };
108
38
 
109
39
  export const get_account_deployments = async function (...args) {
110
- return await send_to_queue('get_account_deployments', ...args);
40
+ return await _ms_broker.send_to_queue('get_account_deployments', ...args);
111
41
  };
112
42
 
113
43
  export const get_account_instances = async function (...args) {
114
- return await send_to_queue('get_account_instances', ...args);
44
+ return await _ms_broker.send_to_queue('get_account_instances', ...args);
115
45
  };
116
46
 
117
47
  export const get_account_info = async function (...args) {
118
- return await send_to_queue('get_account_info', ...args);
48
+ return await _ms_broker.send_to_queue('get_account_info', ...args);
119
49
  };
120
50
 
121
51
  export const get_active_account_profile_info = async function (...args) {
122
- return await send_to_queue('get_active_account_profile_info', ...args);
52
+ return await _ms_broker.send_to_queue('get_active_account_profile_info', ...args);
123
53
  };
124
54
 
125
55
  export const get_account_name = async function (...args) {
126
- return await send_to_queue('get_account_name', ...args);
56
+ return await _ms_broker.send_to_queue('get_account_name', ...args);
127
57
  };
128
58
 
129
59
  export const account_validate_username = async function (...args) {
130
- return await send_to_queue('account_validate_username', ...args);
60
+ return await _ms_broker.send_to_queue('account_validate_username', ...args);
131
61
  };
132
62
 
133
63
  export const verify_account = async function (...args) {
134
- return await send_to_queue('verify_account', ...args);
64
+ return await _ms_broker.send_to_queue('verify_account', ...args);
135
65
  };
136
66
 
137
67
  export const validate_user_plan = async function (...args) {
138
- return await send_to_queue('validate_user_plan', ...args);
68
+ return await _ms_broker.send_to_queue('validate_user_plan', ...args);
139
69
  };
140
70
 
141
71
  export const get_hosting_plan = async function (...args) {
142
- return await send_to_queue('get_hosting_plan', ...args);
72
+ return await _ms_broker.send_to_queue('get_hosting_plan', ...args);
143
73
  };
144
74
 
145
75
  export const get_cpu = async function (...args) {
146
- return await send_to_queue('get_cpu', ...args);
76
+ return await _ms_broker.send_to_queue('get_cpu', ...args);
147
77
  };
148
78
 
149
79
  export const add_account_log_util = async function (...args) {
150
- return await send_to_queue('add_account_log_util', ...args);
80
+ return await _ms_broker.send_to_queue('add_account_log_util', ...args);
151
81
  };
152
82
 
153
83
  export const save_ssh_key = async function (...args) {
154
- return await send_to_queue('save_ssh_key', ...args);
84
+ return await _ms_broker.send_to_queue('save_ssh_key', ...args);
155
85
  };
156
86
 
157
87
  export const delete_ssh_key = async function (...args) {
158
- return await send_to_queue('delete_ssh_key', ...args);
88
+ return await _ms_broker.send_to_queue('delete_ssh_key', ...args);
159
89
  };
160
90
 
161
91
  export const get_ssh_keys = async function (...args) {
162
- return await send_to_queue('get_ssh_keys', ...args);
92
+ return await _ms_broker.send_to_queue('get_ssh_keys', ...args);
163
93
  };
164
94
 
165
95
  export const search_users = async function (...args) {
166
- return await send_to_queue('search_users', ...args);
96
+ return await _ms_broker.send_to_queue('search_users', ...args);
167
97
  };
168
98
 
169
99
  export const find_contact_duplicates = async function (...args) {
170
- return await send_to_queue('find_contact_duplicates', ...args);
100
+ return await _ms_broker.send_to_queue('find_contact_duplicates', ...args);
171
101
  };
172
102
 
173
103
  export const merge_contact = async function (...args) {
174
- return await send_to_queue('merge_contact', ...args);
104
+ return await _ms_broker.send_to_queue('merge_contact', ...args);
175
105
  };
176
106
 
177
107
  export const get_contact_info = async function (...args) {
178
- return await send_to_queue('get_contact_info', ...args);
108
+ return await _ms_broker.send_to_queue('get_contact_info', ...args);
179
109
  };
180
110
 
181
111
  export const get_pending_contact_out = async function (...args) {
182
- return await send_to_queue('get_pending_contact_out', ...args);
112
+ return await _ms_broker.send_to_queue('get_pending_contact_out', ...args);
183
113
  };
184
114
 
185
115
  export const get_pending_contact_in = async function (...args) {
186
- return await send_to_queue('get_pending_contact_in', ...args);
116
+ return await _ms_broker.send_to_queue('get_pending_contact_in', ...args);
187
117
  };
188
118
 
189
119
  export const get_pending_share_contact_in = async function (...args) {
190
- return await send_to_queue('get_pending_share_contact_in', ...args);
120
+ return await _ms_broker.send_to_queue('get_pending_share_contact_in', ...args);
191
121
  };
192
122
 
193
123
  export const update_contact = async function (...args) {
194
- return await send_to_queue('update_contact', ...args);
124
+ return await _ms_broker.send_to_queue('update_contact', ...args);
195
125
  };
196
126
 
197
127
  export const get_account_rt_info = async function (...args) {
198
- return await send_to_queue('get_account_rt_info', ...args);
128
+ return await _ms_broker.send_to_queue('get_account_rt_info', ...args);
199
129
  };
200
130
 
201
131
  export const validate_account_topup = async function (...args) {
202
- return await send_to_queue('validate_account_topup', ...args);
132
+ return await _ms_broker.send_to_queue('validate_account_topup', ...args);
203
133
  };
204
134
 
205
135
  export const create_account_oauth_link = async function (...args) {
206
- return await send_to_queue('create_account_oauth_link', ...args);
136
+ return await _ms_broker.send_to_queue('create_account_oauth_link', ...args);
207
137
  };
208
138
 
209
139
  export const get_default_project_account_doc = async function (...args) {
210
- return await send_to_queue('get_default_project_account_doc', ...args);
140
+ return await _ms_broker.send_to_queue('get_default_project_account_doc', ...args);
211
141
  };
212
142
 
213
143
  export const get_account_default_project_id = async function (...args) {
214
- return await send_to_queue('get_account_default_project_id', ...args);
144
+ return await _ms_broker.send_to_queue('get_account_default_project_id', ...args);
215
145
  };
216
146
 
217
147
  export const get_user_name = async function (...args) {
218
- return await send_to_queue('get_user_name', ...args);
148
+ return await _ms_broker.send_to_queue('get_user_name', ...args);
219
149
  };
220
150
 
221
151
  export const get_user_card = async function (...args) {
222
- return await send_to_queue('get_user_card', ...args);
152
+ return await _ms_broker.send_to_queue('get_user_card', ...args);
223
153
  };
224
154
 
225
155
  export const onboarding_completed = async function (...args) {
226
- return await send_to_queue('onboarding_completed', ...args);
156
+ return await _ms_broker.send_to_queue('onboarding_completed', ...args);
227
157
  };
228
158
 
229
159
  export const ts_contact = async function (...args) {
230
- return await send_to_queue('ts_contact', ...args);
160
+ return await _ms_broker.send_to_queue('ts_contact', ...args);
231
161
  };
232
162
 
233
163
  export const get_account_ai_usage = async function (...args) {
234
- return await send_to_queue('get_account_ai_usage', ...args);
164
+ return await _ms_broker.send_to_queue('get_account_ai_usage', ...args);
235
165
  };
236
166
 
237
167
  export const add_contact = async function (...args) {
238
- return await send_to_queue('add_contact', ...args);
168
+ return await _ms_broker.send_to_queue('add_contact', ...args);
239
169
  };
240
170
 
241
171
  export const get_contacts = async function (...args) {
242
- return await send_to_queue('get_contacts', ...args);
172
+ return await _ms_broker.send_to_queue('get_contacts', ...args);
243
173
  };
244
174
 
245
175
  export const archive_contact = async function (...args) {
246
- return await send_to_queue('archive_contact', ...args);
176
+ return await _ms_broker.send_to_queue('archive_contact', ...args);
247
177
  };
248
178
 
249
179
  export const delete_contact = async function (...args) {
250
- return await send_to_queue('delete_contact', ...args);
180
+ return await _ms_broker.send_to_queue('delete_contact', ...args);
251
181
  };
252
182
 
253
183
  export const unarchive_contact = async function (...args) {
254
- return await send_to_queue('unarchive_contact', ...args);
184
+ return await _ms_broker.send_to_queue('unarchive_contact', ...args);
255
185
  };
256
186
 
257
187
  export const unfriend_contact = async function (...args) {
258
- return await send_to_queue('unfriend_contact', ...args);
188
+ return await _ms_broker.send_to_queue('unfriend_contact', ...args);
259
189
  };
260
190
 
261
191
  export const pin_contact = async function (...args) {
262
- return await send_to_queue('pin_contact', ...args);
192
+ return await _ms_broker.send_to_queue('pin_contact', ...args);
263
193
  };
264
194
 
265
195
  export const set_contact_deep_research = async function (...args) {
266
- return await send_to_queue('set_contact_deep_research', ...args);
196
+ return await _ms_broker.send_to_queue('set_contact_deep_research', ...args);
267
197
  };
268
198
 
269
199
  export const unpin_contact = async function (...args) {
270
- return await send_to_queue('unpin_contact', ...args);
200
+ return await _ms_broker.send_to_queue('unpin_contact', ...args);
271
201
  };
272
202
 
273
203
  export const not_spam_contact = async function (...args) {
274
- return await send_to_queue('not_spam_contact', ...args);
204
+ return await _ms_broker.send_to_queue('not_spam_contact', ...args);
275
205
  };
276
206
 
277
207
  export const generate_contact_avatar = async function (...args) {
278
- return await send_to_queue('generate_contact_avatar', ...args);
208
+ return await _ms_broker.send_to_queue('generate_contact_avatar', ...args);
279
209
  };
280
210
 
281
211
  export const set_deep_research_contact = async function (...args) {
282
- return await send_to_queue('set_deep_research_contact', ...args);
212
+ return await _ms_broker.send_to_queue('set_deep_research_contact', ...args);
283
213
  };
284
214
 
285
215
  export const unset_deep_research_contact = async function (...args) {
286
- return await send_to_queue('unset_deep_research_contact', ...args);
216
+ return await _ms_broker.send_to_queue('unset_deep_research_contact', ...args);
287
217
  };
288
218
 
289
219
  export const get_pending_share_profile_in = async function (...args) {
290
- return await send_to_queue('get_pending_share_profile_in', ...args);
220
+ return await _ms_broker.send_to_queue('get_pending_share_profile_in', ...args);
291
221
  };
292
222
 
293
223
  export const get_account_profile_info = async function (...args) {
294
- return await send_to_queue('get_account_profile_info', ...args);
224
+ return await _ms_broker.send_to_queue('get_account_profile_info', ...args);
295
225
  };
296
226
 
297
227
  export const get_account_profiles = async function (...args) {
298
- return await send_to_queue('get_account_profiles', ...args);
228
+ return await _ms_broker.send_to_queue('get_account_profiles', ...args);
299
229
  };
300
230
 
301
231
  export const archive_account_profile = async function (...args) {
302
- return await send_to_queue('archive_account_profile', ...args);
232
+ return await _ms_broker.send_to_queue('archive_account_profile', ...args);
303
233
  };
304
234
 
305
235
  export const delete_account_profile = async function (...args) {
306
- return await send_to_queue('delete_account_profile', ...args);
236
+ return await _ms_broker.send_to_queue('delete_account_profile', ...args);
307
237
  };
308
238
 
309
239
  export const unarchive_account_profile = async function (...args) {
310
- return await send_to_queue('unarchive_account_profile', ...args);
240
+ return await _ms_broker.send_to_queue('unarchive_account_profile', ...args);
311
241
  };
312
242
 
313
243
  export const create_account_profile = async function (...args) {
314
- return await send_to_queue('create_account_profile', ...args);
244
+ return await _ms_broker.send_to_queue('create_account_profile', ...args);
315
245
  };
316
246
 
317
247
  export const update_account_profile = async function (...args) {
318
- return await send_to_queue('update_account_profile', ...args);
248
+ return await _ms_broker.send_to_queue('update_account_profile', ...args);
319
249
  };
320
250
 
321
251
  export const update_entity_account_profiles = async function (...args) {
322
- return await send_to_queue('update_entity_account_profiles', ...args);
252
+ return await _ms_broker.send_to_queue('update_entity_account_profiles', ...args);
323
253
  };
324
254
 
325
255
  export const get_contact = async function (...args) {
326
- return await send_to_queue('get_contact', ...args);
256
+ return await _ms_broker.send_to_queue('get_contact', ...args);
327
257
  };
328
258
 
329
259
  export const save_contact = async function (...args) {
330
- return await send_to_queue('save_contact', ...args);
260
+ return await _ms_broker.send_to_queue('save_contact', ...args);
331
261
  };
332
262
 
333
263
  export const find_contact_query = async function (...args) {
334
- return await send_to_queue('find_contact_query', ...args);
264
+ return await _ms_broker.send_to_queue('find_contact_query', ...args);
335
265
  };
336
266
 
337
267
  export const delete_xuda_cache = async function (...args) {
338
- return await send_to_queue('delete_xuda_cache', ...args);
268
+ return await _ms_broker.send_to_queue('delete_xuda_cache', ...args);
339
269
  };
340
270
 
341
271
  export const save_xuda_cache = async function (...args) {
342
- return await send_to_queue('save_xuda_cache', ...args);
272
+ return await _ms_broker.send_to_queue('save_xuda_cache', ...args);
343
273
  };
344
274
 
345
275
  export const get_xuda_cache = async function (...args) {
346
- return await send_to_queue('get_xuda_cache', ...args);
276
+ return await _ms_broker.send_to_queue('get_xuda_cache', ...args);
347
277
  };
348
278
 
349
279
  export const save_cache_hit = async function (...args) {
350
- return await send_to_queue('save_cache_hit', ...args);
280
+ return await _ms_broker.send_to_queue('save_cache_hit', ...args);
351
281
  };
352
282
 
353
283
  export const record_ai_usage = async function (...args) {
354
- return await send_to_queue('record_ai_usage', ...args);
284
+ return await _ms_broker.send_to_queue('record_ai_usage', ...args);
355
285
  };
356
286
 
357
287
  export const record_ai_credit = async function (...args) {
358
- return await send_to_queue('record_ai_credit', ...args);
288
+ return await _ms_broker.send_to_queue('record_ai_credit', ...args);
359
289
  };
360
290
 
361
291
  export const add_ai_credits_to_active_accounts = async function (...args) {
362
- return await send_to_queue('add_ai_credits_to_active_accounts', ...args);
292
+ return await _ms_broker.send_to_queue('add_ai_credits_to_active_accounts', ...args);
363
293
  };
364
294
 
365
295
  export const archive_expire_ai_credits = async function (...args) {
366
- return await send_to_queue('archive_expire_ai_credits', ...args);
296
+ return await _ms_broker.send_to_queue('archive_expire_ai_credits', ...args);
367
297
  };
368
298
 
369
299
  export const read_accounts_emails = async function (...args) {
370
- return await send_to_queue('read_accounts_emails', ...args);
300
+ return await _ms_broker.send_to_queue('read_accounts_emails', ...args);
371
301
  };
372
302
 
373
303
  export const process_accounts_emails = async function (...args) {
374
- return await send_to_queue('process_accounts_emails', ...args);
304
+ return await _ms_broker.send_to_queue('process_accounts_emails', ...args);
375
305
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.2052",
3
+ "version": "1.2.2053",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {