hrmndev commited on
Commit
ce20ef2
·
verified ·
1 Parent(s): 78c74d6

Upload dna.js

Browse files
Files changed (1) hide show
  1. dna.js +922 -0
dna.js ADDED
@@ -0,0 +1,922 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const soap = require('strong-soap').soap;
2
+ const axios = require('axios');
3
+ const crypto = require('crypto');
4
+ const fs = require('fs');
5
+
6
+ class DomainNameAPI {
7
+ static VERSION = '2.0.13';
8
+
9
+ constructor(
10
+ userName = 'ownername', password = 'ownerpass', testMode = false) {
11
+ this.serviceUsername = userName;
12
+ this.servicePassword = password;
13
+ this.serviceUrl = 'https://whmcs.domainnameapi.com/DomainApi.svc?singlewsdl';
14
+ this.soapClientPromise = this.createSoapClient();
15
+ }
16
+
17
+ createSoapClient() {
18
+ return new Promise((resolve, reject) => {
19
+ const options = {
20
+ strictSSL : false,
21
+ wsdl_options: {
22
+ timeout: 20000,
23
+ },
24
+ };
25
+
26
+ soap.createClient(this.serviceUrl, options, (err, client) => {
27
+ if (err) {
28
+ console.error('SOAP Client Creation Error:', err);
29
+ reject(new Error(`SOAP Connection Error: ${err.message}`));
30
+ }
31
+ else {
32
+ resolve(client);
33
+ }
34
+ });
35
+ });
36
+ }
37
+
38
+ async AddChildNameServer(domainName, nameServer, ipAddress) {
39
+ const parameters = {
40
+ request: {
41
+ Password: this.servicePassword,
42
+ UserName: this.serviceUsername,
43
+ DomainName: domainName,
44
+ ChildNameServer: nameServer,
45
+ IpAddressList: [ipAddress]
46
+ }
47
+ };
48
+
49
+ // callApiFunction ile API çağrısı yapıyoruz
50
+ return this.callApiFunction('AddChildNameServer', parameters).then((response) => {
51
+ return {
52
+ data: {
53
+ NameServer: parameters.request.ChildNameServer,
54
+ IPAdresses: parameters.request.IpAddressList
55
+ },
56
+ result: true
57
+ };
58
+ });
59
+ }
60
+
61
+
62
+ /**
63
+ * Delete Child Name Server for domain
64
+ * @param {string} domainName
65
+ * @param {string} nameServer
66
+ * @return {Promise<Object>}
67
+ */
68
+ async DeleteChildNameServer(domainName, nameServer) {
69
+ const parameters = {
70
+ request: {
71
+ Password: this.servicePassword,
72
+ UserName: this.serviceUsername,
73
+ DomainName: domainName,
74
+ ChildNameServer: nameServer
75
+ }
76
+ };
77
+
78
+ // callApiFunction ile API çağrısı yapıyoruz
79
+ return this.callApiFunction('DeleteChildNameServer', parameters).then((response) => {
80
+ return {
81
+ data: {
82
+ NameServer: parameters.request.ChildNameServer
83
+ },
84
+ result: true
85
+ };
86
+ });
87
+ }
88
+
89
+
90
+ /**
91
+ * Modify Child Name Server for domain
92
+ * @param {string} domainName
93
+ * @param {string} nameServer
94
+ * @param {string} ipAddress
95
+ * @return {Promise<Object>}
96
+ */
97
+ async ModifyChildNameServer(domainName, nameServer, ipAddress) {
98
+ const parameters = {
99
+ request: {
100
+ Password: this.servicePassword,
101
+ UserName: this.serviceUsername,
102
+ DomainName: domainName,
103
+ ChildNameServer: nameServer,
104
+ IpAddressList: [ipAddress]
105
+ }
106
+ };
107
+
108
+ // callApiFunction ile API çağrısı yapıyoruz
109
+ return this.callApiFunction('ModifyChildNameServer', parameters).then((response) => {
110
+ return {
111
+ data: {
112
+ NameServer: parameters.request.ChildNameServer,
113
+ IPAdresses: parameters.request.IpAddressList
114
+ },
115
+ result: true
116
+ };
117
+ });
118
+ }
119
+
120
+ /**
121
+ * Get Contacts for domain, Administrative, Billing, Technical, Registrant
122
+ * segments will be returned
123
+ * @param {string} domainName
124
+ * @return {Promise<Object>}
125
+ */
126
+ async GetContacts(domainName) {
127
+ const parameters = {
128
+ request: {
129
+ Password: this.servicePassword,
130
+ UserName: this.serviceUsername,
131
+ DomainName: domainName
132
+ }
133
+ };
134
+
135
+ return this.callApiFunction('GetContacts', parameters).then((response) => {
136
+ const data = response[Object.keys(response)[0]];
137
+
138
+ let result = {};
139
+
140
+ // Eğer ContactInfo geçerli bir nesne ise
141
+ if (data.AdministrativeContact && typeof data.AdministrativeContact === 'object' &&
142
+ data.TechnicalContact && typeof data.TechnicalContact === 'object' &&
143
+ data.RegistrantContact && typeof data.RegistrantContact === 'object' &&
144
+ data.BillingContact && typeof data.BillingContact === 'object') {
145
+
146
+ result = {
147
+ data: {
148
+ contacts: {
149
+ Administrative: this.parseContactInfo(data.AdministrativeContact),
150
+ Billing: this.parseContactInfo(data.BillingContact),
151
+ Registrant: this.parseContactInfo(data.RegistrantContact),
152
+ Technical: this.parseContactInfo(data.TechnicalContact),
153
+ }
154
+ },
155
+ result: true
156
+ };
157
+ } else {
158
+ result = data;
159
+ }
160
+
161
+ return result;
162
+ });
163
+ }
164
+
165
+ /**
166
+ * Save Contacts for domain, Contacts segments will be saved as Administrative,
167
+ * Billing, Technical, Registrant.
168
+ * @param {string} domainName
169
+ * @param {Object} contacts
170
+ * @return {Promise<Object>}
171
+ */
172
+ async SaveContacts(domainName, contacts) {
173
+ const parameters = {
174
+ request: {
175
+ Password: this.servicePassword,
176
+ UserName: this.serviceUsername,
177
+ DomainName: domainName,
178
+ AdministrativeContact: contacts.Administrative,
179
+ BillingContact: contacts.Billing,
180
+ TechnicalContact: contacts.Technical,
181
+ RegistrantContact: contacts.Registrant
182
+ }
183
+ };
184
+
185
+ return this.callApiFunction('SaveContacts', parameters).then((response) => {
186
+ const data = response[Object.keys(response)[0]];
187
+
188
+ let result = {};
189
+
190
+ if (data.OperationResult === 'SUCCESS') {
191
+ result = {
192
+ result: true
193
+ };
194
+ } else {
195
+ // Hata durumunu ayarla
196
+ result = data;
197
+
198
+ }
199
+
200
+ return result;
201
+ });
202
+ }
203
+
204
+
205
+ /**
206
+ * Transfer domain with EPP code and period
207
+ * @param {string} domainName
208
+ * @param {string} eppCode
209
+ * @param {string} period
210
+ * @return {Promise<Object>}
211
+ */
212
+ async Transfer(domainName, eppCode, period) {
213
+ const parameters = {
214
+ request: {
215
+ Password: this.servicePassword,
216
+ UserName: this.serviceUsername,
217
+ DomainName: domainName,
218
+ AuthCode: eppCode,
219
+ AdditionalAttributes: {
220
+ KeyValueOfstringstring: [
221
+ {
222
+ Key: 'TRANSFERPERIOD',
223
+ Value: period
224
+ }
225
+ ]
226
+ }
227
+ }
228
+ };
229
+
230
+ return this.callApiFunction('Transfer', parameters).then((response) => {
231
+ const data = response[Object.keys(response)[0]];
232
+ let result = {};
233
+
234
+ // Eğer DomainInfo geçerli bir nesne ise
235
+ if (data.DomainInfo && typeof data.DomainInfo === 'object') {
236
+ // Domain bilgisini ayrıştır ve döndür
237
+ result = {
238
+ result: true,
239
+ data: this.parseDomainInfo(data.DomainInfo)
240
+ };
241
+ } else {
242
+ // Hata durumunu ayarla
243
+ result = data;
244
+ }
245
+
246
+ return result;
247
+ });
248
+ }
249
+
250
+
251
+ /**
252
+ * Stops Incoming Transfer
253
+ * @param {string} domainName
254
+ * @return {Promise<Object>}
255
+ */
256
+ async CancelTransfer(domainName) {
257
+ const parameters = {
258
+ request: {
259
+ Password: this.servicePassword,
260
+ UserName: this.serviceUsername,
261
+ DomainName: domainName
262
+ }
263
+ };
264
+
265
+ return this.callApiFunction('CancelTransfer', parameters).then((response) => {
266
+ const data = response[Object.keys(response)[0]];
267
+
268
+ return {
269
+ result: data.result ,
270
+ data: {
271
+ DomainName: parameters.request.DomainName
272
+ }
273
+ };
274
+ });
275
+ }
276
+
277
+
278
+
279
+ /**
280
+ * Approve Outgoing transfer
281
+ * @param {string} domainName
282
+ * @return {Promise<Object>}
283
+ */
284
+ async ApproveTransfer(domainName) {
285
+ const parameters = {
286
+ request: {
287
+ Password: this.servicePassword,
288
+ UserName: this.serviceUsername,
289
+ DomainName: domainName
290
+ }
291
+ };
292
+
293
+ return this.callApiFunction('ApproveTransfer', parameters).then((response) => {
294
+ const data = response[Object.keys(response)[0]];
295
+
296
+ return {
297
+ result: data.result,
298
+ data: {
299
+ DomainName: parameters.request.DomainName
300
+ }
301
+ };
302
+ });
303
+ }
304
+
305
+
306
+ /**
307
+ * Reject Outgoing transfer
308
+ * @param {string} domainName
309
+ * @return {Promise<Object>}
310
+ */
311
+ async RejectTransfer(domainName) {
312
+ const parameters = {
313
+ request: {
314
+ Password: this.servicePassword,
315
+ UserName: this.serviceUsername,
316
+ DomainName: domainName
317
+ }
318
+ };
319
+
320
+ return this.callApiFunction('RejectTransfer', parameters).then((response) => {
321
+ const data = response[Object.keys(response)[0]];
322
+
323
+ return {
324
+ result: data.result,
325
+ data: {
326
+ DomainName: parameters.request.DomainName
327
+ }
328
+ };
329
+ });
330
+ }
331
+
332
+
333
+
334
+
335
+ /**
336
+ * Renew domain
337
+ * @param {string} domainName
338
+ * @param {number} period
339
+ * @return {Promise<Object>}
340
+ */
341
+ async Renew(domainName, period) {
342
+ const parameters = {
343
+ request: {
344
+ Password: this.servicePassword,
345
+ UserName: this.serviceUsername,
346
+ DomainName: domainName,
347
+ Period: period
348
+ }
349
+ };
350
+
351
+ return this.callApiFunction('Renew', parameters).then((response) => {
352
+ const data = response[Object.keys(response)[0]];
353
+
354
+ if (data.ExpirationDate) {
355
+ return {
356
+ result: true,
357
+ data: {
358
+ ExpirationDate: data.ExpirationDate
359
+ }
360
+ };
361
+ } else {
362
+ return data;
363
+ }
364
+ });
365
+ }
366
+
367
+
368
+ /**
369
+ * Register domain with contact information
370
+ * @param {string} domainName
371
+ * @param {number} period
372
+ * @param {Object} contacts
373
+ * @param {Array<string>} nameServers
374
+ * @param {boolean} eppLock
375
+ * @param {boolean} privacyLock
376
+ * @param {Object} additionalAttributes
377
+ * @return {Promise<Object>}
378
+ */
379
+ async RegisterWithContactInfo(domainName, period, contacts, nameServers = ["dns.domainnameapi.com", "web.domainnameapi.com"], eppLock = true, privacyLock = false, additionalAttributes = {}) {
380
+ const parameters = {
381
+ request: {
382
+ Password: this.servicePassword,
383
+ UserName: this.serviceUsername,
384
+ DomainName: domainName,
385
+ Period: period,
386
+ NameServerList: {
387
+ string: nameServers
388
+ },
389
+ LockStatus: eppLock,
390
+ PrivacyProtectionStatus: privacyLock,
391
+ AdministrativeContact: contacts.Administrative,
392
+ BillingContact: contacts.Billing,
393
+ TechnicalContact: contacts.Technical,
394
+ RegistrantContact: contacts.Registrant
395
+ }
396
+ };
397
+
398
+ // Format AdditionalAttributes correctly
399
+ if (Object.keys(additionalAttributes).length > 0) {
400
+ parameters.request.AdditionalAttributes = {
401
+ KeyValueOfstringstring: Object.entries(additionalAttributes).map(([key, value]) => ({
402
+ Key: key,
403
+ Value: value
404
+ }))
405
+ };
406
+ }
407
+
408
+ // API çağrısı yap ve yanıtı işle
409
+ return this.callApiFunction('RegisterWithContactInfo', parameters).then((response) => {
410
+ // Handle raw number response
411
+ if (typeof response === 'number') {
412
+ return {
413
+ result: false,
414
+ level: 'error',
415
+ message: `Registration failed with code ${response}`,
416
+ ErrorCode: response
417
+ };
418
+ }
419
+
420
+ const data = response;
421
+ let result = {};
422
+
423
+ // Eğer DomainInfo geçerli bir nesne ise
424
+ if (data.DomainInfo && typeof data.DomainInfo === 'object') {
425
+ result = {
426
+ result: true,
427
+ data: this.parseDomainInfo(data.DomainInfo)
428
+ };
429
+ } else {
430
+ // Hata durumunu ayarla
431
+ result = {
432
+ result: false,
433
+ level: 'error',
434
+ message: data.OperationMessage || 'Registration failed',
435
+ ErrorCode: data.ErrorCode || response
436
+ };
437
+ }
438
+
439
+ return result;
440
+ });
441
+ }
442
+
443
+
444
+ /**
445
+ * Modify privacy protection status of domain
446
+ * @param {string} domainName
447
+ * @param {boolean} status
448
+ * @param {string} [reason="Owner request"]
449
+ * @return {Promise<Object>}
450
+ */
451
+ async ModifyPrivacyProtectionStatus(domainName, status, reason = "Owner request") {
452
+ // Eğer reason boşsa varsayılan değeri ayarla
453
+ if (reason.trim() === "") {
454
+ reason = "Owner request";
455
+ }
456
+
457
+ const parameters = {
458
+ request: {
459
+ Password: this.servicePassword,
460
+ UserName: this.serviceUsername,
461
+ DomainName: domainName,
462
+ ProtectPrivacy: status,
463
+ Reason: reason
464
+ }
465
+ };
466
+
467
+ // API çağrısı ve yanıt işleme
468
+ return this.callApiFunction('ModifyPrivacyProtectionStatus', parameters).then((response) => {
469
+ return {
470
+ data: {
471
+ PrivacyProtectionStatus: parameters.request.ProtectPrivacy
472
+ },
473
+ result: true
474
+ };
475
+ });
476
+ }
477
+
478
+
479
+ /**
480
+ * Sync from registry, domain information will be updated from registry
481
+ * @param {string} domainName
482
+ * @return {Promise<Object>}
483
+ */
484
+ async SyncFromRegistry(domainName) {
485
+ const parameters = {
486
+ request: {
487
+ Password: this.servicePassword,
488
+ UserName: this.serviceUsername,
489
+ DomainName: domainName
490
+ }
491
+ };
492
+
493
+ // API çağrısı ve yanıt işleme
494
+ return this.callApiFunction('SyncFromRegistry', parameters).then((response) => {
495
+ const data = response;
496
+
497
+ let result = {};
498
+
499
+ // Eğer DomainInfo geçerli bir nesne ise
500
+ if (data.DomainInfo && typeof data.DomainInfo === 'object') {
501
+ result = {
502
+ data: this.parseDomainInfo(data.DomainInfo),
503
+ result: true
504
+ };
505
+ } else {
506
+ // Hata durumu
507
+ result = data;
508
+ }
509
+
510
+ return result;
511
+ });
512
+ }
513
+
514
+
515
+
516
+
517
+ /**
518
+ * Get Current primary Balance for your account
519
+ * @param {string|number} currencyId
520
+ * @return {Promise<Object>}
521
+ */
522
+ async GetCurrentBalance(currencyId = 2) {
523
+ if (currencyId.toString().toUpperCase() === 'USD') {
524
+ currencyId = 2;
525
+ } else if (['TRY', 'TL', '1'].includes(currencyId.toString().toUpperCase())) {
526
+ currencyId = 1;
527
+ } else {
528
+ currencyId = 2;
529
+ }
530
+
531
+ const parameters = {
532
+ request: {
533
+ Password: this.servicePassword,
534
+ UserName: this.serviceUsername,
535
+ CurrencyId: currencyId
536
+ }
537
+ };
538
+
539
+ return this.callApiFunction('GetCurrentBalance', parameters).then((response) => {
540
+ return response;
541
+ });
542
+ }
543
+
544
+
545
+ /**
546
+ * Check Availability, SLD and TLD must be in array
547
+ * @param {Array<string>} domains
548
+ * @param {Array<string>} extensions
549
+ * @param {number} period
550
+ * @param {string} command
551
+ * @return {Promise<Array<Object>>}
552
+ */
553
+ async CheckAvailability(domains, extensions, period=1, command='create') {
554
+ const parameters = {
555
+ request: {
556
+ Password : this.servicePassword,
557
+ UserName : this.serviceUsername,
558
+ DomainNameList: {
559
+ string: domains, // Array of domains
560
+ },
561
+ TldList : {
562
+ string: extensions, // Array of extensions
563
+ },
564
+ Period : period,
565
+ Commad : command,
566
+ },
567
+ };
568
+
569
+ return this.callApiFunction('CheckAvailability', parameters).then((response) => {
570
+ const data = response;
571
+ const available = [];
572
+
573
+ if (data.DomainAvailabilityInfoList?.DomainAvailabilityInfo?.Tld) {
574
+ const buffer = data.DomainAvailabilityInfoList.DomainAvailabilityInfo;
575
+ data.DomainAvailabilityInfoList = {
576
+ DomainAvailabilityInfo: [buffer]
577
+ };
578
+ }else{
579
+
580
+ }
581
+
582
+ data.DomainAvailabilityInfoList.DomainAvailabilityInfo.forEach(value => {
583
+ available.push({
584
+ TLD: value.Tld,
585
+ DomainName: value.DomainName,
586
+ Status: value.Status,
587
+ Command: value.Command,
588
+ Period: value.Period,
589
+ IsFee: value.IsFee,
590
+ Price: value.Price,
591
+ Currency: value.Currency,
592
+ Reason: value.Reason
593
+ });
594
+ });
595
+
596
+ return available;
597
+ });
598
+ }
599
+
600
+
601
+ /**
602
+ * Get Domain List of your account
603
+ * @param {Object} extraParameters
604
+ * @return {Promise<Object>}
605
+ */
606
+ async GetList(extraParameters = {}) {
607
+ const parameters = {
608
+ request: {
609
+ Password: this.servicePassword,
610
+ UserName: this.serviceUsername,
611
+ ...extraParameters
612
+ }
613
+ };
614
+
615
+ return this.callApiFunction('GetList', parameters).then((response) => {
616
+
617
+ const data = response;
618
+ let result = {};
619
+
620
+ if (data.TotalCount && Number.isInteger(data.TotalCount)) {
621
+ result.data = { domains: [] };
622
+
623
+ if (data.DomainInfoList?.DomainInfo?.Id) {
624
+ result.data.domains.push(data.DomainInfoList.DomainInfo);
625
+ } else {
626
+ data.DomainInfoList.DomainInfo.forEach(domainInfo => {
627
+ result.data.domains.push(this.parseDomainInfo(domainInfo));
628
+ });
629
+ }
630
+
631
+ result.result = true;
632
+ result.totalCount = data.TotalCount;
633
+ } else {
634
+ result= data;
635
+ }
636
+
637
+ return result;
638
+ });
639
+ }
640
+
641
+
642
+
643
+ /**
644
+ * Return tld list and pricing matrix
645
+ * @param {number} count
646
+ * @return {Promise<Object>}
647
+ */
648
+ async GetTldList(count = 20) {
649
+ const parameters = {
650
+ request: {
651
+ Password: this.servicePassword,
652
+ UserName: this.serviceUsername,
653
+ IncludePriceDefinitions: 1,
654
+ PageSize: count
655
+ }
656
+ };
657
+
658
+ return this.callApiFunction('GetTldList', parameters).then((response) => {
659
+ const data = response;
660
+ let result = {};
661
+
662
+ if (data.TldInfoList.TldInfo.length > 0) {
663
+ const extensions = data.TldInfoList.TldInfo.map(v => {
664
+ const pricing = {};
665
+ const currencies = {};
666
+
667
+ v.PriceInfoList.TldPriceInfo.forEach(vp => {
668
+ pricing[vp.TradeType.toLowerCase()] = {
669
+ [vp.Period]: vp.Price
670
+ };
671
+ currencies[vp.TradeType.toLowerCase()] = vp.CurrencyName;
672
+ });
673
+
674
+ return {
675
+ id: v.Id,
676
+ status: v.Status,
677
+ maxchar: v.MaxCharacterCount,
678
+ maxperiod: v.MaxRegistrationPeriod,
679
+ minchar: v.MinCharacterCount,
680
+ minperiod: v.MinRegistrationPeriod,
681
+ tld: v.Name,
682
+ pricing,
683
+ currencies
684
+ };
685
+ });
686
+
687
+ result = { data: extensions, result: true };
688
+ } else {
689
+ result = data
690
+ }
691
+
692
+ return result;
693
+ });
694
+ }
695
+
696
+ /**
697
+ * Get Domain details
698
+ * @param {string} domainName
699
+ * @return {Promise<Object>}
700
+ */
701
+ async GetDetails(domainName) {
702
+ const parameters = {
703
+ request: {
704
+ Password : this.servicePassword,
705
+ UserName : this.serviceUsername,
706
+ DomainName: domainName,
707
+ },
708
+ };
709
+
710
+ return this.callApiFunction('GetDetails', parameters).then((response) => {
711
+ const data = response;
712
+ let result = {};
713
+
714
+ if (data.DomainInfo && typeof data.DomainInfo === 'object') {
715
+ result.data = this.parseDomainInfo(data.DomainInfo);
716
+ result.result = true;
717
+ }
718
+ else {
719
+ result = data;
720
+ }
721
+
722
+ return result;
723
+ });
724
+ }
725
+
726
+ /**
727
+ * Get Reseller Details
728
+ * @returns {Promise<{result: boolean, name: (string|string|*), active:
729
+ * boolean, id: (string|*)}>}
730
+ * @constructor
731
+ */
732
+ async GetResellerDetails() {
733
+
734
+ const parameters = {
735
+ request: {
736
+ UserName : this.serviceUsername,
737
+ Password : this.servicePassword,
738
+ CurrencyId: 2,
739
+ },
740
+ };
741
+
742
+ return this.callApiFunction('GetResellerDetails', parameters).
743
+ then((data) => {
744
+ if (data && data.ResellerInfo) {
745
+ let resp = {
746
+ result: true,
747
+ id : data.ResellerInfo.Id,
748
+ active: data.ResellerInfo.Status === 'Active',
749
+ name : data.ResellerInfo.Name,
750
+ };
751
+
752
+ let activeCurrency = data.ResellerInfo.BalanceInfoList.BalanceInfo[0];
753
+ let balances = [];
754
+
755
+ data.ResellerInfo.BalanceInfoList.BalanceInfo.forEach((v) => {
756
+ if (v.CurrencyName === data.ResellerInfo.CurrencyInfo.Code) {
757
+ activeCurrency = v;
758
+ }
759
+
760
+ balances.push({
761
+ balance : v.Balance,
762
+ currency: v.CurrencyName,
763
+ symbol : v.CurrencySymbol,
764
+ });
765
+ });
766
+
767
+ resp.balance = activeCurrency.Balance;
768
+ resp.currency = activeCurrency.CurrencyName;
769
+ resp.symbol = activeCurrency.CurrencySymbol;
770
+ resp.balances = balances;
771
+
772
+ // Şu noktada resp objesi işleme alınabilir
773
+ return resp;
774
+ }
775
+ else {
776
+ return {result: false, ...data};
777
+ }
778
+
779
+ });
780
+ }
781
+
782
+
783
+
784
+
785
+
786
+ /**
787
+ * Parse domain information
788
+ * @param {Object} data
789
+ * @return {Object}
790
+ */
791
+ parseDomainInfo(data) {
792
+ const result = {
793
+ ID: data.Id || "",
794
+ Status: data.Status || "",
795
+ DomainName: data.DomainName || "",
796
+ AuthCode: data.Auth || "",
797
+ LockStatus: typeof data.LockStatus === "boolean" ? data.LockStatus.toString() : "",
798
+ PrivacyProtectionStatus: typeof data.PrivacyProtectionStatus === "boolean" ? data.PrivacyProtectionStatus.toString() : "",
799
+ IsChildNameServer: typeof data.IsChildNameServer === "boolean" ? data.IsChildNameServer.toString() : "",
800
+ Contacts: {
801
+ Administrative: { ID: data.AdministrativeContactId || "" },
802
+ Billing: { ID: data.BillingContactId || "" },
803
+ Technical: { ID: data.TechnicalContactId || "" },
804
+ Registrant: { ID: data.RegistrantContactId || "" }
805
+ },
806
+ Dates: {
807
+ Start: data.StartDate || "",
808
+ Expiration: data.ExpirationDate || "",
809
+ RemainingDays: data.RemainingDay || ""
810
+ },
811
+ NameServers: data.NameServerList ? (Array.isArray(data.NameServerList) ? data.NameServerList : [data.NameServerList]) : [],
812
+ Additional: (data.AdditionalAttributes && data.AdditionalAttributes.KeyValueOfstringstring) ?
813
+ (Array.isArray(data.AdditionalAttributes.KeyValueOfstringstring) ?
814
+ data.AdditionalAttributes.KeyValueOfstringstring.reduce((acc, attr) => {
815
+ if (attr.Key && attr.Value) acc[attr.Key] = attr.Value;
816
+ return acc;
817
+ }, {}) :
818
+ { [data.AdditionalAttributes.KeyValueOfstringstring.Key]: data.AdditionalAttributes.KeyValueOfstringstring.Value }) : {},
819
+ ChildNameServers: data.ChildNameServerInfo ?
820
+ (Array.isArray(data.ChildNameServerInfo) ?
821
+ data.ChildNameServerInfo.map(server => ({
822
+ ns: server.ChildNameServer || "",
823
+ ip: Array.isArray(server.IpAddress?.string) ? server.IpAddress.string : [server.IpAddress?.string || ""]
824
+ })) :
825
+ [{
826
+ ns: data.ChildNameServerInfo.ChildNameServer || "",
827
+ ip: Array.isArray(data.ChildNameServerInfo.IpAddress?.string) ? data.ChildNameServerInfo.IpAddress.string : [data.ChildNameServerInfo.IpAddress?.string || ""]
828
+ }]) : []
829
+ };
830
+
831
+ return result;
832
+ }
833
+
834
+ /**
835
+ * Parse contact information
836
+ * @param {Object} data
837
+ * @return {Object}
838
+ */
839
+ parseContactInfo(data) {
840
+ return {
841
+ ID : data.Id || '',
842
+ Status : data.Status || '',
843
+ Address : {
844
+ Line1 : data.AddressLine1 || '',
845
+ Line2 : data.AddressLine2 || '',
846
+ Line3 : data.AddressLine3 || '',
847
+ State : data.State || '',
848
+ City : data.City || '',
849
+ Country: data.Country || '',
850
+ ZipCode: data.ZipCode || '',
851
+ },
852
+ Phone : {
853
+ Number : data.Phone || '',
854
+ CountryCode: data.PhoneCountryCode || '',
855
+ },
856
+ Fax : {
857
+ Number : data.Fax || '',
858
+ CountryCode: data.FaxCountryCode || '',
859
+ },
860
+ AuthCode : data.Auth || '',
861
+ FirstName: data.FirstName || '',
862
+ LastName : data.LastName || '',
863
+ Company : data.Company || '',
864
+ EMail : data.EMail || '',
865
+ Type : data.Type || '',
866
+ };
867
+ }
868
+
869
+ async callApiFunction(apiFunctionName, parameters) {
870
+ try {
871
+ const client = await this.soapClientPromise;
872
+
873
+ // Dinamik olarak fonksiyon çağırma
874
+ const result = await client[`${apiFunctionName}`](parameters);
875
+
876
+ // Derinlik ne olursa olsun ...Result anahtarını bulalım
877
+ const responseKey = `${apiFunctionName}Result`;
878
+ let data = result[responseKey] || null; // İlk seviyede arar
879
+
880
+ // Eğer ilk seviyede bulamazsak, ikinci seviyede ararız
881
+ if (!data) {
882
+ const firstKey = Object.keys(result)[0];
883
+ if (result[firstKey] && result[firstKey][responseKey]) {
884
+ data = result[firstKey][responseKey];
885
+ }
886
+ }
887
+
888
+ if (!data || typeof data !== 'object') {
889
+ return {result: false, level: 'fatal', message: 'No data returned', ErrorCode: 0};
890
+ }
891
+ if (data.faultcode) {
892
+ return {result: false, level: 'fault', message: data.faultstring, ErrorCode: data.faultcode};
893
+ }
894
+
895
+ data.result = data.OperationResult === 'SUCCESS';
896
+
897
+ if (data.result === false) {
898
+ data.message = data.OperationMessage || 'Operation failed';
899
+ data.level = 'error';
900
+ // Make sure error code is passed through
901
+ if (typeof data === 'number') {
902
+ data = {
903
+ result: false,
904
+ level: 'error',
905
+ message: 'Operation failed',
906
+ ErrorCode: data
907
+ };
908
+ }
909
+ }
910
+
911
+ return data;
912
+
913
+ }
914
+ catch (error) {
915
+ console.error('API Error:', error);
916
+ return {result: false, level: 'exception', message: error.message, ErrorCode: error.code || 0};
917
+ }
918
+ }
919
+
920
+ }
921
+
922
+ module.exports = DomainNameAPI;