@barchart/portfolio-client-js 1.5.1 → 2.0.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.
@@ -0,0 +1,10 @@
1
+ **Breaking Changes**
2
+
3
+
4
+ * The mechanism for passing JSON Web Tokens to the ```PortfolioGateway``` has changed. Consumers are now required to provide ```JwtProvider``` instances instead of a ```RequestInterceptor``` instances. Here are the specifics:
5
+ * The ```RequestInterceptor``` argument was replaced with a ```JwtProvider``` argument on static factory functions (e.g. ```PortfolioGateway.forProduction```).
6
+ * The ```RequestInterceptor``` argument was removed from the ```PortfolioGateway``` constructor.
7
+ * The ```PortfolioGateway.start``` function was renamed to ```PortfolioGateway.connect``` and now has a ```JwtProvider``` argument.
8
+ * The ```JwtGateway``` and ```JwtEndpoint``` classes were removed.
9
+ * Static factory functions for impersonating users in the ```test``` and ```development``` environments were added. See ```JwtProvider.forTest``` and ```JwtProvider.forDevelopment```.
10
+ * Removed ```PortfolioGateway.batchTransactions``` function.
package/gulpfile.js CHANGED
@@ -65,7 +65,7 @@ gulp.task('embed-version', () => {
65
65
  });
66
66
 
67
67
  gulp.task('commit-changes', () => {
68
- return gulp.src([ './', './test/', './package.json', './lib/index.js', './example/example.js', './test/SpecRunner.js' ])
68
+ return gulp.src([ './', './test/', './package.json', './lib/index.js', './test/SpecRunner.js' ])
69
69
  .pipe(git.add())
70
70
  .pipe(git.commit('Release. Bump version number'));
71
71
  });
@@ -86,14 +86,6 @@ gulp.task('create-tag', (cb) => {
86
86
  });
87
87
  });
88
88
 
