sabre-legacy-client 0.1.1 → 0.1.2
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.
- package/README.md +18 -3
- package/dist/index.d.mts +23 -55
- package/dist/index.d.ts +23 -55
- package/dist/index.js +74 -103
- package/dist/index.mjs +71 -102
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
# Sabre Node.js SDK
|
|
2
2
|
|
|
3
|
-
Node.js library for the Sabre API.
|
|
3
|
+
Node.js library for the Sabre API (SOAP).
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install sabre-legacy-client
|
|
9
|
-
# or
|
|
10
|
-
yarn add sabre-legacy-client
|
|
11
9
|
```
|
|
12
10
|
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
First, you need to get an username, password and pcc which is available in the [DEV STUDIO - Applications](https://developer.sabre.com/my-account/applications).
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { SabreLegacy } from 'sabre-legacy-client';
|
|
17
|
+
const sabre = new SabreLegacy({
|
|
18
|
+
username: '773400',
|
|
19
|
+
password: 'PASSWORD_GOES_HERE',
|
|
20
|
+
organization: '7TZA', // pcc
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Documentation
|
|
25
|
+
|
|
26
|
+
See http://developer.sabre.com
|
|
27
|
+
|
|
13
28
|
## License
|
|
14
29
|
|
|
15
30
|
MIT License
|
package/dist/index.d.mts
CHANGED
|
@@ -15,29 +15,12 @@ declare enum ActionsRS {
|
|
|
15
15
|
QUEUE_ACCESS = "QueueAccessLLSRS"
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
declare const SABRE_ERROR_CODES_BY_KEY: {
|
|
19
|
-
readonly missing_required_field: 422;
|
|
20
|
-
readonly invalid_access: 422;
|
|
21
|
-
readonly invalid_parameter: 422;
|
|
22
|
-
readonly invalid_region: 422;
|
|
23
|
-
readonly rate_limit_exceeded: 429;
|
|
24
|
-
readonly missing_api_key: 401;
|
|
25
|
-
readonly invalid_api_Key: 403;
|
|
26
|
-
readonly invalid_from_address: 403;
|
|
27
|
-
readonly validation_error: 403;
|
|
28
|
-
readonly not_found: 404;
|
|
29
|
-
readonly method_not_allowed: 405;
|
|
30
|
-
readonly error_in_response: 405;
|
|
31
|
-
readonly fault_error: 500;
|
|
32
|
-
readonly application_error: 500;
|
|
33
|
-
readonly internal_server_error: 500;
|
|
34
|
-
};
|
|
35
|
-
type SABRE_ERROR_CODE_KEY = keyof typeof SABRE_ERROR_CODES_BY_KEY;
|
|
36
|
-
interface ErrorResponse {
|
|
37
|
-
message: string;
|
|
38
|
-
name: SABRE_ERROR_CODE_KEY;
|
|
39
|
-
}
|
|
40
18
|
type Actions = ActionsRQ | ActionsRS;
|
|
19
|
+
interface SabreOptions {
|
|
20
|
+
username?: string;
|
|
21
|
+
password?: string;
|
|
22
|
+
organization?: string;
|
|
23
|
+
}
|
|
41
24
|
|
|
42
25
|
interface PostOptions {
|
|
43
26
|
query?: {
|
|
@@ -53,22 +36,10 @@ interface HeadersRequestOptions {
|
|
|
53
36
|
declare class Authentication {
|
|
54
37
|
private readonly sabre;
|
|
55
38
|
constructor(sabre: Sabre);
|
|
56
|
-
sessionCreate(): Promise<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
sessionClose(): Promise<{
|
|
61
|
-
data: unknown;
|
|
62
|
-
error: ErrorResponse | null;
|
|
63
|
-
}>;
|
|
64
|
-
ping(): Promise<{
|
|
65
|
-
data: unknown;
|
|
66
|
-
error: ErrorResponse | null;
|
|
67
|
-
}>;
|
|
68
|
-
tokenCreate(): Promise<{
|
|
69
|
-
data: string | null;
|
|
70
|
-
error: ErrorResponse | null;
|
|
71
|
-
}>;
|
|
39
|
+
sessionCreate(): Promise<string>;
|
|
40
|
+
sessionClose(): Promise<unknown>;
|
|
41
|
+
ping(): Promise<unknown>;
|
|
42
|
+
tokenCreate(): Promise<string>;
|
|
72
43
|
}
|
|
73
44
|
|
|
74
45
|
interface ApplicationResults {
|
|
@@ -371,28 +342,25 @@ interface SessionCreateOptions {
|
|
|
371
342
|
}
|
|
372
343
|
|
|
373
344
|
declare class Sabre {
|
|
374
|
-
private readonly username?;
|
|
375
|
-
private readonly password?;
|
|
376
|
-
private readonly organization?;
|
|
377
345
|
private readonly headers;
|
|
378
346
|
private readonly headersRequest;
|
|
347
|
+
private readonly options;
|
|
379
348
|
readonly authentication: Authentication;
|
|
380
349
|
readonly queue: Queue;
|
|
381
350
|
readonly dailySales: DailySales;
|
|
382
|
-
constructor(
|
|
351
|
+
constructor(options: SabreOptions);
|
|
383
352
|
setAction(action: Actions): void;
|
|
384
|
-
fetchRequest<T>(options?: {}): Promise<
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}>;
|
|
353
|
+
fetchRequest<T>(options?: {}): Promise<T>;
|
|
354
|
+
post<T>(handlerRequest: (payload: HeadersRequestOptions) => string, options?: PostOptions): Promise<T>;
|
|
355
|
+
auth<T>(handlerRequest: (payload: SessionCreateOptions) => string, options?: PostOptions): Promise<T>;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
declare class ErrorInResponse extends Error {
|
|
359
|
+
constructor(message: string);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
declare class FaultError extends Error {
|
|
363
|
+
constructor(message: string);
|
|
396
364
|
}
|
|
397
365
|
|
|
398
|
-
export { type DailySalesReportRS, type DailySalesReportResponseSuccess, type DailySalesSummaryRS, type DailySalesSummaryResponseSuccess,
|
|
366
|
+
export { type DailySalesReportRS, type DailySalesReportResponseSuccess, type DailySalesSummaryRS, type DailySalesSummaryResponseSuccess, ErrorInResponse, FaultError, type QueueAccessOptions, type QueueAccessResponse, type QueueCountResponse, type QueueIgnoreResponse, type QueuePlaceOptions, type QueuePlaceResponse, type QueueRemoveResponse, type ReportOptions, Sabre as SabreLegacy, type SummaryOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -15,29 +15,12 @@ declare enum ActionsRS {
|
|
|
15
15
|
QUEUE_ACCESS = "QueueAccessLLSRS"
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
declare const SABRE_ERROR_CODES_BY_KEY: {
|
|
19
|
-
readonly missing_required_field: 422;
|
|
20
|
-
readonly invalid_access: 422;
|
|
21
|
-
readonly invalid_parameter: 422;
|
|
22
|
-
readonly invalid_region: 422;
|
|
23
|
-
readonly rate_limit_exceeded: 429;
|
|
24
|
-
readonly missing_api_key: 401;
|
|
25
|
-
readonly invalid_api_Key: 403;
|
|
26
|
-
readonly invalid_from_address: 403;
|
|
27
|
-
readonly validation_error: 403;
|
|
28
|
-
readonly not_found: 404;
|
|
29
|
-
readonly method_not_allowed: 405;
|
|
30
|
-
readonly error_in_response: 405;
|
|
31
|
-
readonly fault_error: 500;
|
|
32
|
-
readonly application_error: 500;
|
|
33
|
-
readonly internal_server_error: 500;
|
|
34
|
-
};
|
|
35
|
-
type SABRE_ERROR_CODE_KEY = keyof typeof SABRE_ERROR_CODES_BY_KEY;
|
|
36
|
-
interface ErrorResponse {
|
|
37
|
-
message: string;
|
|
38
|
-
name: SABRE_ERROR_CODE_KEY;
|
|
39
|
-
}
|
|
40
18
|
type Actions = ActionsRQ | ActionsRS;
|
|
19
|
+
interface SabreOptions {
|
|
20
|
+
username?: string;
|
|
21
|
+
password?: string;
|
|
22
|
+
organization?: string;
|
|
23
|
+
}
|
|
41
24
|
|
|
42
25
|
interface PostOptions {
|
|
43
26
|
query?: {
|
|
@@ -53,22 +36,10 @@ interface HeadersRequestOptions {
|
|
|
53
36
|
declare class Authentication {
|
|
54
37
|
private readonly sabre;
|
|
55
38
|
constructor(sabre: Sabre);
|
|
56
|
-
sessionCreate(): Promise<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
sessionClose(): Promise<{
|
|
61
|
-
data: unknown;
|
|
62
|
-
error: ErrorResponse | null;
|
|
63
|
-
}>;
|
|
64
|
-
ping(): Promise<{
|
|
65
|
-
data: unknown;
|
|
66
|
-
error: ErrorResponse | null;
|
|
67
|
-
}>;
|
|
68
|
-
tokenCreate(): Promise<{
|
|
69
|
-
data: string | null;
|
|
70
|
-
error: ErrorResponse | null;
|
|
71
|
-
}>;
|
|
39
|
+
sessionCreate(): Promise<string>;
|
|
40
|
+
sessionClose(): Promise<unknown>;
|
|
41
|
+
ping(): Promise<unknown>;
|
|
42
|
+
tokenCreate(): Promise<string>;
|
|
72
43
|
}
|
|
73
44
|
|
|
74
45
|
interface ApplicationResults {
|
|
@@ -371,28 +342,25 @@ interface SessionCreateOptions {
|
|
|
371
342
|
}
|
|
372
343
|
|
|
373
344
|
declare class Sabre {
|
|
374
|
-
private readonly username?;
|
|
375
|
-
private readonly password?;
|
|
376
|
-
private readonly organization?;
|
|
377
345
|
private readonly headers;
|
|
378
346
|
private readonly headersRequest;
|
|
347
|
+
private readonly options;
|
|
379
348
|
readonly authentication: Authentication;
|
|
380
349
|
readonly queue: Queue;
|
|
381
350
|
readonly dailySales: DailySales;
|
|
382
|
-
constructor(
|
|
351
|
+
constructor(options: SabreOptions);
|
|
383
352
|
setAction(action: Actions): void;
|
|
384
|
-
fetchRequest<T>(options?: {}): Promise<
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}>;
|
|
353
|
+
fetchRequest<T>(options?: {}): Promise<T>;
|
|
354
|
+
post<T>(handlerRequest: (payload: HeadersRequestOptions) => string, options?: PostOptions): Promise<T>;
|
|
355
|
+
auth<T>(handlerRequest: (payload: SessionCreateOptions) => string, options?: PostOptions): Promise<T>;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
declare class ErrorInResponse extends Error {
|
|
359
|
+
constructor(message: string);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
declare class FaultError extends Error {
|
|
363
|
+
constructor(message: string);
|
|
396
364
|
}
|
|
397
365
|
|
|
398
|
-
export { type DailySalesReportRS, type DailySalesReportResponseSuccess, type DailySalesSummaryRS, type DailySalesSummaryResponseSuccess,
|
|
366
|
+
export { type DailySalesReportRS, type DailySalesReportResponseSuccess, type DailySalesSummaryRS, type DailySalesSummaryResponseSuccess, ErrorInResponse, FaultError, type QueueAccessOptions, type QueueAccessResponse, type QueueCountResponse, type QueueIgnoreResponse, type QueuePlaceOptions, type QueuePlaceResponse, type QueueRemoveResponse, type ReportOptions, Sabre as SabreLegacy, type SummaryOptions };
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
23
|
+
ErrorInResponse: () => ErrorInResponse,
|
|
24
|
+
FaultError: () => FaultError,
|
|
25
|
+
SabreLegacy: () => Sabre
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(index_exports);
|
|
26
28
|
|
|
@@ -37,7 +39,7 @@ function getSubString(strSearch, strBegin, strEnd, withEnd) {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
// package.json
|
|
40
|
-
var version = "0.1.
|
|
42
|
+
var version = "0.1.1";
|
|
41
43
|
|
|
42
44
|
// src/config.ts
|
|
43
45
|
var defaultBaseUrl = "https://webservices.platform.sabre.com";
|
|
@@ -326,12 +328,11 @@ var Queue = class {
|
|
|
326
328
|
}
|
|
327
329
|
if (!pcc) throw new Error('Missing pcc. Set it in count("PCC")');
|
|
328
330
|
this.sabre.setAction("QueueCountLLSRQ" /* QUEUE_COUNT */);
|
|
329
|
-
const
|
|
331
|
+
const xml = await this.sabre.post((opts) => countRequest({
|
|
330
332
|
pcc,
|
|
331
333
|
...opts
|
|
332
334
|
}));
|
|
333
|
-
|
|
334
|
-
return parseXMLToQueueCount(response.data);
|
|
335
|
+
return parseXMLToQueueCount(xml);
|
|
335
336
|
}
|
|
336
337
|
async access(payload) {
|
|
337
338
|
if (!payload.pcc) {
|
|
@@ -342,14 +343,13 @@ var Queue = class {
|
|
|
342
343
|
if (!payload.pcc) throw new Error("Missing pcc. Set it in access({ pcc, number })");
|
|
343
344
|
const { number, pcc } = payload;
|
|
344
345
|
this.sabre.setAction("QueueAccessLLSRS" /* QUEUE_ACCESS */);
|
|
345
|
-
const
|
|
346
|
+
const xml = await this.sabre.post((opts) => accessRequest({
|
|
346
347
|
number,
|
|
347
348
|
pcc,
|
|
348
349
|
...opts
|
|
349
350
|
}));
|
|
350
|
-
if (!response.data) throw new Error(`Response error ${response.error}`);
|
|
351
351
|
this.meta.queue = number;
|
|
352
|
-
const queueAccess2 = parseXMLToQueueAccess(
|
|
352
|
+
const queueAccess2 = parseXMLToQueueAccess(xml);
|
|
353
353
|
return formatQueueResponse({
|
|
354
354
|
bookingId: queueAccess2.line.uniqueID.iD,
|
|
355
355
|
paragraph: queueAccess2.paragraph,
|
|
@@ -358,9 +358,8 @@ var Queue = class {
|
|
|
358
358
|
}
|
|
359
359
|
async ignore() {
|
|
360
360
|
this.sabre.setAction("QueueAccessLLSRS" /* QUEUE_ACCESS */);
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
const queueAccess2 = parseXMLToQueueAccess(response.data);
|
|
361
|
+
const xml = await this.sabre.post(ignoreRequest);
|
|
362
|
+
const queueAccess2 = parseXMLToQueueAccess(xml);
|
|
364
363
|
return formatQueueResponse({
|
|
365
364
|
bookingId: queueAccess2.line.uniqueID.iD,
|
|
366
365
|
paragraph: queueAccess2.paragraph,
|
|
@@ -369,9 +368,8 @@ var Queue = class {
|
|
|
369
368
|
}
|
|
370
369
|
async remove() {
|
|
371
370
|
this.sabre.setAction("QueueAccessLLSRS" /* QUEUE_ACCESS */);
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
const queueAccess2 = parseXMLToQueueAccess(response.data);
|
|
371
|
+
const xml = await this.sabre.post(removeRequest);
|
|
372
|
+
const queueAccess2 = parseXMLToQueueAccess(xml);
|
|
375
373
|
return formatQueueResponse({
|
|
376
374
|
bookingId: queueAccess2.line.uniqueID.iD,
|
|
377
375
|
paragraph: queueAccess2.paragraph,
|
|
@@ -391,13 +389,12 @@ var Queue = class {
|
|
|
391
389
|
if (!payload.pcc) throw new Error("Missing pcc. Set it in place({ pcc, number })");
|
|
392
390
|
const { number, pcc } = payload;
|
|
393
391
|
this.sabre.setAction("QueuePlaceLLSRQ" /* QUEUE_PLACE */);
|
|
394
|
-
const
|
|
392
|
+
const xml = await this.sabre.post((opts) => placeRequest({
|
|
395
393
|
number,
|
|
396
394
|
pcc,
|
|
397
395
|
...opts
|
|
398
396
|
}));
|
|
399
|
-
|
|
400
|
-
const queuePlace2 = parseXMLToQueuePlace(response.data);
|
|
397
|
+
const queuePlace2 = parseXMLToQueuePlace(xml);
|
|
401
398
|
return formatQueueResponse({
|
|
402
399
|
bookingId: findBookingId(queuePlace2.text.pop()),
|
|
403
400
|
paragraph: { text: queuePlace2.text },
|
|
@@ -478,9 +475,8 @@ var DailySales = class {
|
|
|
478
475
|
if (!payload.pcc) throw new Error("Missing pcc. Set it in report({ pcc, number })");
|
|
479
476
|
const { pcc, date } = payload;
|
|
480
477
|
this.sabre.setAction("DailySalesReportLLSRQ" /* DAILY_SALES_REPORT */);
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
return parseXMLToDailySalesReport(response.data);
|
|
478
|
+
const xml = await this.sabre.post((headersPayload) => reportRequest({ pcc, date, ...headersPayload }));
|
|
479
|
+
return parseXMLToDailySalesReport(xml);
|
|
484
480
|
}
|
|
485
481
|
async summary(payload) {
|
|
486
482
|
if (!payload.pcc) {
|
|
@@ -491,26 +487,45 @@ var DailySales = class {
|
|
|
491
487
|
if (!payload.pcc) throw new Error("Missing pcc. Set it in summary({ pcc, ... })");
|
|
492
488
|
const { pcc } = payload;
|
|
493
489
|
this.sabre.setAction("DailySalesReportLLSRQ" /* DAILY_SALES_REPORT */);
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
|
|
490
|
+
const xml = await this.sabre.post((headersPayload) => summaryRequest({ pcc, ...payload, ...headersPayload }));
|
|
491
|
+
return parseXMLToDailySalesSummary(xml);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// src/common/utils/fault-error.ts
|
|
496
|
+
var FaultError = class extends Error {
|
|
497
|
+
constructor(message) {
|
|
498
|
+
super(message);
|
|
499
|
+
this.name = "FaultError";
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// src/common/utils/error-in-response.ts
|
|
504
|
+
var ErrorInResponse = class extends Error {
|
|
505
|
+
constructor(message) {
|
|
506
|
+
super(message);
|
|
507
|
+
this.name = "ErrorInResponse";
|
|
497
508
|
}
|
|
498
509
|
};
|
|
499
510
|
|
|
500
511
|
// src/sabre.ts
|
|
501
512
|
var Sabre = class {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
513
|
+
headers;
|
|
514
|
+
headersRequest;
|
|
515
|
+
options = {};
|
|
516
|
+
authentication = new Authentication(this);
|
|
517
|
+
queue = new Queue(this);
|
|
518
|
+
dailySales = new DailySales(this);
|
|
519
|
+
constructor(options2) {
|
|
520
|
+
const { username, password, organization } = options2;
|
|
506
521
|
const processEnv = typeof process !== "undefined" && process.env;
|
|
507
522
|
if (!username && processEnv)
|
|
508
|
-
this.username = processEnv.SABRE_USERNAME;
|
|
523
|
+
this.options.username = processEnv.SABRE_USERNAME;
|
|
509
524
|
if (!password && processEnv)
|
|
510
|
-
this.password = processEnv.SABRE_PASSWORD;
|
|
525
|
+
this.options.password = processEnv.SABRE_PASSWORD;
|
|
511
526
|
if (!organization && processEnv)
|
|
512
|
-
this.organization = processEnv.SABRE_ORGANIZATION;
|
|
513
|
-
if (!this.username || !this.password || !this.organization) {
|
|
527
|
+
this.options.organization = processEnv.SABRE_ORGANIZATION;
|
|
528
|
+
if (!this.options.username || !this.options.password || !this.options.organization) {
|
|
514
529
|
throw new Error('Missing LegacySabre authorization. Pass it to the constructor `new LegacySabre("USERNAME", "PASSWORD", "ORGANIZATION")');
|
|
515
530
|
}
|
|
516
531
|
this.headers = new Headers({
|
|
@@ -523,78 +538,32 @@ var Sabre = class {
|
|
|
523
538
|
authorization: ""
|
|
524
539
|
};
|
|
525
540
|
}
|
|
526
|
-
headers;
|
|
527
|
-
headersRequest;
|
|
528
|
-
authentication = new Authentication(this);
|
|
529
|
-
queue = new Queue(this);
|
|
530
|
-
dailySales = new DailySales(this);
|
|
531
541
|
setAction(action) {
|
|
532
542
|
this.headers.set("SOAPAction", action);
|
|
533
543
|
}
|
|
534
544
|
async fetchRequest(options2 = {}) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
const error2 = {
|
|
559
|
-
message: response.statusText,
|
|
560
|
-
name: "application_error"
|
|
561
|
-
};
|
|
562
|
-
if (err instanceof Error) {
|
|
563
|
-
return { data: null, error: { ...error2, message: err.message } };
|
|
564
|
-
}
|
|
565
|
-
return { data: null, error: error2 };
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
const body = getSubString(xml, "<soap-env:Body>", "</soap-env:Body>", false);
|
|
569
|
-
const error = getSubString(body, "<stl:Error>", "</stl:Error>", false);
|
|
570
|
-
if (error) {
|
|
571
|
-
return {
|
|
572
|
-
data: null,
|
|
573
|
-
error: {
|
|
574
|
-
name: "error_in_response",
|
|
575
|
-
message: getSubString(error, "<stl:Message>", "</stl:Message>", false)
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
const action = this.headers.get("SOAPAction");
|
|
580
|
-
if (action === "SessionCreateRQ" /* SESSION_CREATE */ || action === "TokenCreateRQ" /* TOKEN_CREATE */) {
|
|
581
|
-
const token = getSubString(xml, '<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">', "</wsse:BinarySecurityToken>", false);
|
|
582
|
-
this.headersRequest.authorization = token;
|
|
583
|
-
this.headers.set("Authorization", `Bearer ${token}`);
|
|
584
|
-
} else if (action === "SessionCloseRQ" /* SESSION_CLOSE */) {
|
|
585
|
-
this.headersRequest.authorization = "";
|
|
586
|
-
this.headers.delete("Authorization");
|
|
587
|
-
}
|
|
588
|
-
return { data: body, error: null };
|
|
589
|
-
} catch (error) {
|
|
590
|
-
return {
|
|
591
|
-
data: null,
|
|
592
|
-
error: {
|
|
593
|
-
name: "application_error",
|
|
594
|
-
message: "Unable to fetch data. The request could not be resolved."
|
|
595
|
-
}
|
|
596
|
-
};
|
|
545
|
+
const response = await fetch(baseUrl, options2);
|
|
546
|
+
const xml = await response.text();
|
|
547
|
+
if (!response.ok) {
|
|
548
|
+
const fault = getSubString(xml, "<faultstring>", "</faultstring>", false);
|
|
549
|
+
throw new FaultError(fault);
|
|
550
|
+
}
|
|
551
|
+
const body = getSubString(xml, "<soap-env:Body>", "</soap-env:Body>", false);
|
|
552
|
+
const error = getSubString(body, "<stl:Error>", "</stl:Error>", false);
|
|
553
|
+
if (error) {
|
|
554
|
+
const message = getSubString(error, "<stl:Message>", "</stl:Message>", false);
|
|
555
|
+
throw new ErrorInResponse(message);
|
|
556
|
+
}
|
|
557
|
+
const action = this.headers.get("SOAPAction");
|
|
558
|
+
if (action === "SessionCreateRQ" /* SESSION_CREATE */ || action === "TokenCreateRQ" /* TOKEN_CREATE */) {
|
|
559
|
+
const token = getSubString(xml, '<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">', "</wsse:BinarySecurityToken>", false);
|
|
560
|
+
this.headersRequest.authorization = token;
|
|
561
|
+
this.headers.set("Authorization", `Bearer ${token}`);
|
|
562
|
+
} else if (action === "SessionCloseRQ" /* SESSION_CLOSE */) {
|
|
563
|
+
this.headersRequest.authorization = "";
|
|
564
|
+
this.headers.delete("Authorization");
|
|
597
565
|
}
|
|
566
|
+
return body;
|
|
598
567
|
}
|
|
599
568
|
async post(handlerRequest, options2 = {}) {
|
|
600
569
|
if (!this.headersRequest.authorization) throw new Error('Missing authorization. Set it in setToken("TOKEN")');
|
|
@@ -607,7 +576,7 @@ var Sabre = class {
|
|
|
607
576
|
return this.fetchRequest(requestOptions);
|
|
608
577
|
}
|
|
609
578
|
async auth(handlerRequest, options2 = {}) {
|
|
610
|
-
if (!this.username || !this.password || !this.organization)
|
|
579
|
+
if (!this.options.username || !this.options.password || !this.options.organization)
|
|
611
580
|
throw new Error('Missing authorization. Pass it to the constructor `new LegacySabre("USERNAME", "PASSWORD", "ORGANIZATION")');
|
|
612
581
|
const requestOptions = {
|
|
613
582
|
method: "POST",
|
|
@@ -615,9 +584,9 @@ var Sabre = class {
|
|
|
615
584
|
body: handlerRequest({
|
|
616
585
|
conversationId,
|
|
617
586
|
authorization: {
|
|
618
|
-
username: this.username,
|
|
619
|
-
password: this.password,
|
|
620
|
-
pcc: this.organization,
|
|
587
|
+
username: this.options.username,
|
|
588
|
+
password: this.options.password,
|
|
589
|
+
pcc: this.options.organization,
|
|
621
590
|
domain
|
|
622
591
|
}
|
|
623
592
|
}),
|
|
@@ -628,5 +597,7 @@ var Sabre = class {
|
|
|
628
597
|
};
|
|
629
598
|
// Annotate the CommonJS export names for ESM import in node:
|
|
630
599
|
0 && (module.exports = {
|
|
631
|
-
|
|
600
|
+
ErrorInResponse,
|
|
601
|
+
FaultError,
|
|
602
|
+
SabreLegacy
|
|
632
603
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ function getSubString(strSearch, strBegin, strEnd, withEnd) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// package.json
|
|
21
|
-
var version = "0.1.
|
|
21
|
+
var version = "0.1.1";
|
|
22
22
|
|
|
23
23
|
// src/config.ts
|
|
24
24
|
var defaultBaseUrl = "https://webservices.platform.sabre.com";
|
|
@@ -307,12 +307,11 @@ var Queue = class {
|
|
|
307
307
|
}
|
|
308
308
|
if (!pcc) throw new Error('Missing pcc. Set it in count("PCC")');
|
|
309
309
|
this.sabre.setAction("QueueCountLLSRQ" /* QUEUE_COUNT */);
|
|
310
|
-
const
|
|
310
|
+
const xml = await this.sabre.post((opts) => countRequest({
|
|
311
311
|
pcc,
|
|
312
312
|
...opts
|
|
313
313
|
}));
|
|
314
|
-
|
|
315
|
-
return parseXMLToQueueCount(response.data);
|
|
314
|
+
return parseXMLToQueueCount(xml);
|
|
316
315
|
}
|
|
317
316
|
async access(payload) {
|
|
318
317
|
if (!payload.pcc) {
|
|
@@ -323,14 +322,13 @@ var Queue = class {
|
|
|
323
322
|
if (!payload.pcc) throw new Error("Missing pcc. Set it in access({ pcc, number })");
|
|
324
323
|
const { number, pcc } = payload;
|
|
325
324
|
this.sabre.setAction("QueueAccessLLSRS" /* QUEUE_ACCESS */);
|
|
326
|
-
const
|
|
325
|
+
const xml = await this.sabre.post((opts) => accessRequest({
|
|
327
326
|
number,
|
|
328
327
|
pcc,
|
|
329
328
|
...opts
|
|
330
329
|
}));
|
|
331
|
-
if (!response.data) throw new Error(`Response error ${response.error}`);
|
|
332
330
|
this.meta.queue = number;
|
|
333
|
-
const queueAccess2 = parseXMLToQueueAccess(
|
|
331
|
+
const queueAccess2 = parseXMLToQueueAccess(xml);
|
|
334
332
|
return formatQueueResponse({
|
|
335
333
|
bookingId: queueAccess2.line.uniqueID.iD,
|
|
336
334
|
paragraph: queueAccess2.paragraph,
|
|
@@ -339,9 +337,8 @@ var Queue = class {
|
|
|
339
337
|
}
|
|
340
338
|
async ignore() {
|
|
341
339
|
this.sabre.setAction("QueueAccessLLSRS" /* QUEUE_ACCESS */);
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
const queueAccess2 = parseXMLToQueueAccess(response.data);
|
|
340
|
+
const xml = await this.sabre.post(ignoreRequest);
|
|
341
|
+
const queueAccess2 = parseXMLToQueueAccess(xml);
|
|
345
342
|
return formatQueueResponse({
|
|
346
343
|
bookingId: queueAccess2.line.uniqueID.iD,
|
|
347
344
|
paragraph: queueAccess2.paragraph,
|
|
@@ -350,9 +347,8 @@ var Queue = class {
|
|
|
350
347
|
}
|
|
351
348
|
async remove() {
|
|
352
349
|
this.sabre.setAction("QueueAccessLLSRS" /* QUEUE_ACCESS */);
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
const queueAccess2 = parseXMLToQueueAccess(response.data);
|
|
350
|
+
const xml = await this.sabre.post(removeRequest);
|
|
351
|
+
const queueAccess2 = parseXMLToQueueAccess(xml);
|
|
356
352
|
return formatQueueResponse({
|
|
357
353
|
bookingId: queueAccess2.line.uniqueID.iD,
|
|
358
354
|
paragraph: queueAccess2.paragraph,
|
|
@@ -372,13 +368,12 @@ var Queue = class {
|
|
|
372
368
|
if (!payload.pcc) throw new Error("Missing pcc. Set it in place({ pcc, number })");
|
|
373
369
|
const { number, pcc } = payload;
|
|
374
370
|
this.sabre.setAction("QueuePlaceLLSRQ" /* QUEUE_PLACE */);
|
|
375
|
-
const
|
|
371
|
+
const xml = await this.sabre.post((opts) => placeRequest({
|
|
376
372
|
number,
|
|
377
373
|
pcc,
|
|
378
374
|
...opts
|
|
379
375
|
}));
|
|
380
|
-
|
|
381
|
-
const queuePlace2 = parseXMLToQueuePlace(response.data);
|
|
376
|
+
const queuePlace2 = parseXMLToQueuePlace(xml);
|
|
382
377
|
return formatQueueResponse({
|
|
383
378
|
bookingId: findBookingId(queuePlace2.text.pop()),
|
|
384
379
|
paragraph: { text: queuePlace2.text },
|
|
@@ -459,9 +454,8 @@ var DailySales = class {
|
|
|
459
454
|
if (!payload.pcc) throw new Error("Missing pcc. Set it in report({ pcc, number })");
|
|
460
455
|
const { pcc, date } = payload;
|
|
461
456
|
this.sabre.setAction("DailySalesReportLLSRQ" /* DAILY_SALES_REPORT */);
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
return parseXMLToDailySalesReport(response.data);
|
|
457
|
+
const xml = await this.sabre.post((headersPayload) => reportRequest({ pcc, date, ...headersPayload }));
|
|
458
|
+
return parseXMLToDailySalesReport(xml);
|
|
465
459
|
}
|
|
466
460
|
async summary(payload) {
|
|
467
461
|
if (!payload.pcc) {
|
|
@@ -472,26 +466,45 @@ var DailySales = class {
|
|
|
472
466
|
if (!payload.pcc) throw new Error("Missing pcc. Set it in summary({ pcc, ... })");
|
|
473
467
|
const { pcc } = payload;
|
|
474
468
|
this.sabre.setAction("DailySalesReportLLSRQ" /* DAILY_SALES_REPORT */);
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
469
|
+
const xml = await this.sabre.post((headersPayload) => summaryRequest({ pcc, ...payload, ...headersPayload }));
|
|
470
|
+
return parseXMLToDailySalesSummary(xml);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
// src/common/utils/fault-error.ts
|
|
475
|
+
var FaultError = class extends Error {
|
|
476
|
+
constructor(message) {
|
|
477
|
+
super(message);
|
|
478
|
+
this.name = "FaultError";
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// src/common/utils/error-in-response.ts
|
|
483
|
+
var ErrorInResponse = class extends Error {
|
|
484
|
+
constructor(message) {
|
|
485
|
+
super(message);
|
|
486
|
+
this.name = "ErrorInResponse";
|
|
478
487
|
}
|
|
479
488
|
};
|
|
480
489
|
|
|
481
490
|
// src/sabre.ts
|
|
482
491
|
var Sabre = class {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
492
|
+
headers;
|
|
493
|
+
headersRequest;
|
|
494
|
+
options = {};
|
|
495
|
+
authentication = new Authentication(this);
|
|
496
|
+
queue = new Queue(this);
|
|
497
|
+
dailySales = new DailySales(this);
|
|
498
|
+
constructor(options2) {
|
|
499
|
+
const { username, password, organization } = options2;
|
|
487
500
|
const processEnv = typeof process !== "undefined" && process.env;
|
|
488
501
|
if (!username && processEnv)
|
|
489
|
-
this.username = processEnv.SABRE_USERNAME;
|
|
502
|
+
this.options.username = processEnv.SABRE_USERNAME;
|
|
490
503
|
if (!password && processEnv)
|
|
491
|
-
this.password = processEnv.SABRE_PASSWORD;
|
|
504
|
+
this.options.password = processEnv.SABRE_PASSWORD;
|
|
492
505
|
if (!organization && processEnv)
|
|
493
|
-
this.organization = processEnv.SABRE_ORGANIZATION;
|
|
494
|
-
if (!this.username || !this.password || !this.organization) {
|
|
506
|
+
this.options.organization = processEnv.SABRE_ORGANIZATION;
|
|
507
|
+
if (!this.options.username || !this.options.password || !this.options.organization) {
|
|
495
508
|
throw new Error('Missing LegacySabre authorization. Pass it to the constructor `new LegacySabre("USERNAME", "PASSWORD", "ORGANIZATION")');
|
|
496
509
|
}
|
|
497
510
|
this.headers = new Headers({
|
|
@@ -504,78 +517,32 @@ var Sabre = class {
|
|
|
504
517
|
authorization: ""
|
|
505
518
|
};
|
|
506
519
|
}
|
|
507
|
-
headers;
|
|
508
|
-
headersRequest;
|
|
509
|
-
authentication = new Authentication(this);
|
|
510
|
-
queue = new Queue(this);
|
|
511
|
-
dailySales = new DailySales(this);
|
|
512
520
|
setAction(action) {
|
|
513
521
|
this.headers.set("SOAPAction", action);
|
|
514
522
|
}
|
|
515
523
|
async fetchRequest(options2 = {}) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
const error2 = {
|
|
540
|
-
message: response.statusText,
|
|
541
|
-
name: "application_error"
|
|
542
|
-
};
|
|
543
|
-
if (err instanceof Error) {
|
|
544
|
-
return { data: null, error: { ...error2, message: err.message } };
|
|
545
|
-
}
|
|
546
|
-
return { data: null, error: error2 };
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
const body = getSubString(xml, "<soap-env:Body>", "</soap-env:Body>", false);
|
|
550
|
-
const error = getSubString(body, "<stl:Error>", "</stl:Error>", false);
|
|
551
|
-
if (error) {
|
|
552
|
-
return {
|
|
553
|
-
data: null,
|
|
554
|
-
error: {
|
|
555
|
-
name: "error_in_response",
|
|
556
|
-
message: getSubString(error, "<stl:Message>", "</stl:Message>", false)
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
const action = this.headers.get("SOAPAction");
|
|
561
|
-
if (action === "SessionCreateRQ" /* SESSION_CREATE */ || action === "TokenCreateRQ" /* TOKEN_CREATE */) {
|
|
562
|
-
const token = getSubString(xml, '<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">', "</wsse:BinarySecurityToken>", false);
|
|
563
|
-
this.headersRequest.authorization = token;
|
|
564
|
-
this.headers.set("Authorization", `Bearer ${token}`);
|
|
565
|
-
} else if (action === "SessionCloseRQ" /* SESSION_CLOSE */) {
|
|
566
|
-
this.headersRequest.authorization = "";
|
|
567
|
-
this.headers.delete("Authorization");
|
|
568
|
-
}
|
|
569
|
-
return { data: body, error: null };
|
|
570
|
-
} catch (error) {
|
|
571
|
-
return {
|
|
572
|
-
data: null,
|
|
573
|
-
error: {
|
|
574
|
-
name: "application_error",
|
|
575
|
-
message: "Unable to fetch data. The request could not be resolved."
|
|
576
|
-
}
|
|
577
|
-
};
|
|
524
|
+
const response = await fetch(baseUrl, options2);
|
|
525
|
+
const xml = await response.text();
|
|
526
|
+
if (!response.ok) {
|
|
527
|
+
const fault = getSubString(xml, "<faultstring>", "</faultstring>", false);
|
|
528
|
+
throw new FaultError(fault);
|
|
529
|
+
}
|
|
530
|
+
const body = getSubString(xml, "<soap-env:Body>", "</soap-env:Body>", false);
|
|
531
|
+
const error = getSubString(body, "<stl:Error>", "</stl:Error>", false);
|
|
532
|
+
if (error) {
|
|
533
|
+
const message = getSubString(error, "<stl:Message>", "</stl:Message>", false);
|
|
534
|
+
throw new ErrorInResponse(message);
|
|
535
|
+
}
|
|
536
|
+
const action = this.headers.get("SOAPAction");
|
|
537
|
+
if (action === "SessionCreateRQ" /* SESSION_CREATE */ || action === "TokenCreateRQ" /* TOKEN_CREATE */) {
|
|
538
|
+
const token = getSubString(xml, '<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">', "</wsse:BinarySecurityToken>", false);
|
|
539
|
+
this.headersRequest.authorization = token;
|
|
540
|
+
this.headers.set("Authorization", `Bearer ${token}`);
|
|
541
|
+
} else if (action === "SessionCloseRQ" /* SESSION_CLOSE */) {
|
|
542
|
+
this.headersRequest.authorization = "";
|
|
543
|
+
this.headers.delete("Authorization");
|
|
578
544
|
}
|
|
545
|
+
return body;
|
|
579
546
|
}
|
|
580
547
|
async post(handlerRequest, options2 = {}) {
|
|
581
548
|
if (!this.headersRequest.authorization) throw new Error('Missing authorization. Set it in setToken("TOKEN")');
|
|
@@ -588,7 +555,7 @@ var Sabre = class {
|
|
|
588
555
|
return this.fetchRequest(requestOptions);
|
|
589
556
|
}
|
|
590
557
|
async auth(handlerRequest, options2 = {}) {
|
|
591
|
-
if (!this.username || !this.password || !this.organization)
|
|
558
|
+
if (!this.options.username || !this.options.password || !this.options.organization)
|
|
592
559
|
throw new Error('Missing authorization. Pass it to the constructor `new LegacySabre("USERNAME", "PASSWORD", "ORGANIZATION")');
|
|
593
560
|
const requestOptions = {
|
|
594
561
|
method: "POST",
|
|
@@ -596,9 +563,9 @@ var Sabre = class {
|
|
|
596
563
|
body: handlerRequest({
|
|
597
564
|
conversationId,
|
|
598
565
|
authorization: {
|
|
599
|
-
username: this.username,
|
|
600
|
-
password: this.password,
|
|
601
|
-
pcc: this.organization,
|
|
566
|
+
username: this.options.username,
|
|
567
|
+
password: this.options.password,
|
|
568
|
+
pcc: this.options.organization,
|
|
602
569
|
domain
|
|
603
570
|
}
|
|
604
571
|
}),
|
|
@@ -608,5 +575,7 @@ var Sabre = class {
|
|
|
608
575
|
}
|
|
609
576
|
};
|
|
610
577
|
export {
|
|
611
|
-
|
|
578
|
+
ErrorInResponse,
|
|
579
|
+
FaultError,
|
|
580
|
+
Sabre as SabreLegacy
|
|
612
581
|
};
|