@barchart/portfolio-client-js 1.4.7 → 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.
- package/.releases/2.0.0.md +10 -0
- package/gulpfile.js +2 -11
- package/lib/common/Configuration.js +46 -23
- package/lib/gateway/PortfolioGateway.js +150 -127
- package/lib/index.js +2 -2
- package/lib/security/JwtProvider.js +188 -0
- package/lib/security/meta.js +14 -0
- package/package.json +6 -6
- package/example/example.css +0 -124
- package/example/example.html +0 -98
- package/example/example.js +0 -22074
- package/example/js/startup.js +0 -963
- package/lib/gateway/jwt/JwtGateway.js +0 -410
|
@@ -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
|
-
*
|
|
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
|
|
38
|
-
* @param {String} host - The
|
|
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
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
361
|
+
.withRequestInterceptor(requestInterceptor)
|
|
362
362
|
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
363
363
|
.withResponseInterceptor(responseInterceptorForWealthscopeToken)
|
|
364
364
|
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
@@ -379,12 +379,27 @@ 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(
|
|
382
|
+
.withRequestInterceptor(requestInterceptor)
|
|
383
383
|
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
384
384
|
.withResponseInterceptor(responseInterceptorForBrokerageReportAvailabilityDeserialization)
|
|
385
385
|
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
386
386
|
.endpoint;
|
|
387
387
|
|
|
388
|
+
this._readVersionEndpoint = EndpointBuilder.for('read-api-version', 'read api version')
|
|
389
|
+
.withVerb(VerbType.GET)
|
|
390
|
+
.withProtocol(protocolType)
|
|
391
|
+
.withHost(host)
|
|
392
|
+
.withPort(port)
|
|
393
|
+
.withPathBuilder((pb) => {
|
|
394
|
+
pb.withLiteralParameter('system', 'system')
|
|
395
|
+
.withLiteralParameter('version', 'version');
|
|
396
|
+
})
|
|
397
|
+
.withRequestInterceptor(requestInterceptor)
|
|
398
|
+
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
399
|
+
.withResponseInterceptor(responseInterceptorForVersion)
|
|
400
|
+
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
401
|
+
.endpoint;
|
|
402
|
+
|
|
388
403
|
this._brokerageReportUrlGenerator = (user, portfolio, frame, end) => {
|
|
389
404
|
return `https://${Configuration.getBrokerageHost(host)}/reports/portfolios/${portfolio}/frames/${frame.code}/date/${end.format()}/${user}`;
|
|
390
405
|
};
|
|
@@ -394,31 +409,40 @@ module.exports = (() => {
|
|
|
394
409
|
* Returns a description of the environment (e.g. development or production).
|
|
395
410
|
*
|
|
396
411
|
* @public
|
|
397
|
-
* @returns {
|
|
412
|
+
* @returns {String}
|
|
398
413
|
*/
|
|
399
414
|
get environment() {
|
|
400
415
|
return this._environment;
|
|
401
416
|
}
|
|
402
417
|
|
|
403
418
|
/**
|
|
404
|
-
*
|
|
405
|
-
*
|
|
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.
|
|
406
422
|
*
|
|
407
423
|
* @public
|
|
424
|
+
* @param {JwtProvider} jwtProvider
|
|
408
425
|
* @returns {Promise<PortfolioGateway>}
|
|
409
426
|
*/
|
|
410
|
-
|
|
427
|
+
connect(jwtProvider) {
|
|
411
428
|
return Promise.resolve()
|
|
412
429
|
.then(() => {
|
|
430
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
431
|
+
|
|
413
432
|
if (this._startPromise === null) {
|
|
414
433
|
this._startPromise = Promise.resolve()
|
|
415
434
|
.then(() => {
|
|
416
435
|
this._started = true;
|
|
417
436
|
|
|
437
|
+
this._jwtProvider = jwtProvider;
|
|
438
|
+
|
|
418
439
|
return this;
|
|
419
440
|
}).catch((e) => {
|
|
441
|
+
this._started = false;
|
|
420
442
|
this._startPromise = null;
|
|
421
443
|
|
|
444
|
+
this._jwtProvider = null;
|
|
445
|
+
|
|
422
446
|
throw e;
|
|
423
447
|
});
|
|
424
448
|
}
|
|
@@ -837,45 +861,6 @@ module.exports = (() => {
|
|
|
837
861
|
});
|
|
838
862
|
}
|
|
839
863
|
|
|
840
|
-
/**
|
|
841
|
-
* Creates one or more new transactions.
|
|
842
|
-
*
|
|
843
|
-
* @public
|
|
844
|
-
* @param {Object} transaction
|
|
845
|
-
* @returns {Promise}
|
|
846
|
-
*/
|
|
847
|
-
batchTransactions(portfolio, transactions) {
|
|
848
|
-
return Promise.resolve()
|
|
849
|
-
.then(() => {
|
|
850
|
-
checkStart.call(this);
|
|
851
|
-
|
|
852
|
-
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
853
|
-
assert.argumentIsArray(transactions, 'transactions', Object);
|
|
854
|
-
|
|
855
|
-
const payload = { };
|
|
856
|
-
|
|
857
|
-
payload.portfolio = portfolio.portfolio;
|
|
858
|
-
payload.transactionTypes = [ ];
|
|
859
|
-
payload.transactionItems = [ ];
|
|
860
|
-
|
|
861
|
-
transactions.forEach((transaction) => {
|
|
862
|
-
transaction.portfolio = portfolio.portfolio;
|
|
863
|
-
|
|
864
|
-
if (!transaction.position) {
|
|
865
|
-
transaction.position = 'new';
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
const code = getTransactionTypeCode(transaction);
|
|
869
|
-
const schema = getTransactionSchema(transaction);
|
|
870
|
-
|
|
871
|
-
payload.transactionTypes.push(code);
|
|
872
|
-
payload.transactionItems.push(JSON.stringify(schema.schema.format(transaction)));
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
return Gateway.invoke(this._batchTransactionEndpoint, payload);
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
|
|
879
864
|
/**
|
|
880
865
|
* Edits a transaction.
|
|
881
866
|
*
|
|
@@ -1088,6 +1073,19 @@ module.exports = (() => {
|
|
|
1088
1073
|
});
|
|
1089
1074
|
}
|
|
1090
1075
|
|
|
1076
|
+
/**
|
|
1077
|
+
* Returns current API version of portfolio.
|
|
1078
|
+
*
|
|
1079
|
+
* @public
|
|
1080
|
+
* @returns {Promise<Object>}
|
|
1081
|
+
*/
|
|
1082
|
+
readVersion() {
|
|
1083
|
+
return Promise.resolve()
|
|
1084
|
+
.then(() => {
|
|
1085
|
+
return Gateway.invoke(this._readVersionEndpoint);
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1091
1089
|
/**
|
|
1092
1090
|
* Generates a URL suitable for downloading a brokerage report (as a PDF).
|
|
1093
1091
|
*
|
|
@@ -1113,87 +1111,104 @@ module.exports = (() => {
|
|
|
1113
1111
|
}
|
|
1114
1112
|
|
|
1115
1113
|
/**
|
|
1116
|
-
* Creates and starts a new {@link PortfolioGateway} for use in the
|
|
1114
|
+
* Creates and starts a new {@link PortfolioGateway} for use in the public test environment.
|
|
1115
|
+
*
|
|
1116
|
+
* @public
|
|
1117
|
+
* @static
|
|
1118
|
+
* @param {JwtProvider} jwtProvider
|
|
1119
|
+
* @returns {Promise<PortfolioGateway>}
|
|
1120
|
+
*/
|
|
1121
|
+
static forTest(jwtProvider) {
|
|
1122
|
+
return Promise.resolve()
|
|
1123
|
+
.then(() => {
|
|
1124
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1125
|
+
|
|
1126
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.testHost, REST_API_SECURE_PORT, 'test'), jwtProvider);
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* Creates and starts a new {@link PortfolioGateway} for use in the private development environment.
|
|
1117
1132
|
*
|
|
1118
1133
|
* @public
|
|
1119
1134
|
* @static
|
|
1120
|
-
* @param {
|
|
1135
|
+
* @param {JwtProvider} jwtProvider
|
|
1121
1136
|
* @returns {Promise<PortfolioGateway>}
|
|
1122
1137
|
*/
|
|
1123
|
-
static forDevelopment(
|
|
1124
|
-
return Promise.resolve(
|
|
1125
|
-
.then((
|
|
1126
|
-
assert.
|
|
1138
|
+
static forDevelopment(jwtProvider) {
|
|
1139
|
+
return Promise.resolve()
|
|
1140
|
+
.then(() => {
|
|
1141
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1127
1142
|
|
|
1128
|
-
return start(new PortfolioGateway(
|
|
1143
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.developmentHost, REST_API_SECURE_PORT, 'development'), jwtProvider);
|
|
1129
1144
|
});
|
|
1130
1145
|
}
|
|
1131
1146
|
|
|
1132
1147
|
/**
|
|
1133
|
-
* Creates and starts a new {@link PortfolioGateway} for use in the staging environment.
|
|
1148
|
+
* Creates and starts a new {@link PortfolioGateway} for use in the private staging environment.
|
|
1134
1149
|
*
|
|
1135
1150
|
* @public
|
|
1136
1151
|
* @static
|
|
1137
|
-
* @param {
|
|
1152
|
+
* @param {JwtProvider} jwtProvider
|
|
1138
1153
|
* @returns {Promise<PortfolioGateway>}
|
|
1139
1154
|
*/
|
|
1140
|
-
static forStaging(
|
|
1141
|
-
return Promise.resolve(
|
|
1142
|
-
.then((
|
|
1143
|
-
assert.
|
|
1155
|
+
static forStaging(jwtProvider) {
|
|
1156
|
+
return Promise.resolve()
|
|
1157
|
+
.then(() => {
|
|
1158
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1144
1159
|
|
|
1145
|
-
return start(new PortfolioGateway(
|
|
1160
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.stagingHost, REST_API_SECURE_PORT, 'staging'), jwtProvider);
|
|
1146
1161
|
});
|
|
1147
1162
|
}
|
|
1148
1163
|
|
|
1149
1164
|
/**
|
|
1150
|
-
* Creates and starts a new {@link PortfolioGateway} for use in the demo environment.
|
|
1165
|
+
* Creates and starts a new {@link PortfolioGateway} for use in the private demo environment.
|
|
1151
1166
|
*
|
|
1152
1167
|
* @public
|
|
1153
1168
|
* @static
|
|
1154
|
-
* @param {
|
|
1169
|
+
* @param {JwtProvider} jwtProvider
|
|
1155
1170
|
* @returns {Promise<PortfolioGateway>}
|
|
1156
1171
|
*/
|
|
1157
|
-
static forDemo(
|
|
1158
|
-
return Promise.resolve(
|
|
1159
|
-
.then((
|
|
1160
|
-
assert.
|
|
1172
|
+
static forDemo(jwtProvider) {
|
|
1173
|
+
return Promise.resolve()
|
|
1174
|
+
.then(() => {
|
|
1175
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1161
1176
|
|
|
1162
|
-
return start(new PortfolioGateway(
|
|
1177
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.demoHost, REST_API_SECURE_PORT, 'demo'), jwtProvider);
|
|
1163
1178
|
});
|
|
1164
1179
|
}
|
|
1165
1180
|
|
|
1166
1181
|
/**
|
|
1167
|
-
* Creates and starts a new {@link PortfolioGateway} for use in the production environment.
|
|
1182
|
+
* Creates and starts a new {@link PortfolioGateway} for use in the public production environment.
|
|
1168
1183
|
*
|
|
1169
1184
|
* @public
|
|
1170
1185
|
* @static
|
|
1171
|
-
* @param {
|
|
1186
|
+
* @param {JwtProvider} jwtProvider
|
|
1172
1187
|
* @returns {Promise<PortfolioGateway>}
|
|
1173
1188
|
*/
|
|
1174
|
-
static forProduction(
|
|
1175
|
-
return Promise.resolve(
|
|
1176
|
-
.then((
|
|
1177
|
-
assert.
|
|
1189
|
+
static forProduction(jwtProvider) {
|
|
1190
|
+
return Promise.resolve()
|
|
1191
|
+
.then(() => {
|
|
1192
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1178
1193
|
|
|
1179
|
-
return start(new PortfolioGateway(
|
|
1194
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.productionHost, REST_API_SECURE_PORT, 'production'), jwtProvider);
|
|
1180
1195
|
});
|
|
1181
1196
|
}
|
|
1182
1197
|
|
|
1183
1198
|
/**
|
|
1184
|
-
* Creates and starts a new {@link PortfolioGateway} for use in the
|
|
1199
|
+
* Creates and starts a new {@link PortfolioGateway} for use in the private admin environment.
|
|
1185
1200
|
*
|
|
1186
1201
|
* @public
|
|
1187
1202
|
* @static
|
|
1188
|
-
* @param {
|
|
1203
|
+
* @param {JwtProvider} jwtProvider
|
|
1189
1204
|
* @returns {Promise<PortfolioGateway>}
|
|
1190
1205
|
*/
|
|
1191
|
-
static forAdmin(
|
|
1192
|
-
return Promise.resolve(
|
|
1193
|
-
.then((
|
|
1194
|
-
assert.
|
|
1206
|
+
static forAdmin(jwtProvider) {
|
|
1207
|
+
return Promise.resolve()
|
|
1208
|
+
.then(() => {
|
|
1209
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1195
1210
|
|
|
1196
|
-
return start(new PortfolioGateway(
|
|
1211
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.adminHost, REST_API_SECURE_PORT, 'admin'), jwtProvider);
|
|
1197
1212
|
});
|
|
1198
1213
|
}
|
|
1199
1214
|
|
|
@@ -1323,6 +1338,14 @@ module.exports = (() => {
|
|
|
1323
1338
|
}
|
|
1324
1339
|
});
|
|
1325
1340
|
|
|
1341
|
+
const responseInterceptorForVersion = ResponseInterceptor.fromDelegate((response, ignored) => {
|
|
1342
|
+
try {
|
|
1343
|
+
return JSON.parse(response.data);
|
|
1344
|
+
} catch (e) {
|
|
1345
|
+
console.error('Error deserializing data', e);
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1326
1349
|
function start(gateway) {
|
|
1327
1350
|
return gateway.start()
|
|
1328
1351
|
.then(() => {
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const JwtGateway = require('./
|
|
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: '
|
|
10
|
+
version: '2.0.0'
|
|
11
11
|
};
|
|
12
12
|
})();
|