bellboy 6.3.3 → 6.4.0

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 CHANGED
@@ -342,6 +342,17 @@ For delimited data produces rows described [here](#delimited-produced-row).
342
342
  Symbol placed around a field to signify that it is the same field.
343
343
  - **jsonPath** `RegExp`\
344
344
  Path to the array to be streamed. This option is described in detail inside [JsonProcessor](#json-processor) section.
345
+ - **authorizationRequest** `object`
346
+ - **connection**\
347
+ Options from [axios](https://github.com/axios/axios) library.
348
+ - **applyTo**\
349
+ Where extracted field should be applied. Whether `header` or `query`.
350
+ - **sourceField**\
351
+ Name of the field from which value of authorization token will be extracted.
352
+ - **destinationField**\
353
+ Name of the field which will be applied to `header` or `query` using `applyTo` option.
354
+ - **prefix**\
355
+ Custom prefix to apply to the token.
345
356
  - **nextRequest** `async function(header)`\
346
357
  Function which must return `connection` for the next request or `null` if the next request is not needed.
347
358
 
@@ -572,6 +583,17 @@ Puts processed data one by one in `body` and executes specified HTTP request.
572
583
  - [General destination options](#destination-options)
573
584
  - **request** `required`\
574
585
  Options from [axios](https://github.com/axios/axios) library.
586
+ - **authorizationRequest** `object`
587
+ - **connection**\
588
+ Options from [axios](https://github.com/axios/axios) library.
589
+ - **applyTo**\
590
+ Where extracted field should be applied. Whether `header` or `query`.
591
+ - **sourceField**\
592
+ Name of the field from which value of authorization token will be extracted.
593
+ - **destinationField**\
594
+ Name of the field which will be applied to `header` or `query` using `applyTo` option.
595
+ - **prefix**\
596
+ Custom prefix to apply to the token.
575
597
 
576
598
  ### PostgresDestination <div id='postgres-destination'/>
577
599
 
@@ -1,8 +1,9 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
- import { IHttpDestinationConfig } from '../types';
2
+ import { AuthorizationRequest, IHttpDestinationConfig } from '../types';
3
3
  import { Destination } from './base/destination';
4
4
  export declare class HttpDestination extends Destination {
5
5
  protected request: AxiosRequestConfig;
6
+ protected authorizationRequest?: AuthorizationRequest;
6
7
  constructor(config: IHttpDestinationConfig);
7
8
  loadBatch(data: any[]): Promise<void>;
8
9
  }
@@ -65,12 +65,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
65
65
  Object.defineProperty(exports, "__esModule", { value: true });
66
66
  exports.HttpDestination = void 0;
67
67
  var axios_1 = __importDefault(require("axios"));
68
+ var utils_1 = require("../utils");
68
69
  var destination_1 = require("./base/destination");
69
70
  var HttpDestination = /** @class */ (function (_super) {
70
71
  __extends(HttpDestination, _super);
71
72
  function HttpDestination(config) {
72
73
  var _this = _super.call(this, config) || this;
73
74
  _this.request = config.request;
75
+ _this.authorizationRequest = config.authorizationRequest;
74
76
  return _this;
75
77
  }
76
78
  HttpDestination.prototype.loadBatch = function (data) {
@@ -78,19 +80,21 @@ var HttpDestination = /** @class */ (function (_super) {
78
80
  var i;
79
81
  return __generator(this, function (_a) {
80
82
  switch (_a.label) {
81
- case 0:
82
- i = 0;
83
- _a.label = 1;
83
+ case 0: return [4 /*yield*/, utils_1.applyHttpAuthorization(this.request, this.authorizationRequest)];
84
84
  case 1:
85
- if (!(i < data.length)) return [3 /*break*/, 4];
86
- return [4 /*yield*/, axios_1.default(__assign(__assign({}, this.request), { data: data[i] }))];
87
- case 2:
88
85
  _a.sent();
89
- _a.label = 3;
86
+ i = 0;
87
+ _a.label = 2;
88
+ case 2:
89
+ if (!(i < data.length)) return [3 /*break*/, 5];
90
+ return [4 /*yield*/, axios_1.default(__assign(__assign({}, this.request), { data: data[i] }))];
90
91
  case 3:
92
+ _a.sent();
93
+ _a.label = 4;
94
+ case 4:
91
95
  i++;
92
- return [3 /*break*/, 1];
93
- case 4: return [2 /*return*/];
96
+ return [3 /*break*/, 2];
97
+ case 5: return [2 /*return*/];
94
98
  }
95
99
  });
96
100
  });
@@ -1,5 +1,5 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
- import { IDelimitedHttpProcessorConfig, IJsonHttpProcessorConfig, processStream } from '../types';
2
+ import { AuthorizationRequest, IDelimitedHttpProcessorConfig, IJsonHttpProcessorConfig, processStream } from '../types';
3
3
  import { Processor } from './base/processor';
4
4
  export declare class HttpProcessor extends Processor {
5
5
  protected connection: AxiosRequestConfig;
@@ -10,6 +10,7 @@ export declare class HttpProcessor extends Processor {
10
10
  protected hasHeader: boolean;
11
11
  protected delimiter?: string;
12
12
  protected qualifier?: string;
13
+ protected authorizationRequest?: AuthorizationRequest;
13
14
  constructor(config: IJsonHttpProcessorConfig | IDelimitedHttpProcessorConfig);
14
15
  protected processHttpData(processStream: processStream, options: AxiosRequestConfig): Promise<void>;
15
16
  process(processStream: processStream): Promise<void>;
@@ -95,6 +95,7 @@ var HttpProcessor = /** @class */ (function (_super) {
95
95
  _this.jsonPath = config.jsonPath;
96
96
  }
97
97
  _this.nextRequest = config.nextRequest;
98
+ _this.authorizationRequest = config.authorizationRequest;
98
99
  return _this;
99
100
  }
100
101
  HttpProcessor.prototype.processHttpData = function (processStream, options) {
@@ -156,8 +157,11 @@ var HttpProcessor = /** @class */ (function (_super) {
156
157
  return __awaiter(this, void 0, void 0, function () {
157
158
  return __generator(this, function (_a) {
158
159
  switch (_a.label) {
159
- case 0: return [4 /*yield*/, this.processHttpData(processStream, this.connection)];
160
+ case 0: return [4 /*yield*/, utils_1.applyHttpAuthorization(this.connection, this.authorizationRequest)];
160
161
  case 1:
162
+ _a.sent();
163
+ return [4 /*yield*/, this.processHttpData(processStream, this.connection)];
164
+ case 2:
161
165
  _a.sent();
162
166
  return [2 /*return*/];
163
167
  }
package/lib/types.d.ts CHANGED
@@ -2,6 +2,13 @@
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  import { Readable } from 'stream';
4
4
  import { IWorksheet } from 'xlstream/lib/types';
5
+ export interface AuthorizationRequest {
6
+ connection: AxiosRequestConfig;
7
+ applyTo: 'header' | 'query';
8
+ sourceField: string;
9
+ destinationField: string;
10
+ prefix?: string;
11
+ }
5
12
  export interface IDbConnection {
6
13
  user?: string;
7
14
  password?: string;
@@ -70,6 +77,7 @@ export interface IMssqlDestinationConfig extends IDatabaseDestinationConfig {
70
77
  }
71
78
  export interface IHttpDestinationConfig extends IDestinationConfig {
72
79
  request: AxiosRequestConfig;
80
+ authorizationRequest?: AuthorizationRequest;
73
81
  }
74
82
  export interface IStdoutDestinationConfig extends IDestinationConfig {
75
83
  asTable?: boolean;
@@ -77,6 +85,7 @@ export interface IStdoutDestinationConfig extends IDestinationConfig {
77
85
  export interface IHttpProcessorConfig extends IProcessorConfig {
78
86
  connection: AxiosRequestConfig;
79
87
  nextRequest?: () => Promise<AxiosRequestConfig | null | undefined>;
88
+ authorizationRequest?: AuthorizationRequest;
80
89
  }
81
90
  export interface IJsonHttpProcessorConfig extends IHttpProcessorConfig {
82
91
  dataFormat: 'json';
package/lib/utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
+ import { AxiosRequestConfig } from 'axios';
2
3
  import { Transform } from 'stream';
3
- import { DbTypes, IDbConnection } from './types';
4
+ import { AuthorizationRequest, DbTypes, IDbConnection } from './types';
4
5
  export declare function getDb(databaseConfig: IDbConnection, dbType: DbTypes): Promise<any>;
5
6
  export declare function closeDbConnection(databaseConfig: IDbConnection): Promise<void>;
6
7
  export declare function getValueFromJSONChunk(): Transform;
@@ -13,3 +14,4 @@ export declare function getDelimitedGenerator({ readStream, hasHeader, }: {
13
14
  obj: any;
14
15
  row: string;
15
16
  }, void, unknown>;
17
+ export declare function applyHttpAuthorization(connection: AxiosRequestConfig, authorizationRequest?: AuthorizationRequest): Promise<void>;
package/lib/utils.js CHANGED
@@ -84,8 +84,12 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
84
84
  function reject(value) { resume("throw", value); }
85
85
  function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
86
86
  };
87
+ var __importDefault = (this && this.__importDefault) || function (mod) {
88
+ return (mod && mod.__esModule) ? mod : { "default": mod };
89
+ };
87
90
  Object.defineProperty(exports, "__esModule", { value: true });
88
- exports.getDelimitedGenerator = exports.getValueFromJSONChunk = exports.closeDbConnection = exports.getDb = void 0;
91
+ exports.applyHttpAuthorization = exports.getDelimitedGenerator = exports.getValueFromJSONChunk = exports.closeDbConnection = exports.getDb = void 0;
92
+ var axios_1 = __importDefault(require("axios"));
89
93
  var stream_1 = require("stream");
90
94
  var cachedDbConnections = new Map();
91
95
  function getDb(databaseConfig, dbType) {
@@ -231,3 +235,24 @@ function getDelimitedGenerator(_a) {
231
235
  return generator;
232
236
  }
233
237
  exports.getDelimitedGenerator = getDelimitedGenerator;
238
+ function applyHttpAuthorization(connection, authorizationRequest) {
239
+ return __awaiter(this, void 0, void 0, function () {
240
+ var authorizationResponse, authorizationToken, applyTo;
241
+ var _a;
242
+ return __generator(this, function (_b) {
243
+ switch (_b.label) {
244
+ case 0:
245
+ if (!authorizationRequest) return [3 /*break*/, 2];
246
+ return [4 /*yield*/, axios_1.default(authorizationRequest.connection)];
247
+ case 1:
248
+ authorizationResponse = _b.sent();
249
+ authorizationToken = authorizationResponse.data[authorizationRequest.sourceField];
250
+ applyTo = authorizationRequest.applyTo === 'header' ? 'headers' : 'params';
251
+ connection[applyTo] = __assign(__assign({}, connection[applyTo]), (_a = {}, _a[authorizationRequest.destinationField] = authorizationRequest.prefix ? "" + authorizationRequest.prefix + authorizationToken : authorizationToken, _a));
252
+ _b.label = 2;
253
+ case 2: return [2 /*return*/];
254
+ }
255
+ });
256
+ });
257
+ }
258
+ exports.applyHttpAuthorization = applyHttpAuthorization;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bellboy",
3
- "version": "6.3.3",
3
+ "version": "6.4.0",
4
4
  "description": "Highly performant JavaScript data stream ETL engine.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index",