new-rajaongkir 0.0.2 → 0.0.3

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.
@@ -1,6 +1,7 @@
1
1
  var request = require('request')
2
2
  var Promise = require('promise')
3
3
  var qs = require('querystring')
4
+ const axios = require('axios')
4
5
 
5
6
  function Pro (apiKey) {
6
7
  this.version = 'pro'
@@ -30,1075 +31,273 @@ function Pro (apiKey) {
30
31
  STAR: 'star',
31
32
  EXPEDITO: 'expedito'
32
33
  }
34
+ this.instance = axios.create({
35
+ baseURL: this.httpUri,
36
+ timeout: 120000,
37
+ headers: {'content-type': 'application/json', 'key': apiKey}
38
+ });
33
39
  }
34
40
 
35
41
  module.exports = Pro
36
42
 
37
- Pro.prototype.getProvinces = function () {
38
- var uri = this.httpUri + '/province'
39
- var apiKey = this.apiKey
40
- return new Promise(function (resolve, reject) {
41
- request({
42
- uri: uri,
43
- method: 'GET',
44
- headers: {
45
- 'key': apiKey
46
- }
47
- }, function (error, response, body) {
48
- if (error) reject(error)
49
- var result = JSON.parse(body)
50
- if (result.rajaongkir.status.code !== 200) reject(result)
51
- return resolve(result)
52
- })
53
- })
43
+ Pro.prototype.getProvinces = async function () {
44
+ var uri = '/province'
45
+ var instance = this.instance
46
+ return await instance.get(uri);
54
47
  }
55
48
 
56
- Pro.prototype.getProvince = function (id) {
57
- var uri = this.httpUri + '/province?id=' + id
58
- var apiKey = this.apiKey
59
- return new Promise(function (resolve, reject) {
60
- request({
61
- uri: uri,
62
- method: 'GET',
63
- headers: {
64
- 'key': apiKey
65
- }
66
- }, function (error, response, body) {
67
- var result = JSON.parse(body)
68
- if (error) reject(error)
69
- if (result.rajaongkir.status.code !== 200) reject(result)
70
- return resolve(result)
71
- })
72
- })
49
+ Pro.prototype.getProvince = async function (id) {
50
+ var uri = '/province?id=' + id
51
+ var instance = this.instance
52
+ return await instance.get(uri);
73
53
  }
74
54
 
75
- Pro.prototype.getCities = function () {
76
- var uri = this.httpUri + '/city'
55
+ Pro.prototype.getCities = async function () {
56
+ var uri = '/city'
77
57
  var apiKey = this.apiKey
78
- return new Promise(function (resolve, reject) {
79
- request({
80
- uri: uri,
81
- method: 'GET',
82
- headers: {
83
- 'key': apiKey
84
- }
85
- }, function (error, response, body) {
86
- if (error) reject(error)
87
- var result = JSON.parse(body)
88
- if (result.rajaongkir.status.code !== 200) reject(result)
89
- return resolve(result)
90
- })
91
- })
58
+ var instance = this.instance
59
+ return await instance.get(uri,);
92
60
  }
93
61
 
94
- Pro.prototype.getCity = function (id) {
95
- var uri = this.httpUri + '/city?id=' + id
96
- var apiKey = this.apiKey
97
- return new Promise(function (resolve, reject) {
98
- request({
99
- uri: uri,
100
- method: 'GET',
101
- headers: {
102
- 'key': apiKey
103
- }
104
- }, function (error, response, body) {
105
- if (error) reject(error)
106
- var result = JSON.parse(body)
107
- if (result.rajaongkir.status.code !== 200) reject(result)
108
- return resolve(result)
109
- })
110
- })
62
+ Pro.prototype.getCity = async function (id) {
63
+ var uri = '/city?id=' + id
64
+ var instance = this.instance
65
+ return await instance.get(uri);
111
66
  }
112
67
 
113
- Pro.prototype.getSubDistrict = function (params) {
114
- var uri = this.httpUri + '/subdistrict?' + qs.stringify(params)
115
- var apiKey = this.apiKey
116
- return new Promise(function (resolve, reject) {
117
- request({
118
- uri: uri,
119
- method: 'GET',
120
- headers: {
121
- 'key': apiKey,
122
- 'Content-Type': 'application/json'
123
- }
124
- }, function (error, response, body) {
125
- if (error || typeof body === 'undefined') reject(error)
126
- var result = JSON.parse(body)
127
- if (result.rajaongkir.status.code !== 200) reject(result)
128
- return resolve(result)
129
- })
130
- })
68
+ Pro.prototype.getSubDistrict = async function (params) {
69
+ var uri = '/subdistrict?' + qs.stringify(params)
70
+ var instance = this.instance
71
+ return await instance.get(uri);
131
72
  }
132
73
 
133
- Pro.prototype.getCosts = function (params) {
134
- var uri = this.httpUri + '/cost'
135
- var apiKey = this.apiKey
136
- return new Promise(function (resolve, reject) {
137
- request({
138
- uri: uri,
139
- timeout: 120000,
140
- method: 'POST',
141
- headers: {
142
- 'key': apiKey,
143
- 'Content-Type': 'application/x-www-form-urlencoded'
144
- },
145
- form: params
146
- }, function (error, response, body) {
147
- if (error) reject(error)
148
- var result = JSON.parse(body)
149
- if (result.rajaongkir.status.code !== 200) reject(result)
150
- return resolve(result)
151
- })
152
- })
74
+ Pro.prototype.getCosts = async function (params) {
75
+ return await this.instance.post('/cost', params);
153
76
  }
154
77
 
155
- Pro.prototype.getLIONCost = function (params) {
156
- var uri = this.httpUri + '/cost'
157
- var apiKey = this.apiKey
78
+ Pro.prototype.getLIONCost = async function (params) {
158
79
  params.courier = this.couriers.LION
159
- return new Promise(function (resolve, reject) {
160
- request({
161
- uri: uri,
162
- timeout: 120000,
163
- method: 'POST',
164
- headers: {
165
- 'key': apiKey,
166
- 'Content-Type': 'application/x-www-form-urlencoded'
167
- },
168
- form: params
169
- }, function (error, response, body) {
170
- if (error) reject(error)
171
- var result = JSON.parse(body)
172
- if (result.rajaongkir.status.code !== 200) reject(result)
173
- return resolve(result)
174
- })
175
- })
80
+ return await this.instance.post('/cost', params);
176
81
  }
177
82
 
178
- Pro.prototype.getJNECost = function (params) {
179
- var uri = this.httpUri + '/cost'
180
- var apiKey = this.apiKey
83
+ Pro.prototype.getJNECost = async function (params) {
181
84
  params.courier = this.couriers.JNE
182
- return new Promise(function (resolve, reject) {
183
- request({
184
- uri: uri,
185
- timeout: 120000,
186
- method: 'POST',
187
- headers: {
188
- 'key': apiKey,
189
- 'Content-Type': 'application/x-www-form-urlencoded'
190
- },
191
- form: params
192
- }, function (error, response, body) {
193
- if (error) reject(error)
194
- var result = JSON.parse(body)
195
- if (result.rajaongkir.status.code !== 200) reject(result)
196
- return resolve(result)
197
- })
198
- })
85
+ return await this.instance.post('/cost', params);
199
86
  }
200
87
 
201
- Pro.prototype.getTIKICost = function (params) {
202
- var uri = this.httpUri + '/cost'
203
- var apiKey = this.apiKey
88
+ Pro.prototype.getTIKICost = async function (params) {
204
89
  params.courier = this.couriers.TIKI
205
- return new Promise(function (resolve, reject) {
206
- request({
207
- uri: uri,
208
- timeout: 120000,
209
- method: 'POST',
210
- headers: {
211
- 'key': apiKey,
212
- 'Content-Type': 'application/x-www-form-urlencoded'
213
- },
214
- form: params
215
- }, function (error, response, body) {
216
- if (error) reject(error)
217
- var result = JSON.parse(body)
218
- if (result.rajaongkir.status.code !== 200) reject(result)
219
- return resolve(result)
220
- })
221
- })
90
+ return await this.instance.post('/cost', params);
222
91
  }
223
92
 
224
- Pro.prototype.getPOSCost = function (params) {
225
- var uri = this.httpUri + '/cost'
226
- var apiKey = this.apiKey
93
+ Pro.prototype.getPOSCost = async function (params) {
227
94
  params.courier = this.couriers.POS
228
- return new Promise(function (resolve, reject) {
229
- request({
230
- uri: uri,
231
- timeout: 120000,
232
- method: 'POST',
233
- headers: {
234
- 'key': apiKey,
235
- 'Content-Type': 'application/x-www-form-urlencoded'
236
- },
237
- form: params
238
- }, function (error, response, body) {
239
- if (error) reject(error)
240
- var result = JSON.parse(body)
241
- if (result.rajaongkir.status.code !== 200) reject(result)
242
- return resolve(result)
243
- })
244
- })
95
+ return await this.instance.post('/cost', params);
245
96
  }
246
97
 
247
- Pro.prototype.getRPXCost = function (params) {
248
- var uri = this.httpUri + '/cost'
249
- var apiKey = this.apiKey
98
+ Pro.prototype.getRPXCost = async function (params) {
250
99
  params.courier = this.couriers.RPX
251
- return new Promise(function (resolve, reject) {
252
- request({
253
- uri: uri,
254
- timeout: 120000,
255
- method: 'POST',
256
- headers: {
257
- 'key': apiKey,
258
- 'Content-Type': 'application/x-www-form-urlencoded'
259
- },
260
- form: params
261
- }, function (error, response, body) {
262
- if (error) reject(error)
263
- var result = JSON.parse(body)
264
- if (result.rajaongkir.status.code !== 200) reject(result)
265
- return resolve(result)
266
- })
267
- })
100
+ return await this.instance.post('/cost', params);
268
101
  }
269
102
 
270
- Pro.prototype.getESLCost = function (params) {
271
- var uri = this.httpUri + '/cost'
272
- var apiKey = this.apiKey
103
+ Pro.prototype.getESLCost = async function (params) {
273
104
  params.courier = this.couriers.ESL
274
- return new Promise(function (resolve, reject) {
275
- request({
276
- uri: uri,
277
- timeout: 120000,
278
- method: 'POST',
279
- headers: {
280
- 'key': apiKey,
281
- 'Content-Type': 'application/x-www-form-urlencoded'
282
- },
283
- form: params
284
- }, function (error, response, body) {
285
- if (error) reject(error)
286
- var result = JSON.parse(body)
287
- if (result.rajaongkir.status.code !== 200) reject(result)
288
- return resolve(result)
289
- })
290
- })
105
+ return await this.instance.post('/cost', params);
291
106
  }
292
107
 
293
- Pro.prototype.getPCPCost = function (params) {
294
- var uri = this.httpUri + '/cost'
295
- var apiKey = this.apiKey
108
+ Pro.prototype.getPCPCost = async function (params) {
296
109
  params.courier = this.couriers.PCP
297
- return new Promise(function (resolve, reject) {
298
- request({
299
- uri: uri,
300
- timeout: 120000,
301
- method: 'POST',
302
- headers: {
303
- 'key': apiKey,
304
- 'Content-Type': 'application/x-www-form-urlencoded'
305
- },
306
- form: params
307
- }, function (error, response, body) {
308
- if (error) reject(error)
309
- var result = JSON.parse(body)
310
- if (result.rajaongkir.status.code !== 200) reject(result)
311
- return resolve(result)
312
- })
313
- })
110
+ return await this.instance.post('/cost', params);
314
111
  }
315
112
 
316
- Pro.prototype.getPanduCost = function (params) {
317
- var uri = this.httpUri + '/cost'
318
- var apiKey = this.apiKey
113
+ Pro.prototype.getPanduCost = async function (params) {
319
114
  params.courier = this.couriers.PANDU
320
- return new Promise(function (resolve, reject) {
321
- request({
322
- uri: uri,
323
- timeout: 120000,
324
- method: 'POST',
325
- headers: {
326
- 'key': apiKey,
327
- 'Content-Type': 'application/x-www-form-urlencoded'
328
- },
329
- form: params
330
- }, function (error, response, body) {
331
- if (error) reject(error)
332
- var result = JSON.parse(body)
333
- if (result.rajaongkir.status.code !== 200) reject(result)
334
- return resolve(result)
335
- })
336
- })
115
+ return await this.instance.post('/cost', params);
337
116
  }
338
117
 
339
- Pro.prototype.getWahanaCost = function (params) {
340
- var uri = this.httpUri + '/cost'
341
- var apiKey = this.apiKey
118
+ Pro.prototype.getWahanaCost = async function (params) {
342
119
  params.courier = this.couriers.WAHANA
343
- return new Promise(function (resolve, reject) {
344
- request({
345
- uri: uri,
346
- timeout: 120000,
347
- method: 'POST',
348
- headers: {
349
- 'key': apiKey,
350
- 'Content-Type': 'application/x-www-form-urlencoded'
351
- },
352
- form: params
353
- }, function (error, response, body) {
354
- if (error) reject(error)
355
- var result = JSON.parse(body)
356
- if (result.rajaongkir.status.code !== 200) reject(result)
357
- return resolve(result)
358
- })
359
- })
120
+ return await this.instance.post('/cost', params);
360
121
  }
361
122
 
362
- Pro.prototype.getSiCepatCost = function (params) {
363
- var uri = this.httpUri + '/cost'
364
- var apiKey = this.apiKey
123
+ Pro.prototype.getSiCepatCost = async function (params) {
365
124
  params.courier = this.couriers.SICEPAT
366
- return new Promise(function (resolve, reject) {
367
- request({
368
- uri: uri,
369
- timeout: 120000,
370
- method: 'POST',
371
- headers: {
372
- 'key': apiKey,
373
- 'Content-Type': 'application/x-www-form-urlencoded'
374
- },
375
- form: params
376
- }, function (error, response, body) {
377
- if (error) reject(error)
378
- var result = JSON.parse(body)
379
- if (result.rajaongkir.status.code !== 200) reject(result)
380
- return resolve(result)
381
- })
382
- })
125
+ return await this.instance.post('/cost', params);
383
126
  }
384
127
 
385
- Pro.prototype.getPahalaCost = function (params) {
386
- var uri = this.httpUri + '/cost'
387
- var apiKey = this.apiKey
128
+ Pro.prototype.getPahalaCost = async function (params) {
388
129
  params.courier = this.couriers.PAHALA
389
- return new Promise(function (resolve, reject) {
390
- request({
391
- uri: uri,
392
- timeout: 120000,
393
- method: 'POST',
394
- headers: {
395
- 'key': apiKey,
396
- 'Content-Type': 'application/x-www-form-urlencoded'
397
- },
398
- form: params
399
- }, function (error, response, body) {
400
- if (error) reject(error)
401
- var result = JSON.parse(body)
402
- if (result.rajaongkir.status.code !== 200) reject(result)
403
- return resolve(result)
404
- })
405
- })
130
+ return await this.instance.post('/cost', params);
406
131
  }
407
132
 
408
- Pro.prototype.getCahayaCost = function (params) {
409
- var uri = this.httpUri + '/cost'
410
- var apiKey = this.apiKey
133
+ Pro.prototype.getCahayaCost = async function (params) {
411
134
  params.courier = this.couriers.CAHAYA
412
- return new Promise(function (resolve, reject) {
413
- request({
414
- uri: uri,
415
- timeout: 120000,
416
- method: 'POST',
417
- headers: {
418
- 'key': apiKey,
419
- 'Content-Type': 'application/x-www-form-urlencoded'
420
- },
421
- form: params
422
- }, function (error, response, body) {
423
- if (error) reject(error)
424
- var result = JSON.parse(body)
425
- if (result.rajaongkir.status.code !== 200) reject(result)
426
- return resolve(result)
427
- })
428
- })
135
+ return await this.instance.post('/cost', params);
429
136
  }
430
137
 
431
- Pro.prototype.getSAPCost = function (params) {
432
- var uri = this.httpUri + '/cost'
433
- var apiKey = this.apiKey
138
+ Pro.prototype.getSAPCost = async function (params) {
434
139
  params.courier = this.couriers.SAP
435
- return new Promise(function (resolve, reject) {
436
- request({
437
- uri: uri,
438
- timeout: 120000,
439
- method: 'POST',
440
- headers: {
441
- 'key': apiKey,
442
- 'Content-Type': 'application/x-www-form-urlencoded'
443
- },
444
- form: params
445
- }, function (error, response, body) {
446
- if (error) reject(error)
447
- var result = JSON.parse(body)
448
- if (result.rajaongkir.status.code !== 200) reject(result)
449
- return resolve(result)
450
- })
451
- })
140
+ return await this.instance.post('/cost', params);
452
141
  }
453
142
 
454
- Pro.prototype.getJETCost = function (params) {
455
- var uri = this.httpUri + '/cost'
456
- var apiKey = this.apiKey
143
+ Pro.prototype.getJETCost = async function (params) {
457
144
  params.courier = this.couriers.JET
458
- return new Promise(function (resolve, reject) {
459
- request({
460
- uri: uri,
461
- timeout: 120000,
462
- method: 'POST',
463
- headers: {
464
- 'key': apiKey,
465
- 'Content-Type': 'application/x-www-form-urlencoded'
466
- },
467
- form: params
468
- }, function (error, response, body) {
469
- if (error) reject(error)
470
- var result = JSON.parse(body)
471
- if (result.rajaongkir.status.code !== 200) reject(result)
472
- return resolve(result)
473
- })
474
- })
145
+ return await this.instance.post('/cost', params);
475
146
  }
476
147
 
477
- Pro.prototype.getIndahCost = function (params) {
478
- var uri = this.httpUri + '/cost'
479
- var apiKey = this.apiKey
148
+ Pro.prototype.getIndahCost = async function (params) {
480
149
  params.courier = this.couriers.INDAH
481
- return new Promise(function (resolve, reject) {
482
- request({
483
- uri: uri,
484
- timeout: 120000,
485
- method: 'POST',
486
- headers: {
487
- 'key': apiKey,
488
- 'Content-Type': 'application/x-www-form-urlencoded'
489
- },
490
- form: params
491
- }, function (error, response, body) {
492
- if (error) reject(error)
493
- var result = JSON.parse(body)
494
- if (result.rajaongkir.status.code !== 200) reject(result)
495
- return resolve(result)
496
- })
497
- })
150
+ return await this.instance.post('/cost', params);
498
151
  }
499
152
 
500
- Pro.prototype.getDSECost = function (params) {
501
- var uri = this.httpUri + '/cost'
502
- var apiKey = this.apiKey
153
+ Pro.prototype.getDSECost = async function (params) {
503
154
  params.courier = this.couriers.DSE
504
- return new Promise(function (resolve, reject) {
505
- request({
506
- uri: uri,
507
- timeout: 120000,
508
- method: 'POST',
509
- headers: {
510
- 'key': apiKey,
511
- 'Content-Type': 'application/x-www-form-urlencoded'
512
- },
513
- form: params
514
- }, function (error, response, body) {
515
- if (error) reject(error)
516
- var result = JSON.parse(body)
517
- if (result.rajaongkir.status.code !== 200) reject(result)
518
- return resolve(result)
519
- })
520
- })
155
+ return await this.instance.post('/cost', params);
521
156
  }
522
157
 
523
- Pro.prototype.getSLISCost = function (params) {
524
- var uri = this.httpUri + '/cost'
525
- var apiKey = this.apiKey
158
+ Pro.prototype.getSLISCost = async function (params) {
526
159
  params.courier = this.couriers.SLIS
527
- return new Promise(function (resolve, reject) {
528
- request({
529
- uri: uri,
530
- timeout: 120000,
531
- method: 'POST',
532
- headers: {
533
- 'key': apiKey,
534
- 'Content-Type': 'application/x-www-form-urlencoded'
535
- },
536
- form: params
537
- }, function (error, response, body) {
538
- if (error) reject(error)
539
- var result = JSON.parse(body)
540
- if (result.rajaongkir.status.code !== 200) reject(result)
541
- return resolve(result)
542
- })
543
- })
160
+ return await this.instance.post('/cost', params);
544
161
  }
545
162
 
546
- Pro.prototype.getFirstCost = function (params) {
547
- var uri = this.httpUri + '/cost'
548
- var apiKey = this.apiKey
163
+ Pro.prototype.getFirstCost = async function (params) {
549
164
  params.courier = this.couriers.FIRST
550
- return new Promise(function (resolve, reject) {
551
- request({
552
- uri: uri,
553
- timeout: 120000,
554
- method: 'POST',
555
- headers: {
556
- 'key': apiKey,
557
- 'Content-Type': 'application/x-www-form-urlencoded'
558
- },
559
- form: params
560
- }, function (error, response, body) {
561
- if (error) reject(error)
562
- var result = JSON.parse(body)
563
- if (result.rajaongkir.status.code !== 200) reject(result)
564
- return resolve(result)
565
- })
566
- })
165
+ return await this.instance.post('/cost', params);
567
166
  }
568
167
 
569
- Pro.prototype.getNCSCost = function (params) {
570
- var uri = this.httpUri + '/cost'
571
- var apiKey = this.apiKey
168
+ Pro.prototype.getNCSCost = async function (params) {
572
169
  params.courier = this.couriers.NCS
573
- return new Promise(function (resolve, reject) {
574
- request({
575
- uri: uri,
576
- timeout: 120000,
577
- method: 'POST',
578
- headers: {
579
- 'key': apiKey,
580
- 'Content-Type': 'application/x-www-form-urlencoded'
581
- },
582
- form: params
583
- }, function (error, response, body) {
584
- if (error) reject(error)
585
- var result = JSON.parse(body)
586
- if (result.rajaongkir.status.code !== 200) reject(result)
587
- return resolve(result)
588
- })
589
- })
170
+ return await this.instance.post('/cost', params);
590
171
  }
591
172
 
592
- Pro.prototype.getStarCost = function (params) {
593
- var uri = this.httpUri + '/cost'
594
- var apiKey = this.apiKey
173
+ Pro.prototype.getStarCost = async function (params) {
595
174
  params.courier = this.couriers.STAR
596
- return new Promise(function (resolve, reject) {
597
- request({
598
- uri: uri,
599
- timeout: 120000,
600
- method: 'POST',
601
- headers: {
602
- 'key': apiKey,
603
- 'Content-Type': 'application/x-www-form-urlencoded'
604
- },
605
- form: params
606
- }, function (error, response, body) {
607
- if (error) reject(error)
608
- var result = JSON.parse(body)
609
- if (result.rajaongkir.status.code !== 200) reject(result)
610
- return resolve(result)
611
- })
612
- })
175
+ return await this.instance.post('/cost', params);
613
176
  }
614
177
 
615
- Pro.prototype.getInterOrigins = function () {
616
- var uri = this.httpUri + '/v2/internationalOrigin'
617
- var apiKey = this.apiKey
618
- return new Promise(function (resolve, reject) {
619
- request({
620
- uri: uri,
621
- timeout: 120000,
622
- method: 'GET',
623
- headers: {
624
- 'key': apiKey
625
- }
626
- }, function (error, response, body) {
627
- if (error) reject(error)
628
- var result = JSON.parse(body)
629
- if (result.rajaongkir.status.code !== 200) reject(result)
630
- return resolve(result)
631
- })
632
- })
178
+ Pro.prototype.getInterOrigins = async function () {
179
+ var uri = '/v2/internationalOrigin'
180
+ return await this.instance.get(uri);
633
181
  }
634
182
 
635
- Pro.prototype.getInterOrigin = function (params) {
183
+ Pro.prototype.getInterOrigin = async function (params) {
636
184
  var uri = this.httpUri + '/v2/internationalOrigin?' + qs.stringify(params)
637
- var apiKey = this.apiKey
638
- return new Promise(function (resolve, reject) {
639
- request({
640
- uri: uri,
641
- timeout: 120000,
642
- method: 'GET',
643
- headers: {
644
- 'key': apiKey
645
- }
646
- }, function (error, response, body) {
647
- if (error) reject(error)
648
- var result = JSON.parse(body)
649
- if (result.rajaongkir.status.code !== 200) reject(result)
650
- return resolve(result)
651
- })
652
- })
185
+ return await this.instance.get(uri);
653
186
  }
654
187
 
655
- Pro.prototype.getInterDests = function () {
188
+ Pro.prototype.getInterDests = async function () {
656
189
  var uri = this.httpUri + '/v2/internationalDestination'
657
- var apiKey = this.apiKey
658
- return new Promise(function (resolve, reject) {
659
- request({
660
- uri: uri,
661
- timeout: 120000,
662
- method: 'GET',
663
- headers: {
664
- 'key': apiKey
665
- }
666
- }, function (error, response, body) {
667
- if (error) reject(error)
668
- var result = JSON.parse(body)
669
- if (result.rajaongkir.status.code !== 200) reject(result)
670
- return resolve(result)
671
- })
672
- })
190
+ return await this.instance.get(uri);
673
191
  }
674
192
 
675
- Pro.prototype.getInterDest = function (id) {
193
+ Pro.prototype.getInterDest = async function (id) {
676
194
  var uri = this.httpUri + '/v2/internationalDestination?id=' + id
677
- var apiKey = this.apiKey
678
- return new Promise(function (resolve, reject) {
679
- request({
680
- uri: uri,
681
- timeout: 120000,
682
- method: 'GET',
683
- headers: {
684
- 'key': apiKey
685
- }
686
- }, function (error, response, body) {
687
- if (error) reject(error)
688
- var result = JSON.parse(body)
689
- if (result.rajaongkir.status.code !== 200) reject(result)
690
- return resolve(result)
691
- })
692
- })
195
+ return await this.instance.get(uri);
693
196
  }
694
197
 
695
- Pro.prototype.getTIKIInterConst = function (params) {
198
+ Pro.prototype.getTIKIInterConst = async function (params) {
696
199
  var uri = this.httpUri + '/v2/internationalCost'
697
- var apiKey = this.apiKey
698
200
  params.courier = this.couriers.TIKI
699
- return new Promise(function (resolve, reject) {
700
- request({
701
- uri: uri,
702
- timeout: 120000,
703
- method: 'POST',
704
- headers: {
705
- 'key': apiKey,
706
- 'Content-Type': 'application/x-www-form-urlencoded'
707
- },
708
- form: params
709
- }, function (error, response, body) {
710
- if (error) reject(error)
711
- var result = JSON.parse(body)
712
- if (result.rajaongkir.status.code !== 200) reject(result)
713
- return resolve(result)
714
- })
715
- })
201
+ return await this.instance.post(uri, params);
716
202
  }
717
203
 
718
- Pro.prototype.getPOSInterCost = function (params) {
204
+ Pro.prototype.getPOSInterCost = async function (params) {
719
205
  var uri = this.httpUri + '/v2/internationalCost'
720
- var apiKey = this.apiKey
721
206
  params.courier = this.couriers.POS
722
- return new Promise(function (resolve, reject) {
723
- request({
724
- uri: uri,
725
- timeout: 120000,
726
- method: 'POST',
727
- headers: {
728
- 'key': apiKey,
729
- 'Content-Type': 'application/x-www-form-urlencoded'
730
- },
731
- form: params
732
- }, function (error, response, body) {
733
- if (error) reject(error)
734
- var result = JSON.parse(body)
735
- if (result.rajaongkir.status.code !== 200) reject(result)
736
- return resolve(result)
737
- })
738
- })
207
+ return await this.instance.post(uri, params);
739
208
  }
740
209
 
741
- Pro.prototype.getJNEInterCost = function (params) {
210
+ Pro.prototype.getJNEInterCost = async function (params) {
742
211
  var uri = this.httpUri + '/v2/internationalCost'
743
- var apiKey = this.apiKey
744
212
  params.courier = this.couriers.JNE
745
- return new Promise(function (resolve, reject) {
746
- request({
747
- uri: uri,
748
- timeout: 120000,
749
- method: 'POST',
750
- headers: {
751
- 'key': apiKey,
752
- 'Content-Type': 'application/x-www-form-urlencoded'
753
- },
754
- form: params
755
- }, function (error, response, body) {
756
- if (error) reject(error)
757
- var result = JSON.parse(body)
758
- if (result.rajaongkir.status.code !== 200) reject(result)
759
- return resolve(result)
760
- })
761
- })
213
+ return await this.instance.post(uri, params);
762
214
  }
763
215
 
764
- Pro.prototype.getSLISInterCost = function (params) {
216
+ Pro.prototype.getSLISInterCost = async function (params) {
765
217
  var uri = this.httpUri + '/v2/internationalCost'
766
- var apiKey = this.apiKey
767
218
  params.courier = this.couriers.SLIS
768
- return new Promise(function (resolve, reject) {
769
- request({
770
- uri: uri,
771
- timeout: 120000,
772
- method: 'POST',
773
- headers: {
774
- 'key': apiKey,
775
- 'Content-Type': 'application/x-www-form-urlencoded'
776
- },
777
- form: params
778
- }, function (error, response, body) {
779
- if (error) reject(error)
780
- var result = JSON.parse(body)
781
- if (result.rajaongkir.status.code !== 200) reject(result)
782
- return resolve(result)
783
- })
784
- })
219
+ return await this.instance.post(uri, params);
785
220
  }
786
221
 
787
- Pro.prototype.getExpeditoInterCost = function (params) {
222
+ Pro.prototype.getExpeditoInterCost = async function (params) {
788
223
  var uri = this.httpUri + '/v2/internationalCost'
789
- var apiKey = this.apiKey
790
224
  params.courier = this.couriers.EXPEDITO
791
- return new Promise(function (resolve, reject) {
792
- request({
793
- uri: uri,
794
- timeout: 120000,
795
- method: 'POST',
796
- headers: {
797
- 'key': apiKey,
798
- 'Content-Type': 'application/x-www-form-urlencoded'
799
- },
800
- form: params
801
- }, function (error, response, body) {
802
- if (error) reject(error)
803
- var result = JSON.parse(body)
804
- if (result.rajaongkir.status.code !== 200) reject(result)
805
- return resolve(result)
806
- })
807
- })
225
+ return await this.instance.post(uri, params);
808
226
  }
809
227
 
810
- Pro.prototype.getCurrency = function () {
228
+ Pro.prototype.getCurrency = async function () {
811
229
  var uri = this.httpUri + '/currency'
812
- var apiKey = this.apiKey
813
- return new Promise(function (resolve, reject) {
814
- request({
815
- uri: uri,
816
- timeout: 120000,
817
- method: 'GET',
818
- headers: {
819
- 'key': apiKey
820
- }
821
- }, function (error, response, body) {
822
- if (error) reject(error)
823
- var result = JSON.parse(body)
824
- if (result.rajaongkir.status.code !== 200) reject(result)
825
- return resolve(result)
826
- })
827
- })
230
+ return await this.instance.get(uri);
828
231
  }
829
232
 
830
- Pro.prototype.getJNEWaybill = function (params) {
233
+ Pro.prototype.getJNEWaybill = async function (params) {
831
234
  var uri = this.httpUri + '/waybill'
832
- var apiKey = this.apiKey
833
235
  params.courier = this.couriers.JNE
834
- return new Promise(function (resolve, reject) {
835
- request({
836
- uri: uri,
837
- timeout: 120000,
838
- method: 'POST',
839
- headers: {
840
- 'key': apiKey,
841
- 'Content-Type': 'application/x-www-form-urlencoded'
842
- },
843
- form: params
844
- }, function (error, response, body) {
845
- if (error) reject(error)
846
- var result = JSON.parse(body)
847
- if (result.rajaongkir.status.code !== 200) reject(result)
848
- return resolve(result)
849
- })
850
- })
236
+ return await this.instance.post(uri, params);
851
237
  }
852
238
 
853
- Pro.prototype.getPOSWaybill = function (params) {
239
+ Pro.prototype.getPOSWaybill = async function (params) {
854
240
  var uri = this.httpUri + '/waybill'
855
- var apiKey = this.apiKey
856
241
  params.courier = this.couriers.POS
857
- return new Promise(function (resolve, reject) {
858
- request({
859
- uri: uri,
860
- timeout: 120000,
861
- method: 'POST',
862
- headers: {
863
- 'key': apiKey,
864
- 'Content-Type': 'application/x-www-form-urlencoded'
865
- },
866
- form: params
867
- }, function (error, response, body) {
868
- if (error) reject(error)
869
- var result = JSON.parse(body)
870
- if (result.rajaongkir.status.code !== 200) reject(result)
871
- return resolve(result)
872
- })
873
- })
242
+ return await this.instance.post(uri, params);
874
243
  }
875
244
 
876
- Pro.prototype.getTIKIWaybill = function (params) {
245
+ Pro.prototype.getTIKIWaybill = async function (params) {
877
246
  var uri = this.httpUri + '/waybill'
878
- var apiKey = this.apiKey
879
247
  params.courier = this.couriers.TIKI
880
- return new Promise(function (resolve, reject) {
881
- request({
882
- uri: uri,
883
- timeout: 120000,
884
- method: 'POST',
885
- headers: {
886
- 'key': apiKey,
887
- 'Content-Type': 'application/x-www-form-urlencoded'
888
- },
889
- form: params
890
- }, function (error, response, body) {
891
- if (error) reject(error)
892
- var result = JSON.parse(body)
893
- if (result.rajaongkir.status.code !== 200) reject(result)
894
- return resolve(result)
895
- })
896
- })
248
+ return await this.instance.post(uri, params);
897
249
  }
898
250
 
899
- Pro.prototype.getWahanaWaybill = function (params) {
251
+ Pro.prototype.getWahanaWaybill = async function (params) {
900
252
  var uri = this.httpUri + '/waybill'
901
- var apiKey = this.apiKey
902
253
  params.courier = this.couriers.WAHANA
903
- return new Promise(function (resolve, reject) {
904
- request({
905
- uri: uri,
906
- timeout: 120000,
907
- method: 'POST',
908
- headers: {
909
- 'key': apiKey,
910
- 'Content-Type': 'application/x-www-form-urlencoded'
911
- },
912
- form: params
913
- }, function (error, response, body) {
914
- if (error) reject(error)
915
- var result = JSON.parse(body)
916
- if (result.rajaongkir.status.code !== 200) reject(result)
917
- return resolve(result)
918
- })
919
- })
254
+ return await this.instance.post(uri, params);
920
255
  }
921
256
 
922
- Pro.prototype.getJNTWaybill = function (params) {
257
+ Pro.prototype.getJNTWaybill = async function (params) {
923
258
  var uri = this.httpUri + '/waybill'
924
- var apiKey = this.apiKey
925
259
  params.courier = this.couriers.JNT
926
- return new Promise(function (resolve, reject) {
927
- request({
928
- uri: uri,
929
- timeout: 120000,
930
- method: 'POST',
931
- headers: {
932
- 'key': apiKey,
933
- 'Content-Type': 'application/x-www-form-urlencoded'
934
- },
935
- form: params
936
- }, function (error, response, body) {
937
- if (error) reject(error)
938
- var result = JSON.parse(body)
939
- if (result.rajaongkir.status.code !== 200) reject(result)
940
- return resolve(result)
941
- })
942
- })
260
+ return await this.instance.post(uri, params);
943
261
  }
944
262
 
945
- Pro.prototype.getRPXWaybill = function (params) {
263
+ Pro.prototype.getRPXWaybill = async function (params) {
946
264
  var uri = this.httpUri + '/waybill'
947
- var apiKey = this.apiKey
948
265
  params.courier = this.couriers.RPX
949
- return new Promise(function (resolve, reject) {
950
- request({
951
- uri: uri,
952
- timeout: 120000,
953
- method: 'POST',
954
- headers: {
955
- 'key': apiKey,
956
- 'Content-Type': 'application/x-www-form-urlencoded'
957
- },
958
- form: params
959
- }, function (error, response, body) {
960
- if (error) reject(error)
961
- var result = JSON.parse(body)
962
- if (result.rajaongkir.status.code !== 200) reject(result)
963
- return resolve(result)
964
- })
965
- })
266
+ return await this.instance.post(uri, params);
966
267
  }
967
268
 
968
- Pro.prototype.getSAPWaybill = function (params) {
269
+ Pro.prototype.getSAPWaybill = async function (params) {
969
270
  var uri = this.httpUri + '/waybill'
970
- var apiKey = this.apiKey
971
271
  params.courier = this.couriers.SAP
972
- return new Promise(function (resolve, reject) {
973
- request({
974
- uri: uri,
975
- timeout: 120000,
976
- method: 'POST',
977
- headers: {
978
- 'key': apiKey,
979
- 'Content-Type': 'application/x-www-form-urlencoded'
980
- },
981
- form: params
982
- }, function (error, response, body) {
983
- if (error) reject(error)
984
- var result = JSON.parse(body)
985
- if (result.rajaongkir.status.code !== 200) reject(result)
986
- return resolve(result)
987
- })
988
- })
272
+ return await this.instance.post(uri, params);
989
273
  }
990
274
 
991
- Pro.prototype.getSiCepatWaybill = function (params) {
275
+ Pro.prototype.getSiCepatWaybill = async function (params) {
992
276
  var uri = this.httpUri + '/waybill'
993
- var apiKey = this.apiKey
994
277
  params.courier = this.couriers.SICEPAT
995
- return new Promise(function (resolve, reject) {
996
- request({
997
- uri: uri,
998
- timeout: 120000,
999
- method: 'POST',
1000
- headers: {
1001
- 'key': apiKey,
1002
- 'Content-Type': 'application/x-www-form-urlencoded'
1003
- },
1004
- form: params
1005
- }, function (error, response, body) {
1006
- if (error) reject(error)
1007
- var result = JSON.parse(body)
1008
- if (result.rajaongkir.status.code !== 200) reject(result)
1009
- return resolve(result)
1010
- })
1011
- })
278
+ return await this.instance.post(uri, params);
1012
279
  }
1013
280
 
1014
- Pro.prototype.getPCPWaybill = function (params) {
281
+ Pro.prototype.getPCPWaybill = async function (params) {
1015
282
  var uri = this.httpUri + '/waybill'
1016
- var apiKey = this.apiKey
1017
283
  params.courier = this.couriers.PCP
1018
- return new Promise(function (resolve, reject) {
1019
- request({
1020
- uri: uri,
1021
- timeout: 120000,
1022
- method: 'POST',
1023
- headers: {
1024
- 'key': apiKey,
1025
- 'Content-Type': 'application/x-www-form-urlencoded'
1026
- },
1027
- form: params
1028
- }, function (error, response, body) {
1029
- if (error) reject(error)
1030
- var result = JSON.parse(body)
1031
- if (result.rajaongkir.status.code !== 200) reject(result)
1032
- return resolve(result)
1033
- })
1034
- })
284
+ return await this.instance.post(uri, params);
1035
285
  }
1036
286
 
1037
- Pro.prototype.getJETWaybill = function (params) {
287
+ Pro.prototype.getJETWaybill = async function (params) {
1038
288
  var uri = this.httpUri + '/waybill'
1039
- var apiKey = this.apiKey
1040
289
  params.courier = this.couriers.JET
1041
- return new Promise(function (resolve, reject) {
1042
- request({
1043
- uri: uri,
1044
- timeout: 120000,
1045
- method: 'POST',
1046
- headers: {
1047
- 'key': apiKey,
1048
- 'Content-Type': 'application/x-www-form-urlencoded'
1049
- },
1050
- form: params
1051
- }, function (error, response, body) {
1052
- if (error) reject(error)
1053
- var result = JSON.parse(body)
1054
- if (result.rajaongkir.status.code !== 200) reject(result)
1055
- return resolve(result)
1056
- })
1057
- })
290
+ return await this.instance.post(uri, params);
1058
291
  }
1059
292
 
1060
- Pro.prototype.getDSEWaybill = function (params) {
293
+ Pro.prototype.getDSEWaybill = async function (params) {
1061
294
  var uri = this.httpUri + '/waybill'
1062
- var apiKey = this.apiKey
1063
295
  params.courier = this.couriers.DSE
1064
- return new Promise(function (resolve, reject) {
1065
- request({
1066
- uri: uri,
1067
- timeout: 120000,
1068
- method: 'POST',
1069
- headers: {
1070
- 'key': apiKey,
1071
- 'Content-Type': 'application/x-www-form-urlencoded'
1072
- },
1073
- form: params
1074
- }, function (error, response, body) {
1075
- if (error) reject(error)
1076
- var result = JSON.parse(body)
1077
- if (result.rajaongkir.status.code !== 200) reject(result)
1078
- return resolve(result)
1079
- })
1080
- })
296
+ return await this.instance.post(uri, params);
1081
297
  }
1082
298
 
1083
- Pro.prototype.getFirstWaybill = function (params) {
299
+ Pro.prototype.getFirstWaybill = async function (params) {
1084
300
  var uri = this.httpUri + '/waybill'
1085
- var apiKey = this.apiKey
1086
301
  params.courier = this.couriers.FIRST
1087
- return new Promise(function (resolve, reject) {
1088
- request({
1089
- uri: uri,
1090
- timeout: 120000,
1091
- method: 'POST',
1092
- headers: {
1093
- 'key': apiKey,
1094
- 'Content-Type': 'application/x-www-form-urlencoded'
1095
- },
1096
- form: params
1097
- }, function (error, response, body) {
1098
- if (error) reject(error)
1099
- var result = JSON.parse(body)
1100
- if (result.rajaongkir.status.code !== 200) reject(result)
1101
- return resolve(result)
1102
- })
1103
- })
302
+ return await this.instance.post(uri, params);
1104
303
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "new-rajaongkir",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "NodeJS Client Library API RajaOngkir",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -45,6 +45,7 @@
45
45
  "http": "0.0.0",
46
46
  "promise": "^8.0.1",
47
47
  "querystring": "^0.2.0",
48
+ "axios": "^1.6.2",
48
49
  "request": "^2.81.0"
49
50
  }
50
51
  }