@xuda.io/account_module 1.2.2052 → 1.2.2054

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