-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.cjs.js
executable file
·3212 lines (2945 loc) · 108 KB
/
bundle.cjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var get = _interopDefault(require('lodash/get'));
var set = _interopDefault(require('lodash/set'));
var isEmpty = _interopDefault(require('lodash/isEmpty'));
var normalizr = require('normalizr');
var unionBy = _interopDefault(require('lodash/unionBy'));
var union = _interopDefault(require('lodash/union'));
var extend = _interopDefault(require('lodash/extend'));
var camelCase = _interopDefault(require('lodash/camelCase'));
var omit = _interopDefault(require('lodash/omit'));
var reduce = _interopDefault(require('lodash/reduce'));
var some = _interopDefault(require('lodash/some'));
var uniqueId = _interopDefault(require('lodash/uniqueId'));
var map = _interopDefault(require('lodash/map'));
var includes = _interopDefault(require('lodash/includes'));
var each = _interopDefault(require('lodash/each'));
var flatMap = _interopDefault(require('lodash/flatMap'));
var flow = _interopDefault(require('lodash/flow'));
require('isomorphic-fetch');
var assign = _interopDefault(require('lodash/assign'));
var join = _interopDefault(require('lodash/join'));
var pickBy = _interopDefault(require('lodash/pickBy'));
/**
* Where our values are to be stored
* @type {object}
*/
var storage = {};
/**
* Gets a value out of storage
* @param {number|string} key - the key to get from storage
* @param {*} [defaultValue] - value to return if the key is not set
* @returns {*} - the value from storage, if available
*/
function getValue(key, defaultValue) {
return get(storage, key, defaultValue);
}
/**
* Saves a value to storage
* @param {number|string} key - the key to save the value with
* @param {*} value - the value to save in storage
* @returns {object} - storage Object
*/
function setValue(key, value) {
return set(storage, key, value);
}
/**
* Gets the saved execution key from storage
* @returns {string} - the execution key
*/
var getExecutionKey = (function () {
return getValue('execution');
});
/**
* Saves the execution key from the response
* @param {object} response - response from DC
* @returns {boolean} - the execution key was saved
*/
var saveExecutionKey = (function (response) {
var execution = response && response.headers ? response.headers.get('execution') : undefined;
if (!isEmpty(execution)) {
setValue('execution', execution);
return true;
}
return false;
});
/**
* Gets the NetworkLink instance from storage
* @returns {NetworkLink} - the NetworkLink instance
*/
var getNetworkLink = (function () {
return getValue('config').networkLink;
});
var ticketNumbers = new normalizr.schema.Entity('ticketNumbers', undefined, {
idAttribute: 'number'
});
var tickets = new normalizr.schema.Entity('tickets', { ticketNumber: ticketNumbers }, {
idAttribute: function idAttribute(value) {
return get(value, 'ticketNumber.number', 'NA');
},
mergeStrategy: function mergeStrategy(entityA, entityB) {
var ticketCoupon = unionBy(entityA.ticketCoupon, entityB.ticketCoupon, 'couponNumber');
var paymentRefs = union(entityA.paymentRefs, entityB.paymentRefs);
return extend({}, entityA, entityB, {
ticketCoupon: ticketCoupon,
paymentRefs: paymentRefs
});
}
});
var eligibilities = new normalizr.schema.Entity('eligibilities', undefined, {
idAttribute: function idAttribute(value) {
return get(value, 'reason[0].category', 'NA');
}
});
var editCodes = new normalizr.schema.Entity('editCodes');
var airExtras = new normalizr.schema.Entity('airExtras');
var loyaltyAccounts = new normalizr.schema.Entity('loyaltyAccounts');
var flights = new normalizr.schema.Entity('flights');
var boardingPasses = new normalizr.schema.Entity('boardingPasses', {
loyaltyAccount: loyaltyAccounts,
flightDetail: flights,
ticketNumber: ticketNumbers
}, {
idAttribute: function idAttribute(value, parent) {
return parent.id + '-bp';
}
});
var passengerFlights = new normalizr.schema.Entity('passengerFlights', {
eligibilities: { eligibility: [eligibilities] },
boardingPass: boardingPasses
});
var passengerSegments = new normalizr.schema.Entity('passengerSegments', {
editCodes: {
editCode: [editCodes]
},
passengerFlight: [passengerFlights],
airExtra: [airExtras],
eligibilities: { eligibility: [eligibilities] },
loyaltyAccount: loyaltyAccounts
});
var options = {
idAttribute: function idAttribute(value, parent) {
return parent.id;
},
processStrategy: function processStrategy(entity) {
return extend({}, entity.document);
}
};
var passports = new normalizr.schema.Entity('passports', undefined, options);
var nationalIds = new normalizr.schema.Entity('nationalIds', undefined, options);
// todo: add entity for all document types
var passengerDocuments = new normalizr.schema.Array({
passports: passports,
nationalIds: nationalIds
}, function (input) {
return camelCase(get(input, 'document.type', 'unknown')) + 's';
});
var passengers = new normalizr.schema.Entity('passengers', {
ticket: [tickets],
eligibilities: { eligibility: [eligibilities] },
passengerSegments: {
passengerSegment: [passengerSegments]
},
airExtra: [airExtras],
loyaltyAccount: [loyaltyAccounts],
passengerDocument: passengerDocuments
});
var segments = new normalizr.schema.Entity('segments', {
flights: [flights],
eligibilities: { eligibility: [eligibilities] }
}, {
processStrategy: function processStrategy(entity) {
var newEntity = extend({}, entity, { flights: entity.flightDetail });
return omit(newEntity, 'flightDetail');
}
});
var itineraryParts = new normalizr.schema.Entity('itineraries', {
segment: [segments],
eligibilities: { eligibility: [eligibilities] },
airExtra: [airExtras]
});
var reservation = new normalizr.schema.Entity('reservations', {
passengers: { passenger: [passengers] },
itinerary: {
itineraryPart: [itineraryParts],
eligibilities: { eligibility: [eligibilities] }
},
eligibilities: { eligibility: [eligibilities] },
travelOrganizer: {
loyaltyAccount: [loyaltyAccounts]
}
});
var index = (function (input) {
return normalizr.normalize(input, { reservation: reservation });
});
var seatColumns = new normalizr.schema.Entity('columns');
var seats = new normalizr.schema.Entity('seats', undefined, {
idAttribute: 'number'
});
var seatFacilities = new normalizr.schema.Entity('facilities', undefined, {
idAttribute: 'type'
});
var seatSlots = new normalizr.schema.Entity('slots', {
seat: seats,
facility: [seatFacilities]
}, {
idAttribute: function idAttribute(entity, parent) {
return parent.number + '-' + entity.columnRef;
}
});
var seatRows = new normalizr.schema.Entity('rows', {
slot: [seatSlots]
}, {
idAttribute: 'number'
});
var seatCabins = new normalizr.schema.Entity('cabins', {
column: [seatColumns],
row: [seatRows]
}, {
idAttribute: 'bookingClass',
processStrategy: function processStrategy(entity) {
var rowHaveWing = false;
var rows = map(entity.row, function (row, index) {
var rowExtra = { isFacilityRow: false };
if (row && !row.number) {
rowExtra.number = uniqueId('facility_');
rowExtra.isFacilityRow = true;
}
if (row.characteristic && includes(row.characteristic, 'WING')) {
rowExtra.isWing = true;
if (!rowHaveWing && index !== 0) {
rowExtra.isWingBegin = true;
}
rowHaveWing = true;
} else if (rowHaveWing && rowExtra.isFacilityRow) {
rowExtra.isWing = true;
} else if (rowHaveWing) {
set(entity, 'row[' + (index - 1) + '].isWingEnd', true);
rowHaveWing = false;
}
return extend(row, rowExtra);
});
var columns = reduce(entity.column, function (memo, column, columnIndex) {
if (column) {
var addAisle = false;
if (some(column.characteristic, { value: 'AISLE', location: 'RIGHT' })) {
set(column, 'isNextToAisle', true);
set(column, 'isAisleOnRight', true);
addAisle = true;
} else if (some(column.characteristic, { value: 'AISLE', location: 'LEFT' })) {
set(column, 'isNextToAisle', true);
set(column, 'isAisleOnLeft', true);
} else if (some(column.characteristic, { value: 'WINDOW' })) {
set(column, 'isNextToWindow', true);
}
if ((columnIndex === 0 || columnIndex === entity.column.length - 1) && !column.isNextToWindow) {
set(column, 'isNextToWindow', true);
}
memo.push(column);
if (addAisle) {
memo.push({
id: column.id + '_AISLE',
isAisle: true,
name: 'AISLE'
});
}
}
return memo;
}, []);
return extend({}, entity, { column: columns, row: rows });
}
});
var seatPassengers = new normalizr.schema.Entity('seatPassengers', {
passenger: passengers
});
var seatSegments = new normalizr.schema.Entity('segments');
var seatPrices = new normalizr.schema.Entity('prices');
var passengerSeatDetail = new normalizr.schema.Entity('passengerSeatDetails', undefined, {
idAttribute: 'passengerRef'
});
/**
* Transformer Function.
*
* Function to create a empty seatDetail object.
* @access private
* @returns {object}
*/
var createDefaultpassengerSeatDetail = function createDefaultpassengerSeatDetail() {
return {
priceRefs: undefined,
seatFeeWaivers: [],
seatEntitlements: [],
isEntitled: true,
isFeeWaived: false
};
};
/**
* Transformer Function.
*
* Transforms the passengerSeatDetail for enhanced seatmap to a seat entity map.
* @param {object} entity - passengerSeatDetail entity with seatPrice, seatFeeWaiver and seatEntitlement
* @returns {object}
*/
var transformPassengerSeatDetail = function transformPassengerSeatDetail(entity) {
if (!entity) {
return entity;
}
return reduce(entity.passengerSeatDetail, function (memo, passengerSeatDetail) {
var seatDetails = {};
reduce(passengerSeatDetail.seatPrice, function (priceMemo, seatPrice) {
each(seatPrice.value, function (value) {
if (!priceMemo[value]) {
set(priceMemo, [value], createDefaultpassengerSeatDetail());
}
set(priceMemo, [value, 'priceRefs'], seatPrice.priceRef);
return priceMemo;
});
return priceMemo;
}, seatDetails);
reduce(passengerSeatDetail.seatFeeWaiver, function (priceMemo, seatFeeWaiver) {
each(seatFeeWaiver.value, function (value) {
if (!priceMemo[value]) {
set(priceMemo, [value], createDefaultpassengerSeatDetail());
}
set(priceMemo, [value, 'isFeeWaived'], priceMemo[value].isFeeWaived || seatFeeWaiver.waived);
priceMemo[value].seatFeeWaivers.push(seatFeeWaiver.ruleId);
return priceMemo;
});
return priceMemo;
}, seatDetails);
reduce(passengerSeatDetail.seatEntitlement, function (priceMemo, seatEntitlement) {
each(seatEntitlement.value, function (value) {
if (!priceMemo[value]) {
set(priceMemo, [value], createDefaultpassengerSeatDetail());
}
set(priceMemo, [value, 'isEntitled'], priceMemo[value].isEntitled && seatEntitlement.entitled);
priceMemo[value].seatEntitlements.push(seatEntitlement.ruleId);
return priceMemo;
});
return priceMemo;
}, seatDetails);
each(passengerSeatDetail.passengerRefs, function (passengerRef) {
memo.push(extend({}, { seatDetails: seatDetails }, { passengerRef: passengerRef }));
});
return memo;
}, []);
};
var seatMaps = (function (input) {
var normalizedOutput = normalizr.normalize(input, { passengers: { seatMapPassenger: [seatPassengers] } });
var segments = map(get(input, 'seatMap'), 'segment');
normalizedOutput.entities.seatMaps = reduce(get(input, 'seatMap'), function (memo, seatMap) {
if (seatMap) {
var segmentId = get(seatMap, 'segment.id', uniqueId('s'));
set(seatMap, 'passengerSeatDetails', transformPassengerSeatDetail(seatMap.passengerSeatDetails));
set(seatMap, 'segment.id', segmentId);
set(memo, seatMap.id, normalizr.normalize(seatMap, {
cabin: [seatCabins], segment: seatSegments, pricing: { price: [seatPrices] }, passengerSeatDetails: [passengerSeatDetail]
}));
}
return memo;
}, {});
normalizedOutput.result.segments = segments;
if (normalizedOutput.result.seatMap) {
normalizedOutput.result.seatMap = map(normalizedOutput.result.seatMap, 'id');
}
if (get(normalizedOutput, ['entities', 'seatPassengers'])) {
normalizedOutput.result.relations = flatMap(get(normalizedOutput, 'entities.seatMaps'), function (seatMap) {
var segmentId = get(seatMap, 'result.segment', '');
var _get = get(seatMap, ['entities', 'segments', segmentId]),
airline = _get.airline,
flightNumber = _get.flightNumber,
departureAirport = _get.departureAirport,
arrivalAirport = _get.arrivalAirport,
departureDate = _get.departureDate,
bookingClass = _get.bookingClass,
equipment = _get.equipment;
return flatMap(get(seatMap, 'result.passengerSeatDetails'), function (passengerRef) {
return {
seatPassenger: passengerRef,
seatMap: seatMap.result.id,
airline: airline,
flightNumber: flightNumber,
departureAirport: departureAirport,
arrivalAirport: arrivalAirport,
departureDate: departureDate,
bookingClass: bookingClass,
equipment: equipment,
passenger: get(normalizedOutput, ['entities', 'seatPassengers', passengerRef, 'passenger'])
};
});
}, []);
} else {
normalizedOutput.result.relations = flatMap(get(normalizedOutput, 'entities.seatMaps'), function (seatMap) {
var segmentId = get(seatMap, 'result.segment', '');
var _get2 = get(seatMap, ['entities', 'segments', segmentId]),
airline = _get2.airline,
flightNumber = _get2.flightNumber,
departureAirport = _get2.departureAirport,
arrivalAirport = _get2.arrivalAirport,
departureDate = _get2.departureDate,
bookingClass = _get2.bookingClass,
equipment = _get2.equipment;
return {
seatPassenger: 'ALL',
seatMap: seatMap.result.id,
airline: airline,
flightNumber: flightNumber,
departureAirport: departureAirport,
arrivalAirport: arrivalAirport,
departureDate: departureDate,
bookingClass: bookingClass,
equipment: equipment,
passenger: 'ALL'
};
});
}
return normalizedOutput;
});
var checkin = Object.freeze({
pnrNormalizer: index,
seatMapNormalizer: seatMaps
});
var availableNormalizers = {
checkin: checkin
};
/**
* @param {object} json - JSON result of a service call
* @param {*} [normalizers=false] - callback function to be invoked after service
* @returns {*} result of invoking service and running the response through normalizers
*/
var normalizeResponse = function normalizeResponse(json) {
var normalizers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (normalizers) {
if (typeof normalizers === 'function') {
return flow([normalizers])(json);
} else if (normalizers instanceof Array) {
var builtFlows = [];
each(normalizers, function (normalizer) {
var resolvedNormalizer = get(availableNormalizers, normalizer);
if (resolvedNormalizer && typeof resolvedNormalizer === 'function') {
builtFlows.push(resolvedNormalizer);
} else {
throw new Error('Unable to resolve path with argument "' + normalizer + '". Please send a valid path to a normalizer.');
}
});
return flow(builtFlows)(json);
}
}
return json;
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
var get$1 = function get$$1(object, property, receiver) {
if (object === null) object = Function.prototype;
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent === null) {
return undefined;
} else {
return get$$1(parent, property, receiver);
}
} else if ("value" in desc) {
return desc.value;
} else {
var getter = desc.get;
if (getter === undefined) {
return undefined;
}
return getter.call(receiver);
}
};
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
/** Class handling http calls to Digital Connect instance */
var NetworkLink = function () {
/**
* Create an instance for network calls
*
* @param {object} [args] - argument object
* @param {object} [headers={}] - headers to be added to each request
* @param {function} [shouldRetry] - a function to determine if the SDK should retry the same call again in case of network error
*/
function NetworkLink(_ref) {
var _ref$headers = _ref.headers,
headers = _ref$headers === undefined ? {} : _ref$headers,
shouldRetry = _ref.shouldRetry;
classCallCheck(this, NetworkLink);
/**
* Headers to be sent in each request
* @type {Object}
*/
this.headers = headers;
/**
* the function to be called to determine if the sdk should retry the request
* @type {function}
*/
this.shouldRetry = shouldRetry;
}
/**
* Entry method.
*
* Invokes function supplied to build the network request.
* Sends request down the pipe.
* @param {function} invoke - builds the URL & body of the request about to be sent
* @returns {Promise}
*/
createClass(NetworkLink, [{
key: 'buildRequest',
value: function buildRequest(invoke) {
var _this = this;
var _getValue = getValue('config'),
baseUrl = _getValue.baseUrl,
storefront = _getValue.storefront,
headers = _getValue.headers,
agent = _getValue.agent;
var execution = getExecutionKey();
var requestParameters = invoke({
headers: headers, baseUrl: baseUrl, storefront: storefront, execution: execution
});
var requestUrl = requestParameters.url + '?' + NetworkLink.buildQueryString(requestParameters.queryParameters);
return this.sendRequest(requestUrl, _extends({}, requestParameters.body, { agent: agent })).then(function (response) {
var status = response.status;
if (status !== 200) {
return response.json().then(function (json) {
throw assign({}, json, { status: status });
});
}
return response.json().then(function (json) {
var processedJson = _this.postResponseProcessing(response, json);
return normalizeResponse(processedJson, requestParameters.normalizers);
});
});
}
/**
* Builds the query parameter string
*
* @param {array|object} queryParameters - parameters to include in the URL
*/
}, {
key: 'sendRequest',
/**
* Sends the request down the network tube
*
* @access private
* @param {string} url - URL the request goes to
* @param {object} args - arguments object
* @param {string} args.method - HTTP method to use for Request e.g. GET, POST, PUT
* @param {object} args.body - body of the HTTP call
* @param {string} args.agent - agent to use for the HTTP call
* @param {function} args.shouldRetry - a function to determine if the SDK should retry the same call again in case of network error
* @returns {Promise}
*/
value: function sendRequest(url, _ref2) {
var _this2 = this;
var method = _ref2.method,
body = _ref2.body,
agent = _ref2.agent,
shouldRetry = _ref2.shouldRetry;
var options = this.wrapRequest(method, body, agent);
var shouldRetryFn = shouldRetry || this.shouldRetry;
var now = Date.now();
this.onBeforeSend({ url: url, options: options });
var successHandler = function successHandler(response) {
return _this2.onComplete({
url: url,
options: options,
response: response,
took: Date.now() - now
});
};
var errorHandler = function errorHandler(error) {
return _this2.onComplete({
url: url,
options: options,
error: error,
took: Date.now() - now
});
};
if (shouldRetryFn === undefined) {
return fetch(url, options).then(function (response) {
successHandler(response);
return Promise.resolve(response);
}).catch(function (error) {
errorHandler(error);
throw error;
});
}
return fetch(url, options).then(function (response) {
successHandler(response);
return Promise.resolve(response);
}).catch(function (error) {
errorHandler(error);
if (!shouldRetryFn({ error: error, url: url, options: options })) {
throw error;
}
return fetch(url, options);
});
}
/**
* Wraps the request with appropriate headers and other properties for call to work in DC
*
* @access private
* @param {string} method - HTTP method to use for Request e.g. GET, POST, PUT
* @param {object} body - body of the HTTP call
* @param {string} agent - agent to use for the HTTP call
* @returns {object} {agent: string, body: object, credentials: string, method: string, headers: object}
*/
}, {
key: 'wrapRequest',
value: function wrapRequest(method, body, agent) {
var headers = assign({
Accept: 'application/json',
'Content-Type': 'application/json'
}, this.headers);
return {
agent: agent,
body: JSON.stringify(body),
credentials: 'include',
method: method,
headers: headers
};
}
/**
* Handles processing the response.
* Useful for setting cookies/execution key/headers returned from the request
*
* @access private
* @param {object} response - response returned by the service
* @param {object} json - json response from the service call
* @return {object} response - the http call response
*/
}, {
key: 'postResponseProcessing',
value: function postResponseProcessing(response, json) {
saveExecutionKey(response);
if (response.headers) {
this.saveHeaders(response.headers);
}
return json;
}
/**
* triggered when the request completed, regardless the response status
*
* @access private
* @param {string} url - the request url
* @param {object} options - the request options
* @param {object} error - the error thrown
* @return {object} response - the http call response
*/
}, {
key: 'onComplete',
value: function onComplete(_ref3) {
var url = _ref3.url,
options = _ref3.options,
response = _ref3.response,
error = _ref3.error;
} // eslint-disable-line no-unused-vars,class-methods-use-this,object-curly-newline
/**
* triggered before the request sent to the server
*
* @access private
* @param {string} url - the request url
* @param {object} options - the request options
* @param {object} error - the error thrown
* @return {object} response - the http call response
*/
}, {
key: 'onBeforeSend',
value: function onBeforeSend(_ref4) {
var url = _ref4.url,
options = _ref4.options;
} // eslint-disable-line no-unused-vars,class-methods-use-this,object-curly-newline
/**
* Saves appropriate headers for response
*
* @access private
* @param {Map} headers - headers returned by network request
*/
}, {
key: 'saveHeaders',
value: function saveHeaders(headers) {
var sessionId = headers.get('session-id');
if (sessionId) {
this.headers['Session-ID'] = sessionId;
}
}
}], [{
key: 'buildQueryString',
value: function buildQueryString(queryParameters) {
return join(map(pickBy(queryParameters), function (value, name) {
return name + '=' + value;
}), '&');
}
}]);
return NetworkLink;
}();
/** Class handling http calls to Digital Connect instance that saves cookies */
var CookingSavingNetworkLink = function (_NetworkLink) {
inherits(CookingSavingNetworkLink, _NetworkLink);
function CookingSavingNetworkLink() {
classCallCheck(this, CookingSavingNetworkLink);
return possibleConstructorReturn(this, (CookingSavingNetworkLink.__proto__ || Object.getPrototypeOf(CookingSavingNetworkLink)).apply(this, arguments));
}
createClass(CookingSavingNetworkLink, [{
key: 'postResponseProcessing',
/**
* @override
* @param response
*/
value: function postResponseProcessing(response) {
get$1(CookingSavingNetworkLink.prototype.__proto__ || Object.getPrototypeOf(CookingSavingNetworkLink.prototype), 'postResponseProcessing', this).call(this, response);
var cookie = response.headers.get('set-cookie');
if (cookie.includes('JSESSION')) {
this.headers.cookie = response.headers.get('set-cookie');
}
}
}]);
return CookingSavingNetworkLink;
}(NetworkLink);
/**
* Initialize a Sabre DC SDK Client instance
* @param {object} args - Initialize function arguments
* @param {string} args.baseUrl - Base URL for DC instance
* @param {string} args.storefront - Storefront associated with this instance
* @param {object} args.headers - additional headers to be supplied to each request
* @param {NetworkLink} [args.networkLink] - NetworkLink instance to use (overwrites default)
* @param {function} args.shouldRetry - a function to determine if the SDK should retry the same call again in case of network error
*/
var initialize = (function (_ref) {
var baseUrl = _ref.baseUrl,
storefront = _ref.storefront,
headers = _ref.headers,
networkLink = _ref.networkLink,
agent = _ref.agent,
shouldRetry = _ref.shouldRetry;
setValue('config', {
baseUrl: baseUrl, storefront: storefront, headers: headers, networkLink: networkLink || new NetworkLink({ headers: headers, shouldRetry: shouldRetry }), agent: agent
});
});
/**
* Execute a flight search
* @param {object} args - argument object
* @param {string} args.cabinClass - cabin class to search for
* @param {boolean} args.awardBooking - award booking flag
* @param {string} args.searchType - search type
* @param {Array<string>} args.promoCodes - promo codes to apply to search
* @param {Array<object>} args.itineraryParts - Itinerary parts defined by DC to search for
* @param {object} args.passengers - passengers counts to be included in search
*/
var flightSearch = function flightSearch(_ref) {
var cabinClass = _ref.cabinClass,
awardBooking = _ref.awardBooking,
searchType = _ref.searchType,
promoCodes = _ref.promoCodes,
itineraryParts = _ref.itineraryParts,
passengers = _ref.passengers;
return getNetworkLink().buildRequest(function (_ref2) {
var headers = _ref2.headers,
baseUrl = _ref2.baseUrl,
storefront = _ref2.storefront;
return {
url: baseUrl + '/products/air/search',
queryParameters: {
jipcc: storefront
},
body: {
method: 'POST',
body: {
cabinClass: cabinClass, awardBooking: awardBooking, searchType: searchType, promoCodes: promoCodes, itineraryParts: itineraryParts, passengers: passengers
},
headers: headers
}
};
});
};
/**
* Creates the URL string for selecting flights
*
* @access private
* @param {Array<number>} selectFlights - flight has codes to select
* @returns {string} URL Query parameter of flights to select
*/
function createSelectFlightString(selectFlights) {
var prefix = 'selectFlights=';
return join(selectFlights, prefix + '&');
}
/**
* Select flights
* @param {Array<number>} selectFlights - flight has codes to select
*/
var flightSelect = function flightSelect(_ref) {
var selectFlights = _ref.selectFlights;
return getNetworkLink().buildRequest(function (_ref2) {
var headers = _ref2.headers,
baseUrl = _ref2.baseUrl,
storefront = _ref2.storefront,
execution = _ref2.execution;
return {
url: baseUrl + '/products/air',
queryParameters: {
jipcc: storefront,
execution: execution,
selectFlights: createSelectFlightString(selectFlights)
},
body: {
method: 'POST',
headers: headers
}
};
});
};
/**
* Add Passenger to Itinerary
* @param {object} args - argument object
* @param {Array<object>} args.passengers - Passengers object defined by DC
* @param {object} args.businessLoyalty - businessLoyalty object defined by DC
* @param {object} args.contact - contact info defined by DC
*/
var addPassengers = function addPassengers(_ref) {
var passengers = _ref.passengers,
businessLoyalty = _ref.businessLoyalty,
contact = _ref.contact;
return getNetworkLink().buildRequest(function (_ref2) {
var headers = _ref2.headers,