89
- gulp.task('build-example-bundle', () => {
90
- return browserify([ './lib/index.js', './example/js/startup.js', ])
91
- .bundle()
92
- .pipe(source('example.js'))
93
- .pipe(buffer())
94
- .pipe(gulp.dest('./example'));
95
- });
96
-
97
89
  gulp.task('build-test-bundle', () => {
98
90
  return browserify({ entries: glob.sync('test/specs/**/*.js') })
99
91
  .bundle()
@@ -124,14 +116,13 @@ gulp.task('release', gulp.series(
124
116
  'bump-choice',
125
117
  'bump-version',
126
118
  'embed-version',
127
- 'build-example-bundle',
128
119
  'commit-changes',
129
120
  'push-changes',
130
121
  'create-tag'
131
122
  ));
132
123
 
133
124
  gulp.task('lint', () => {
134
- return gulp.src([ './**/*.js', './test/specs/**/*.js', '!./node_modules/**', '!./docs/**', '!./test/SpecRunner.js', '!./example/example.js' ])
125
+ return gulp.src([ './**/*.js', './test/specs/**/*.js', '!./node_modules/**', '!./docs/**', '!./test/SpecRunner.js' ])
135
126
  .pipe(jshint({ esversion: 9 }))
136
127
  .pipe(jshint.reporter('default'))
137
128
  .pipe(jshint.reporter('fail'));
@@ -11,24 +11,8 @@ module.exports = (() => {
11
11
 
12
12
  }
13
13
 
14
- static getBrokerageHost(host) {
15
- if (host === Configuration.developmentHost) {
16
- return '7enbtpamgg.execute-api.us-east-1.amazonaws.com/dev';
17
- } else if (host === Configuration.stagingHost) {
18
- return 'i98b1sdxp6.execute-api.us-east-1.amazonaws.com/stage';
19
- } else if (host === Configuration.productionHost) {
20
- return 'xos40seq3e.execute-api.us-east-1.amazonaws.com/prod';
21
- } else if (host === Configuration.adminHost) {
22
- return 'q1x45oxon1.execute-api.us-east-1.amazonaws.com/admin';
23
- } else if (host === Configuration.demoHost) {
24
- return 'b9132ukaob.execute-api.us-east-1.amazonaws.com/demo';
25
- } else {
26
- return '';
27
- }
28
- }
29
-
30
14
  /**
31
- * The host of the development system.
15
+ * The hostname of the REST API for the development environment (intended for Barchart use only).
32
16
  *
33
17
  * @public
34
18
  * @static
@@ -39,7 +23,18 @@ module.exports = (() => {
39
23
  }
40
24
 
41
25
  /**
42
- * The host of the staging system.
26
+ * The hostname of the REST API for the test environment (public use allowed).
27
+ *
28
+ * @public
29
+ * @static
30
+ * @returns {String}
31
+ */
32
+ static get testHost() {
33
+ return 'portfolio-test.aws.barchart.com';
34
+ }
35
+
36
+ /**
37
+ * The hostname of the REST API for the staging environment (public use allowed).
43
38
  *
44
39
  * @public
45
40
  * @static
@@ -50,18 +45,18 @@ module.exports = (() => {
50
45
  }
51
46
 
52
47
  /**
53
- * The host of the public demo system.
48
+ * The hostname of the REST API for the demo environment (intended for Barchart use only).
54
49
  *
55
50
  * @public
56
51
  * @static
57
- * @return {String}
52
+ * @returns {String}
58
53
  */
59
54
  static get demoHost() {
60
55
  return 'portfolio-demo.aws.barchart.com';
61
56
  }
62
57
 
63
58
  /**
64
- * The host of the production system.
59
+ * The hostname of the REST API for the production environment (public use allowed).
65
60
  *
66
61
  * @public
67
62
  * @static
@@ -72,16 +67,44 @@ module.exports = (() => {
72
67
  }
73
68
 
74
69
  /**
75
- * The host of the internal admin system.
70
+ * The hostname of the REST API for the admin environment (intended for Barchart use only).
76
71
  *
77
72
  * @public
78
73
  * @static
79
- * @return {String}
74
+ * @returns {String}
80
75
  */
81
76
  static get adminHost() {
82
77
  return 'portfolio-admin.aws.barchart.com';
83
78
  }
84
79
 
80
+ /**
81
+ * The hostname of REST API which generates impersonation tokens for non-secure
82
+ * test and demo environments.
83
+ *
84
+ * @public
85
+ * @static
86
+ * @returns {string}
87
+ */
88
+ static get getJwtImpersonationHost() {
89
+ return 'jwt-public-prod.aws.barchart.com';
90
+ }
91
+
92
+ static getBrokerageHost(host) {
93
+ if (host === Configuration.developmentHost) {
94
+ return '7enbtpamgg.execute-api.us-east-1.amazonaws.com/dev';
95
+ } else if (host === Configuration.stagingHost) {
96
+ return 'i98b1sdxp6.execute-api.us-east-1.amazonaws.com/stage';
97
+ } else if (host === Configuration.productionHost) {
98
+ return 'xos40seq3e.execute-api.us-east-1.amazonaws.com/prod';
99
+ } else if (host === Configuration.adminHost) {
100
+ return 'q1x45oxon1.execute-api.us-east-1.amazonaws.com/admin';
101
+ } else if (host === Configuration.demoHost) {
102
+ return 'b9132ukaob.execute-api.us-east-1.amazonaws.com/demo';
103
+ } else {
104
+ return '';
105
+ }
106
+ }
107
+
85
108
  toString() {
86
109
  return '[Configuration]';
87
110
  }
@@ -19,47 +19,65 @@ const PositionSummaryFrame = require('@barchart/portfolio-api-common/lib/data/Po
19
19
  const EndpointBuilder = require('@barchart/common-js/api/http/builders/EndpointBuilder'),
20
20
  Gateway = require('@barchart/common-js/api/http/Gateway'),
21
21
  FailureReason = require('@barchart/common-js/api/failures/FailureReason'),
22
+ FailureType = require('@barchart/common-js/api/failures/FailureType'),
22
23
  ProtocolType = require('@barchart/common-js/api/http/definitions/ProtocolType'),
23
24
  ErrorInterceptor = require('@barchart/common-js/api/http/interceptors/ErrorInterceptor'),
24
25
  RequestInterceptor = require('@barchart/common-js/api/http/interceptors/RequestInterceptor'),
25
26
  ResponseInterceptor = require('@barchart/common-js/api/http/interceptors/ResponseInterceptor'),
26
27
  VerbType = require('@barchart/common-js/api/http/definitions/VerbType');
27
28
 
28
- const Configuration = require('./../common/Configuration');
29
+ const Configuration = require('./../common/Configuration'),
30
+ JwtProvider = require('../security/JwtProvider');
29
31
 
30
32
  module.exports = (() => {
31
33
  'use strict';
32
34
 
35
+ const REST_API_SECURE_PROTOCOL = 'https';
36
+ const REST_API_SECURE_PORT = 443;
37
+
33
38
  /**
34
- * Web service gateway for invoking the Portfolio API.
39
+ * The **central component of the SDK**. It is responsible for connecting to Barchart's
40
+ * Portfolio Service. It can be used to query, edit, and delete portfolios.
35
41
  *
36
42
  * @public
37
- * @param {String} protocol - The protocol to use (either HTTP or HTTPS).
38
- * @param {String} host - The host name of the Portfolio web service.
43
+ * @param {String} protocol - The protocol of the of the Portfolio web service (either http or https).
44
+ * @param {String} host - The hostname of the Portfolio web service.
39
45
  * @param {Number} port - The TCP port number of the Portfolio web service.
40
46
  * @param {String} environment - A description of the environment we're connecting to.
41
- * @param {RequestInterceptor=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
42
47
  * @extends {Disposable}
43
48
  */
44
49
  class PortfolioGateway extends Disposable {
45
- constructor(protocol, host, port, environment, requestInterceptor) {
50
+ constructor(protocol, host, port, environment) {
46
51
  super();
47
52
 
53
+ this._environment = environment;
54
+
55
+ this._jwtProvider = null;
56
+
48
57
  this._started = false;
49
58
  this._startPromise = null;
59
+
60
+ const requestInterceptor = RequestInterceptor.fromDelegate((options, endpoint) => {
61
+ return Promise.resolve()
62
+ .then(() => {
63
+ return this._jwtProvider.getToken()
64
+ .then((token) => {
65
+ options.headers = options.headers || {};
66
+ options.headers.Authorization = `Bearer ${token}`;
67
+
68
+ return options;
69
+ });
70
+ }).catch((e) => {
71
+ const failure = FailureReason.forRequest({ endpoint: endpoint })
72
+ .addItem(FailureType.REQUEST_IDENTITY_FAILURE)
73
+ .format();
50
74
 
51
- this._environment = environment;
75
+ return Promise.reject(failure);
76
+ });
77
+ });
52
78
 
53
79
  const protocolType = Enum.fromCode(ProtocolType, protocol.toUpperCase());
54
80
 
55
- let requestInterceptorToUse;
56
-
57
- if (requestInterceptor) {
58
- requestInterceptorToUse = requestInterceptor;
59
- } else {
60
- requestInterceptorToUse = RequestInterceptor.EMPTY;
61
- }
62
-
63
81
  this._readPortfoliosEndpoint = EndpointBuilder.for('read-portfolios', 'read portfolios')
64
82
  .withVerb(VerbType.GET)
65
83
  .withProtocol(protocolType)
@@ -70,7 +88,7 @@ module.exports = (() => {
70
88
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false);
71
89
  })
72
90
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
73
- .withRequestInterceptor(requestInterceptorToUse)
91
+ .withRequestInterceptor(requestInterceptor)
74
92
  .withResponseInterceptor(responseInterceptorForPortfolioDeserialization)
75
93
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
76
94
  .endpoint;
@@ -86,7 +104,7 @@ module.exports = (() => {
86
104
  .withBody('portfolio')
87
105
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
88
106
  .withRequestInterceptor(RequestInterceptor.fromDelegate(createPortfolioRequestInterceptor))
89
- .withRequestInterceptor(requestInterceptorToUse)
107
+ .withRequestInterceptor(requestInterceptor)
90
108
  .withResponseInterceptor(responseInterceptorForPortfolioDeserialization)
91
109
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
92
110
  .endpoint;
@@ -103,7 +121,7 @@ module.exports = (() => {
103
121
  .withBody('portfolio')
104
122
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
105
123
  .withRequestInterceptor(RequestInterceptor.fromDelegate(updatePortfolioRequestInterceptor))
106
- .withRequestInterceptor(requestInterceptorToUse)
124
+ .withRequestInterceptor(requestInterceptor)
107
125
  .withResponseInterceptor(responseInterceptorForPortfolioDeserialization)
108
126
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
109
127
  .endpoint;
@@ -117,7 +135,7 @@ module.exports = (() => {
117
135
  pb.withLiteralParameter('portfolios', 'portfolios')
118
136
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false);
119
137
  })
120
- .withRequestInterceptor(requestInterceptorToUse)
138
+ .withRequestInterceptor(requestInterceptor)
121
139
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
122
140
  .endpoint;
123
141
 
@@ -135,7 +153,7 @@ module.exports = (() => {
135
153
  .withQueryBuilder((qb) => {
136
154
  qb.withVariableParameter('includePreviousPrice', 'includePreviousPrice', 'includePreviousPrice', true);
137
155
  })
138
- .withRequestInterceptor(requestInterceptorToUse)
156
+ .withRequestInterceptor(requestInterceptor)
139
157
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
140
158
  .withResponseInterceptor(responseInterceptorForPositionDeserialization)
141
159
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
@@ -154,7 +172,7 @@ module.exports = (() => {
154
172
  })
155
173
  .withBody('portfolio')
156
174
  .withRequestInterceptor(RequestInterceptor.fromDelegate(updatePositionRequestInterceptor))
157
- .withRequestInterceptor(requestInterceptorToUse)
175
+ .withRequestInterceptor(requestInterceptor)
158
176
  .withResponseInterceptor(responseInterceptorForPositionMutateDeserialization)
159
177
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
160
178
  .endpoint;
@@ -171,7 +189,7 @@ module.exports = (() => {
171
189
  .withVariableParameter('position', 'position', 'position', false);
172
190
  })
173
191
  .withBody('transaction')
174
- .withRequestInterceptor(requestInterceptorToUse)
192
+ .withRequestInterceptor(requestInterceptor)
175
193
  .withResponseInterceptor(responseInterceptorForPositionMutateDeserializationForRemoval)
176
194
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
177
195
  .endpoint;
@@ -192,7 +210,7 @@ module.exports = (() => {
192
210
  .withVariableParameter('periods', 'periods', 'periods', true)
193
211
  .withVariableParameter('start', 'start', 'start', true, x => x.format());
194
212
  })
195
- .withRequestInterceptor(requestInterceptorToUse)
213
+ .withRequestInterceptor(requestInterceptor)
196
214
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
197
215
  .withResponseInterceptor(responseInterceptorForPositionSummaryDeserialization)
198
216
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
@@ -211,7 +229,7 @@ module.exports = (() => {
211
229
  .withLiteralParameter('values', 'values');
212
230
  })
213
231
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
214
- .withRequestInterceptor(requestInterceptorToUse)
232
+ .withRequestInterceptor(requestInterceptor)
215
233
  .withResponseInterceptor(ResponseInterceptor.DATA)
216
234
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
217
235
  .endpoint;
@@ -232,7 +250,7 @@ module.exports = (() => {
232
250
  qb.withLiteralParameter('mode', 'mode', 'text');
233
251
  })
234
252
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
235
- .withRequestInterceptor(requestInterceptorToUse)
253
+ .withRequestInterceptor(requestInterceptor)
236
254
  .withResponseInterceptor(responseInterceptorForTransactionDeserialization)
237
255
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
238
256
  .endpoint;
@@ -253,29 +271,11 @@ module.exports = (() => {
253
271
  qb.withVariableParameter('type', 'type', 'type', false, x => x.code);
254
272
  })
255
273
  .withBody('transaction')
256
- .withRequestInterceptor(requestInterceptorToUse)
274
+ .withRequestInterceptor(requestInterceptor)
257
275
  .withResponseInterceptor(responseInterceptorForPositionMutateDeserialization)
258
276
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
259
277
  .endpoint;
260
278
 
261
- this._batchTransactionEndpoint = EndpointBuilder.for('batch-transactions', 'batch transactions')
262
- .withVerb(VerbType.POST)
263
- .withProtocol(protocolType)
264
- .withHost(host)
265
- .withPort(port)
266
- .withPathBuilder((pb) => {
267
- pb.withLiteralParameter('portfolios', 'portfolios')
268
- .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
269
- .withLiteralParameter('positions', 'positions')
270
- .withLiteralParameter('multiple', 'multiple')
271
- .withLiteralParameter('transactions', 'transactions');
272
- })
273
- .withBody('transactions')
274
- .withRequestInterceptor(requestInterceptorToUse)
275
- .withResponseInterceptor(ResponseInterceptor.DATA)
276
- .withErrorInterceptor(ErrorInterceptor.GENERAL)
277
- .endpoint;
278
-
279
279
  this._editTransactionEndpoint = EndpointBuilder.for('edit-transaction', 'edit transaction')
280
280
  .withVerb(VerbType.POST)
281
281
  .withProtocol(protocolType)
@@ -293,7 +293,7 @@ module.exports = (() => {
293
293
  qb.withVariableParameter('type', 'type', 'type', false, x => x.code);
294
294
  })
295
295
  .withBody('transaction')
296
- .withRequestInterceptor(requestInterceptorToUse)
296
+ .withRequestInterceptor(requestInterceptor)
297
297
  .withResponseInterceptor(responseInterceptorForPositionMutateDeserialization)
298
298
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
299
299
  .endpoint;
@@ -316,7 +316,7 @@ module.exports = (() => {
316
316
  .withVariableParameter('echoStart', 'echoStart', 'echoStart', true, x => x.format())
317
317
  .withVariableParameter('echoEnd', 'echoEnd', 'echoEnd', true, x => x.format());
318
318
  })
319
- .withRequestInterceptor(requestInterceptorToUse)
319
+ .withRequestInterceptor(requestInterceptor)
320
320
  .withResponseInterceptor(responseInterceptorForPositionMutateDeserializationForRemoval)
321
321
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
322
322
  .endpoint;
@@ -342,7 +342,7 @@ module.exports = (() => {
342
342
  .withVariableParameter('count', 'count', 'count', true)
343
343
  .withVariableParameter('descending', 'descending', 'descending', true);
344
344
  })
345
- .withRequestInterceptor(requestInterceptorToUse)
345
+ .withRequestInterceptor(requestInterceptor)
346
346
  .withResponseInterceptor(ResponseInterceptor.DATA)
347
347
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
348
348
  .endpoint;
@@ -358,7 +358,7 @@ module.exports = (() => {
358
358
  .withLiteralParameter('wealthscope', 'wealthscope')
359
359
  .withLiteralParameter('token', 'token');
360
360
  })
361
- .withRequestInterceptor(requestInterceptorToUse)
361
+ .withRequestInterceptor(requestInterceptor)
362
362
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
363
363
  .withResponseInterceptor(responseInterceptorForWealthscopeToken)
364
364
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
@@ -379,7 +379,7 @@ module.exports = (() => {
379
379
  .withQueryBuilder((qb) => {
380
380
  qb.withVariableParameter('frames', 'frames', 'frames', true, frames => frames.map(f => f.code).join());
381
381
  })
382
- .withRequestInterceptor(requestInterceptorToUse)
382
+ .withRequestInterceptor(requestInterceptor)
383
383
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
384
384
  .withResponseInterceptor(responseInterceptorForBrokerageReportAvailabilityDeserialization)
385
385
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
@@ -394,7 +394,7 @@ module.exports = (() => {
394
394
  pb.withLiteralParameter('system', 'system')
395
395
  .withLiteralParameter('version', 'version');
396
396
  })
397
- .withRequestInterceptor(requestInterceptorToUse)
397
+ .withRequestInterceptor(requestInterceptor)
398
398
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
399
399
  .withResponseInterceptor(responseInterceptorForVersion)
400
400
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
@@ -409,31 +409,40 @@ module.exports = (() => {
409
409
  * Returns a description of the environment (e.g. development or production).
410
410
  *
411
411
  * @public
412
- * @returns {*}
412
+ * @returns {String}
413
413
  */
414
414
  get environment() {
415
415
  return this._environment;
416
416
  }
417
417
 
418
418
  /**
419
- * Initializes the connection to the remote server and returns a promise
420
- * containing the current instance.
419
+ * Attempts to establish a connection to the backend. This function should be invoked
420
+ * immediately following instantiation. Once the resulting promise resolves, a
421
+ * connection has been established and other instance methods can be used.
421
422
  *
422
423
  * @public
424
+ * @param {JwtProvider} jwtProvider
423
425
  * @returns {Promise<PortfolioGateway>}
424
426
  */
425
- start() {
427
+ connect(jwtProvider) {
426
428
  return Promise.resolve()
427
429
  .then(() => {
430
+ assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
431
+
428
432
  if (this._startPromise === null) {
429
433
  this._startPromise = Promise.resolve()
430
434
  .then(() => {
431
435
  this._started = true;
432
436
 
437
+ this._jwtProvider = jwtProvider;
438
+
433
439
  return this;
434
440
  }).catch((e) => {
441
+ this._started = false;
435
442
  this._startPromise = null;
436
443
 
444
+ this._jwtProvider = null;
445
+
437
446
  throw e;
438
447
  });
439
448
  }
@@ -852,45 +861,6 @@ module.exports = (() => {
852
861
  });
853
862
  }
854
863
 
855
- /**
856
- * Creates one or more new transactions.
857
- *
858
- * @public
859
- * @param {Object} transaction
860
- * @returns {Promise}
861
- */
862
- batchTransactions(portfolio, transactions) {
863
- return Promise.resolve()
864
- .then(() => {
865
- checkStart.call(this);
866
-
867
- assert.argumentIsRequired(portfolio, 'portfolio', Object);
868
- assert.argumentIsArray(transactions, 'transactions', Object);
869
-
870
- const payload = { };
871
-
872
- payload.portfolio = portfolio.portfolio;
873
- payload.transactionTypes = [ ];
874
- payload.transactionItems = [ ];
875
-
876
- transactions.forEach((transaction) => {
877
- transaction.portfolio = portfolio.portfolio;
878
-
879
- if (!transaction.position) {
880
- transaction.position = 'new';
881
- }
882
-
883
- const code = getTransactionTypeCode(transaction);
884
- const schema = getTransactionSchema(transaction);
885
-
886
- payload.transactionTypes.push(code);
887
- payload.transactionItems.push(JSON.stringify(schema.schema.format(transaction)));
888
- });
889
-
890
- return Gateway.invoke(this._batchTransactionEndpoint, payload);
891
- });
892
- }
893
-
894
864
  /**
895
865
  * Edits a transaction.
896
866
  *
@@ -1141,87 +1111,104 @@ module.exports = (() => {
1141
1111
  }
1142
1112
 
1143
1113
  /**
1144
- * Creates and starts a new {@link PortfolioGateway} for use in the development environment.
1114
+ * Creates and starts a new {@link PortfolioGateway} for use in the public test environment.
1145
1115
  *
1146
1116
  * @public
1147
1117
  * @static
1148
- * @param {RequestInterceptor=|Promise<RequestInterceptor>=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
1118
+ * @param {JwtProvider} jwtProvider
1149
1119
  * @returns {Promise<PortfolioGateway>}
1150
1120
  */
1151
- static forDevelopment(requestInterceptor) {
1152
- return Promise.resolve(requestInterceptor)
1153
- .then((requestInterceptor) => {
1154
- assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'RequestInterceptor');
1121
+ static forTest(jwtProvider) {
1122
+ return Promise.resolve()
1123
+ .then(() => {
1124
+ assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
1155
1125
 
1156
- return start(new PortfolioGateway('https', Configuration.developmentHost, 443, 'development', requestInterceptor));
1126
+ return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.testHost, REST_API_SECURE_PORT, 'test'), jwtProvider);
1157
1127
  });
1158
1128
  }
1159
1129
 
1160
1130
  /**
1161
- * Creates and starts a new {@link PortfolioGateway} for use in the staging environment.
1131
+ * Creates and starts a new {@link PortfolioGateway} for use in the private development environment.
1162
1132
  *
1163
1133
  * @public
1164
1134
  * @static
1165
- * @param {RequestInterceptor=|Promise<RequestInterceptor>=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
1135
+ * @param {JwtProvider} jwtProvider
1166
1136
  * @returns {Promise<PortfolioGateway>}
1167
1137
  */
1168
- static forStaging(requestInterceptor) {
1169
- return Promise.resolve(requestInterceptor)
1170
- .then((requestInterceptor) => {
1171
- assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'RequestInterceptor');
1138
+ static forDevelopment(jwtProvider) {
1139
+ return Promise.resolve()
1140
+ .then(() => {
1141
+ assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
1172
1142
 
1173
- return start(new PortfolioGateway('https', Configuration.stagingHost, 443, 'staging', requestInterceptor));
1143
+ return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.developmentHost, REST_API_SECURE_PORT, 'development'), jwtProvider);
1174
1144
  });
1175
1145
  }
1176
1146
 
1177
1147
  /**
1178
- * Creates and starts a new {@link PortfolioGateway} for use in the demo environment.
1148
+ * Creates and starts a new {@link PortfolioGateway} for use in the private staging environment.
1179
1149
  *
1180
1150
  * @public
1181
1151
  * @static
1182
- * @param {RequestInterceptor=|Promise<RequestInterceptor>=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
1152
+ * @param {JwtProvider} jwtProvider
1183
1153
  * @returns {Promise<PortfolioGateway>}
1184
1154
  */
1185
- static forDemo(requestInterceptor) {
1186
- return Promise.resolve(requestInterceptor)
1187
- .then((requestInterceptor) => {
1188
- assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'RequestInterceptor');
1155
+ static forStaging(jwtProvider) {
1156
+ return Promise.resolve()
1157
+ .then(() => {
1158
+ assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
1189
1159
 
1190
- return start(new PortfolioGateway('https', Configuration.demoHost, 443, 'demo', requestInterceptor));
1160
+ return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.stagingHost, REST_API_SECURE_PORT, 'staging'), jwtProvider);
1191
1161
  });
1192
1162
  }
1193
1163
 
1194
1164
  /**
1195
- * Creates and starts a new {@link PortfolioGateway} for use in the production environment.
1165
+ * Creates and starts a new {@link PortfolioGateway} for use in the private demo environment.
1196
1166
  *
1197
1167
  * @public
1198
1168
  * @static
1199
- * @param {RequestInterceptor=|Promise<RequestInterceptor>=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
1169
+ * @param {JwtProvider} jwtProvider
1200
1170
  * @returns {Promise<PortfolioGateway>}
1201
1171
  */
1202
- static forProduction(requestInterceptor) {
1203
- return Promise.resolve(requestInterceptor)
1204
- .then((requestInterceptor) => {
1205
- assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'RequestInterceptor');
1172
+ static forDemo(jwtProvider) {
1173
+ return Promise.resolve()
1174
+ .then(() => {
1175
+ assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
1206
1176
 
1207
- return start(new PortfolioGateway('https', Configuration.productionHost, 443, 'production', requestInterceptor));
1177
+ return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.demoHost, REST_API_SECURE_PORT, 'demo'), jwtProvider);
1208
1178
  });
1209
1179
  }
1210
1180
 
1211
1181
  /**
1212
- * Creates and starts a new {@link PortfolioGateway} for use in the administration environment.
1182
+ * Creates and starts a new {@link PortfolioGateway} for use in the public production environment.
1213
1183
  *
1214
1184
  * @public
1215
1185
  * @static
1216
- * @param {RequestInterceptor=|Promise<RequestInterceptor>=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
1186
+ * @param {JwtProvider} jwtProvider
1217
1187
  * @returns {Promise<PortfolioGateway>}
1218
1188
  */
1219
- static forAdmin(requestInterceptor) {
1220
- return Promise.resolve(requestInterceptor)
1221
- .then((requestInterceptor) => {
1222
- assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'RequestInterceptor');
1189
+ static forProduction(jwtProvider) {
1190
+ return Promise.resolve()
1191
+ .then(() => {
1192
+ assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
1193
+
1194
+ return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.productionHost, REST_API_SECURE_PORT, 'production'), jwtProvider);
1195
+ });
1196
+ }
1197
+
1198
+ /**
1199
+ * Creates and starts a new {@link PortfolioGateway} for use in the private admin environment.
1200
+ *
1201
+ * @public
1202
+ * @static
1203
+ * @param {JwtProvider} jwtProvider
1204
+ * @returns {Promise<PortfolioGateway>}
1205
+ */
1206
+ static forAdmin(jwtProvider) {
1207
+ return Promise.resolve()
1208
+ .then(() => {
1209
+ assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
1223
1210
 
1224
- return start(new PortfolioGateway('https', Configuration.adminHost, 443, 'admin', requestInterceptor));
1211
+ return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.adminHost, REST_API_SECURE_PORT, 'admin'), jwtProvider);
1225
1212
  });
1226
1213
  }
1227
1214
 
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const JwtGateway = require('./gateway/jwt/JwtGateway'),
1
+ const JwtGateway = require('./security/JwtGateway'),
2
2
  PortfolioGateway = require('./gateway/PortfolioGateway');
3
3
 
4
4
  module.exports = (() => {
@@ -7,6 +7,6 @@ module.exports = (() => {
7
7
  return {
8
8
  JwtGateway: JwtGateway,
9
9
  PortfolioGateway: PortfolioGateway,
10
- version: '1.5.1'
10
+ version: '2.0.0'
11
11
  };
12
12
  })();