@@ -44,10 +44,21 @@ class Plugin {
44
44
this [ attr ] = value ;
45
45
} ) ;
46
46
this . tokenTemplate = ( ) => ( {
47
+ endpoint : {
48
+ type : 'text' ,
49
+ regExp : / ^ (? ! m a i l t o : ) (?: (?: h t t p | h t t p s | f t p ) : \/ \/ ) (?: \S + (?: : \S * ) ? @ ) ? (?: (?: (?: [ 1 - 9 ] \d ? | 1 \d \d | 2 [ 0 1 ] \d | 2 2 [ 0 - 3 ] ) (?: \. (?: 1 ? \d { 1 , 2 } | 2 [ 0 - 4 ] \d | 2 5 [ 0 - 5 ] ) ) { 2 } (?: \. (?: [ 0 - 9 ] \d ? | 1 \d \d | 2 [ 0 - 4 ] \d | 2 5 [ 0 - 4 ] ) ) | (?: (?: [ a - z \u00a1 - \uffff 0 - 9 ] + - ? ) * [ a - z \u00a1 - \uffff 0 - 9 ] + ) (?: \. (?: [ a - z \u00a1 - \uffff 0 - 9 ] + - ? ) * [ a - z \u00a1 - \uffff 0 - 9 ] + ) * (?: \. (?: [ a - z \u00a1 - \uffff ] { 2 , } ) ) ) | l o c a l h o s t ) (?: : \d { 2 , 5 } ) ? (?: ( \/ | \? | # ) [ ^ \s ] * ) ? $ / i,
50
+ default : 'https://bmsstage.bonzabiketours.com:3001/octo/v1' ,
51
+ description : 'The Bonza API endpoint URL' ,
52
+ } ,
53
+ apiKey : {
54
+ type : 'text' ,
55
+ regExp : / [ 0 - 9 a - f ] { 48 } / ,
56
+ description : 'The authentication key for Bonza API endpoint' ,
57
+ } ,
47
58
bookingPartnerId : {
48
59
type : 'text' ,
49
60
regExp : / ^ \d + $ / ,
50
- description : 'The booking partner id' ,
61
+ description : 'The Bonza booking partner id' ,
51
62
}
52
63
} ) ;
53
64
this . errorPathsAxiosErrors = ( ) => ( [ // axios triggered errors
@@ -57,17 +68,20 @@ class Plugin {
57
68
}
58
69
59
70
async validateToken ( {
60
- axios,
61
- token : {
62
- bookingPartnerId,
63
- } ,
64
- } )
71
+ axios,
72
+ token : {
73
+ endpoint,
74
+ apiKey,
75
+ bookingPartnerId,
76
+ } ,
77
+ } )
65
78
{
66
- // console.log("API KEY in plugin : " + this.apiKey);
67
- // console.log("ENDPOINT in plugin : " + this.endpoint);
68
- const url = `${ this . endpoint } /products` ;
79
+ // console.log("API KEY in plugin : " + apiKey);
80
+ // console.log("ENDPOINT in plugin : " + endpoint);
81
+ // console.log("BOOKIGN PARTNER ID in plugin : " + bookingPartnerId);
82
+ const url = `${ endpoint } /products` ;
69
83
const headers = getHeaders ( {
70
- apiKey :this . apiKey ,
84
+ apiKey : apiKey ,
71
85
} ) ;
72
86
try {
73
87
const suppliers = R . path ( [ 'data' ] , await axios ( {
@@ -85,15 +99,17 @@ class Plugin {
85
99
async searchProducts ( {
86
100
axios,
87
101
token : {
102
+ endpoint,
103
+ apiKey,
88
104
bookingPartnerId,
89
- } ,
105
+ } ,
90
106
payload,
91
107
typeDefsAndQueries : {
92
108
productTypeDefs,
93
109
productQuery,
94
110
} ,
95
111
} ) {
96
- let url = `${ this . endpoint } /products` ;
112
+ let url = `${ endpoint } /products` ;
97
113
console . log ( "URL: " + url ) ;
98
114
if ( ! isNilOrEmpty ( payload ) ) {
99
115
if ( payload . productId ) {
@@ -104,7 +120,7 @@ class Plugin {
104
120
105
121
console . log ( "URL: " + url ) ;
106
122
const headers = getHeaders ( {
107
- apiKey : this . apiKey ,
123
+ apiKey : apiKey ,
108
124
} ) ;
109
125
let results = R . pathOr ( [ ] , [ 'data' ] , await axios ( {
110
126
method : 'get' ,
@@ -137,21 +153,25 @@ class Plugin {
137
153
return ( { products } ) ;
138
154
}
139
155
140
- async searchQuote ( {
141
- token : {
142
- bookingPartnerId,
143
- } ,
144
- payload : {
145
- productIds,
146
- optionIds,
147
- } ,
148
- } ) {
149
- return { quote : [ ] } ;
150
- }
156
+ // async searchQuote({
157
+ // token: {
158
+ // endpoint,
159
+ // apiKey,
160
+ // bookingPartnerId,
161
+ // },
162
+ // payload: {
163
+ // productIds,
164
+ // optionIds,
165
+ // },
166
+ // }) {
167
+ // return { quote: [] };
168
+ // }
151
169
152
170
async searchAvailability ( {
153
171
axios,
154
172
token : {
173
+ endpoint,
174
+ apiKey,
155
175
bookingPartnerId,
156
176
} ,
157
177
// ONLY add payload key when absolutely necessary
@@ -188,10 +208,10 @@ class Plugin {
188
208
const localDateStart = moment ( startDate , dateFormat ) . format ( 'YYYY-MM-DD' ) ;
189
209
const localDateEnd = moment ( endDate , dateFormat ) . format ( 'YYYY-MM-DD' ) ;
190
210
const headers = getHeaders ( {
191
- apiKey : this . apiKey ,
211
+ apiKey : apiKey ,
192
212
} ) ;
193
213
194
- const url = `${ this . endpoint } /availability/calendar` ;
214
+ const url = `${ endpoint } /availability/calendar` ;
195
215
let availability = (
196
216
await Promise . map ( productIds , async ( productId , ix ) => {
197
217
const data = {
@@ -231,6 +251,8 @@ class Plugin {
231
251
async availabilityCalendar ( {
232
252
axios,
233
253
token : {
254
+ endpoint,
255
+ apiKey,
234
256
bookingPartnerId,
235
257
} ,
236
258
// ONLY add payload key when absolutely necessary
@@ -247,6 +269,8 @@ class Plugin {
247
269
} ,
248
270
} ) {
249
271
try {
272
+ console . log ( "availabilityCalendar called" ) ;
273
+
250
274
assert ( this . jwtKey , 'JWT secret should be set' ) ;
251
275
assert (
252
276
productIds . length === productIds . length ,
@@ -273,10 +297,10 @@ class Plugin {
273
297
274
298
// console.log("AC: END DATE: " + localDateEnd);
275
299
const headers = getHeaders ( {
276
- apiKey : this . apiKey ,
300
+ apiKey : apiKey ,
277
301
} ) ;
278
302
279
- const url = `${ this . endpoint } /availability/calendar` ;
303
+ const url = `${ endpoint } /availability/calendar` ;
280
304
const availability = (
281
305
await Promise . map ( productIds , async ( productId , ix ) => {
282
306
// console.log("PRODUCT ID: " + productId);
@@ -311,6 +335,8 @@ class Plugin {
311
335
async createBooking ( {
312
336
axios,
313
337
token : {
338
+ endpoint,
339
+ apiKey,
314
340
bookingPartnerId,
315
341
} ,
316
342
// ONLY add payload key when absolutely necessary
@@ -525,10 +551,10 @@ class Plugin {
525
551
console . log ( "AFTER UPDATE (data for create booking) : " + JSON . stringify ( dataForBooking ) ) ;
526
552
527
553
const headers = getHeaders ( {
528
- apiKey : this . apiKey ,
554
+ apiKey : apiKey ,
529
555
} ) ;
530
556
531
- const urlForCreateBooking = `${ this . endpoint } /bookings` ;
557
+ const urlForCreateBooking = `${ endpoint } /bookings` ;
532
558
let booking = R . path ( [ 'data' ] , await axios ( {
533
559
method : 'post' ,
534
560
url : urlForCreateBooking ,
@@ -555,7 +581,7 @@ class Plugin {
555
581
} ;
556
582
booking = R . path ( [ 'data' ] , await axios ( {
557
583
method : 'post' ,
558
- url : `${ this . endpoint } /bookings/${ booking . orderUUID } /confirm` ,
584
+ url : `${ endpoint } /bookings/${ booking . orderUUID } /confirm` ,
559
585
data : dataForConfirmBooking ,
560
586
headers,
561
587
} ) ) ;
@@ -565,7 +591,7 @@ class Plugin {
565
591
// Get the booking
566
592
let newBooking = R . path ( [ 'data' ] , await axios ( {
567
593
method : 'get' ,
568
- url : `${ this . endpoint } /bookings/${ booking . id } ` ,
594
+ url : `${ endpoint } /bookings/${ booking . id } ` ,
569
595
data : dataForConfirmBooking ,
570
596
headers,
571
597
} ) ) ;
@@ -583,6 +609,8 @@ class Plugin {
583
609
async cancelBooking ( {
584
610
axios,
585
611
token : {
612
+ endpoint,
613
+ apiKey,
586
614
bookingPartnerId,
587
615
} ,
588
616
// ONLY add payload key when absolutely necessary
@@ -600,9 +628,9 @@ class Plugin {
600
628
} ) {
601
629
assert ( ! isNilOrEmpty ( bookingId ) || ! isNilOrEmpty ( id ) , 'Invalid booking id' ) ;
602
630
const headers = getHeaders ( {
603
- apiKey : this . apiKey ,
631
+ apiKey : apiKey ,
604
632
} ) ;
605
- const url = `${ this . endpoint } /bookings/${ bookingId || id } /cancel` ;
633
+ const url = `${ endpoint } /bookings/${ bookingId || id } /cancel` ;
606
634
const booking = R . path ( [ 'data' ] , await axios ( {
607
635
method : 'post' ,
608
636
url,
@@ -633,6 +661,8 @@ class Plugin {
633
661
async searchBooking ( {
634
662
axios,
635
663
token : {
664
+ endpoint,
665
+ apiKey,
636
666
bookingPartnerId,
637
667
} ,
638
668
// ONLY add payload key when absolutely necessary
@@ -663,28 +693,28 @@ class Plugin {
663
693
) ;
664
694
665
695
const headers = getHeaders ( {
666
- apiKey : this . apiKey ,
696
+ apiKey : apiKey ,
667
697
} ) ;
668
698
669
699
const bookingsFound = await ( async ( ) => {
670
700
if ( ! isNilOrEmpty ( bookingId ) ) {
671
701
console . log ( "BookingID: calling search by URL" ) ;
672
- let url = `${ this . endpoint } /bookings/${ bookingId } ` ;
702
+ let url = `${ endpoint } /bookings/${ bookingId } ` ;
673
703
return [ R . path ( [ 'data' ] , await axios ( {
674
704
method : 'get' ,
675
705
url,
676
706
headers,
677
707
} ) ) ]
678
708
} else if ( ! isNilOrEmpty ( bookingRefId ) ) {
679
709
console . log ( "BookingRefId: calling search by Booking Ref ID" ) ;
680
- let url = `${ this . endpoint } /bookings?bookingRefId=${ bookingRefId } ` ;
710
+ let url = `${ endpoint } /bookings?bookingRefId=${ bookingRefId } ` ;
681
711
return R . path ( [ 'data' , 'bookings' ] , await axios ( {
682
712
method : 'get' ,
683
713
url,
684
714
headers,
685
715
} ) ) ;
686
716
} else {
687
- let url = `${ this . endpoint } /bookings?` ;
717
+ let url = `${ endpoint } /bookings?` ;
688
718
let lastNameFilter = false ;
689
719
let travelDateFilter = false ;
690
720
if ( ! isNilOrEmpty ( name ) ) {
@@ -750,8 +780,9 @@ class Plugin {
750
780
async getCreateBookingFields ( {
751
781
axios,
752
782
token : {
753
- apiKey,
754
783
endpoint,
784
+ apiKey,
785
+ bookingPartnerId,
755
786
octoEnv,
756
787
acceptLanguage,
757
788
resellerId,
@@ -764,7 +795,7 @@ class Plugin {
764
795
} ,
765
796
} ) {
766
797
const headers = getHeaders ( {
767
- apiKey : this . apiKey ,
798
+ apiKey : apiKey ,
768
799
endpoint,
769
800
octoEnv,
770
801
acceptLanguage,
0 commit comments