@barchart/portfolio-api-common 1.3.16 → 1.3.20

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
@@ -1,2 +1,7 @@
1
1
  # @barchart/portfolio-api-common
2
2
  ## Barchart Portfolio API Common Components
3
+
4
+ Shared code, used by the serverless application and the client-side SDK. See:
5
+
6
+ * https://github.com/barchart/aws-lambda-portfolio and
7
+ * https://github.com/barchart/portfolio-client-js
package/gulpfile.js CHANGED
@@ -1,5 +1,7 @@
1
1
  const gulp = require('gulp');
2
2
 
3
+ const fs = require('fs');
4
+
3
5
  const browserify = require('browserify'),
4
6
  buffer = require('vinyl-buffer'),
5
7
  bump = require('gulp-bump'),
@@ -9,31 +11,30 @@ const browserify = require('browserify'),
9
11
  glob = require('glob'),
10
12
  jasmine = require('gulp-jasmine'),
11
13
  jshint = require('gulp-jshint'),
12
- runSequence = require('run-sequence'),
13
- source = require('vinyl-source-stream'),
14
- util = require('gulp-util');
15
-
16
- const fs = require('fs');
14
+ replace = require('gulp-replace'),
15
+ source = require('vinyl-source-stream');
17
16
 
18
17
  function getVersionFromPackage() {
19
18
  return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
20
19
  }
21
20
 
22
- gulp.task('ensure-clean-working-directory', () => {
23
- gitStatus(function(err, status) {
21
+ gulp.task('ensure-clean-working-directory', (cb) => {
22
+ gitStatus((err, status) => {
24
23
  if (err, !status.clean) {
25
24
  throw new Error('Unable to proceed, your working directory is not clean.');
26
25
  }
26
+
27
+ cb();
27
28
  });
28
29
  });
29
30
 
30
31
  gulp.task('bump-version', () => {
31
- return gulp.src([ './package.json' ])
32
- .pipe(bump({ type: 'patch' }).on('error', util.log))
33
- .pipe(gulp.dest('./'));
32
+ return gulp.src([ './package.json' ])
33
+ .pipe(bump({ type: 'patch' }))
34
+ .pipe(gulp.dest('./'));
34
35
  });
35
36
 
36
- gulp.task('document', function (cb) {
37
+ gulp.task('document', (cb) => {
37
38
  exec('jsdoc . -c jsdoc.json -r -d docs', (error, stdout, stderr) => {
38
39
  console.log(stdout);
39
40
  console.log(stderr);
@@ -55,7 +56,7 @@ gulp.task('push-changes', (cb) => {
55
56
  gulp.task('create-tag', (cb) => {
56
57
  const version = getVersionFromPackage();
57
58
 
58
- git.tag(version, 'Release ' + version, function (error) {
59
+ git.tag(version, 'Release ' + version, (error) => {
59
60
  if (error) {
60
61
  return cb(error);
61
62
  }
@@ -82,41 +83,21 @@ gulp.task('execute-node-tests', () => {
82
83
  .pipe(jasmine());
83
84
  });
84
85
 
85
- gulp.task('execute-tests', (cb) => {
86
- runSequence(
87
- 'build-test-bundle',
88
- 'execute-browser-tests',
89
- 'execute-node-tests',
90
-
91
- function (error) {
92
- if (error) {
93
- console.log(error.message);
94
- }
95
-
96
- cb(error);
97
- });
98
- });
99
-
100
- gulp.task('release', (cb) => {
101
- runSequence(
102
- 'ensure-clean-working-directory',
103
- 'execute-tests',
104
- 'document',
105
- 'bump-version',
106
- 'commit-changes',
107
- 'push-changes',
108
- 'create-tag',
109
-
110
- function (error) {
111
- if (error) {
112
- console.log(error.message);
113
- } else {
114
- console.log('Release complete');
115
- }
116
-
117
- cb(error);
118
- });
119
- });
86
+ gulp.task('execute-tests', gulp.series(
87
+ 'build-test-bundle',
88
+ 'execute-browser-tests',
89
+ 'execute-node-tests'
90
+ ));
91
+
92
+ gulp.task('release', gulp.series(
93
+ 'ensure-clean-working-directory',
94
+ 'execute-tests',
95
+ 'document',
96
+ 'bump-version',
97
+ 'commit-changes',
98
+ 'push-changes',
99
+ 'create-tag'
100
+ ));
120
101
 
121
102
  gulp.task('lint', () => {
122
103
  return gulp.src([ './**/*.js', './test/specs/**/*.js', '!./node_modules/**', '!./docs/**', '!./test/SpecRunner.js' ])
@@ -124,6 +105,6 @@ gulp.task('lint', () => {
124
105
  .pipe(jshint.reporter('default'));
125
106
  });
126
107
 
127
- gulp.task('test', [ 'execute-tests' ]);
108
+ gulp.task('test', gulp.series('execute-tests'));
128
109
 
129
- gulp.task('default', [ 'lint' ]);
110
+ gulp.task('default', gulp.series('lint'));
@@ -142,6 +142,17 @@ module.exports = (() => {
142
142
  return transactionCreateFailedInvalidInitialType;
143
143
  }
144
144
 
145
+ /**
146
+ * A valuation transaction cannot have a negative rate (or amount).
147
+ *
148
+ * @public
149
+ * @static
150
+ * @returns {FailureType}
151
+ */
152
+ static get TRANSACTION_CREATE_FAILED_VALUATION_NEGATIVE() {
153
+ return transactionCreateFailedValuationNegative;
154
+ }
155
+
145
156
  /**
146
157
  * The transaction (of this type) cannot be created by a user, instead,
147
158
  * it is created and managed by the system (e.g. dividends).
@@ -285,20 +296,21 @@ module.exports = (() => {
285
296
  }
286
297
  }
287
298
 
288
- const portfolioUpdateFailedNoPortfolio = new FailureType('PORTFOLIO_UPDATE_FAILED_NO_PORTFOLIO', 'Unable to update portfolio. The portfolio does not exist, has it been deleted?');
289
- const portfolioDeleteFailedNoPortfolio = new FailureType('PORTFOLIO_DELETE_FAILED_NO_PORTFOLIO', 'Unable to delete portfolio. The portfolio does not exist, has it already been deleted?');
299
+ const portfolioUpdateFailedNoPortfolio = new FailureType('PORTFOLIO_UPDATE_FAILED_NO_PORTFOLIO', 'Unable to update portfolio. The portfolio does not exist, has it been deleted?', false);
300
+ const portfolioDeleteFailedNoPortfolio = new FailureType('PORTFOLIO_DELETE_FAILED_NO_PORTFOLIO', 'Unable to delete portfolio. The portfolio does not exist, has it already been deleted?', false);
290
301
 
291
- const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_NO_PORTFOLIO', 'Unable to create transaction. The portfolio does not exist, has it been deleted?');
292
- const positionUpdateFailedNoPosition = new FailureType('POSITION_UPDATE_FAILED_NO_POSITION', 'Unable to update preferences for position. The position does not exist, has it been deleted?');
302
+ const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_NO_PORTFOLIO', 'Unable to create transaction. The portfolio does not exist, has it been deleted?', false);
303
+ const positionUpdateFailedNoPosition = new FailureType('POSITION_UPDATE_FAILED_NO_POSITION', 'Unable to update preferences for position. The position does not exist, has it been deleted?', false);
293
304
  const positionDeleteFailedPositionLocked = new FailureType('POSITION_DELETE_FAILED_POSITION_LOCKED', 'Unable to delete position, your {L|description} history is being recalculated. Please wait a minute or two and retry.');
294
305
 
295
- const transactionCreateFailedNoPosition = new FailureType('TRANSACTION_CREATE_FAILED_NO_POSITION', 'Unable to create transaction. The referenced position does not exist. Has it been deleted?');
306
+ const transactionCreateFailedNoPosition = new FailureType('TRANSACTION_CREATE_FAILED_NO_POSITION', 'Unable to create transaction. The referenced position does not exist. Has it been deleted?', false);
296
307
  const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to process transaction, because the transaction date is out-of-sequence. In other words, it would occur before an existing transaction. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
297
308
  const transactionCreateFailedInvalidDate = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DATE', 'Unable to process transaction with given date.');
298
309
  const transactionCreateFailedTypeInvalidForInstrument = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_INSTRUMENT', 'Unable to process transaction, {L|transactionType.description} transactions cannot be used with {L|instrumentType.description} positions.');
299
310
  const transactionCreateFailedTypeInvalidForDirection = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_DIRECTION', 'Unable to process transaction, a {L|positionDirection.description} position would be created (i.e. you would have {L|positionDirection.sign} shares/units). {u|instrumentType.description} positions cannot have {L|positionDirection.description} positions.', false);
300
311
  const transactionCreateFailedInvalidDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_DIRECTION_SWITCH', 'Unable to process transaction, the transaction would switch the position from {L|currentDirection.description} to {L|proposedDirection.description} (i.e. {L|currentDirection.sign} to {L|proposedDirection.sign} shares/units). This is not allowed. Please close the current position (i.e. zero it out) and then enter a second transaction.', false);
301
- const transactionCreateFailedInvalidInitialType = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_INITIAL_TYPE', 'Unable to process operation because the first transaction would to be a {U|transactionType.description}, which is not allowed -- since {U|transactionType.description} transactions cannot open a position.');
312
+ const transactionCreateFailedInvalidInitialType = new FailureType('TRANSACTION_CREATE_FAILED_INVALID_INITIAL_TYPE', 'Unable to process operation because the first transaction would to be a {U|transactionType.description}, which is not allowed -- since {U|transactionType.description} transactions cannot open a position.', false);
313
+ const transactionCreateFailedValuationNegative = new FailureType('TRANSACTION_CREATE_FAILED_VALUATION_NEGATIVE', 'Unable to process operation, valuations cannot be negative.', false);
302
314
 
303
315
  const transactionCreateFailedTypeReserved = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_RESERVED', 'Unable to create {U|type.description} transaction, this type of transaction is managed by the system.');
304
316
  const transactionCreateFailedReinvestPriceUnavailable = new FailureType('TRANSACTION_CREATE_FAILED_REINVEST_PRICE_UNAVAILABLE', 'Unable to create transaction, a dividend was paid on {L|day}; however no historical price is available for this day. To successfully create this transaction, please turn off dividend reinvestment for this position.');
@@ -218,7 +218,6 @@ module.exports = (() => {
218
218
  const last = array.last(transactions);
219
219
 
220
220
  const firstDate = first.date;
221
- const lastDate = last.date;
222
221
 
223
222
  let lastYear;
224
223
 
@@ -277,13 +276,12 @@ module.exports = (() => {
277
276
  const ranges = [ ];
278
277
 
279
278
  if (transactions.length !== 0) {
280
- const first = array.first(transactions);
281
279
  const last = array.last(transactions);
282
280
 
283
281
  const currentYear = Day.getToday().year;
284
282
 
285
283
  if (!last.snapshot.open.getIsZero() || last.date.year === currentYear) {
286
- let end = new Day(Day.getToday().year, 12, 31);
284
+ let end = new Day(currentYear, 12, 31);
287
285
  let start = end.subtractYears(1);
288
286
 
289
287
  ranges.push(getRange(start, end));
@@ -54,6 +54,18 @@ module.exports = (() => {
54
54
  return client;
55
55
  }
56
56
 
57
+ /**
58
+ * Reduced schema that only includes frames and dates -- allowing consumer
59
+ * to detect existence (or non-existence) of summary.
60
+ *
61
+ * @static
62
+ * @public
63
+ * @returns {PositionSummarySchema}
64
+ */
65
+ static get EXISTS() {
66
+ return exists;
67
+ }
68
+
57
69
  toString() {
58
70
  return '[PositionSummarySchema]';
59
71
  }
@@ -111,5 +123,15 @@ module.exports = (() => {
111
123
  .schema
112
124
  );
113
125
 
126
+ const exists = new PositionSummarySchema(SchemaBuilder.withName('complete')
127
+ .withField('user', DataType.STRING)
128
+ .withField('portfolio', DataType.STRING)
129
+ .withField('position', DataType.STRING)
130
+ .withField('frame', DataType.forEnum(PositionSummaryFrame, 'PositionSummaryFrame'))
131
+ .withField('start.date', DataType.DAY)
132
+ .withField('end.date', DataType.DAY)
133
+ .schema
134
+ );
135
+
114
136
  return PositionSummarySchema;
115
137
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.3.16",
3
+ "version": "1.3.20",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -13,23 +13,22 @@
13
13
  "uuid": "3.1.0"
14
14
  },
15
15
  "devDependencies": {
16
- "babel-core": "^6.26.0",
17
- "babel-preset-es2015": "^6.24.1",
18
- "babelify": "^8.0.0",
19
- "browserify": "^14.5.0",
16
+ "@babel/core": "^7.6.2",
17
+ "babelify": "^10.0.0",
18
+ "browserify": "^16.5.0",
20
19
  "git-get-status": "^1.0.5",
21
20
  "glob": "^6.0.1",
22
- "gulp": "~3.9.0",
21
+ "gulp": "^4.0.2",
23
22
  "gulp-bump": "~1.0.0",
24
- "gulp-git": "^2.5.1",
23
+ "gulp-git": "^2.9.0",
25
24
  "gulp-jasmine": "^2.2.1",
25
+ "gulp-jsdoc3": "^1.0.1",
26
26
  "gulp-jshint": "~2.1.0",
27
- "gulp-util": "^3.0.7",
27
+ "gulp-replace": "^0.5.4",
28
28
  "jsdoc": "^3.5.5",
29
29
  "jshint": "2.9.5",
30
- "run-sequence": "~1.1.4",
31
- "vinyl-buffer": "^1.0.0",
32
- "vinyl-source-stream": "^1.1.0"
30
+ "vinyl-buffer": "^1.0.1",
31
+ "vinyl-source-stream": "^2.0.0"
33
32
  },
34
33
  "license": "GPL-3.0"
35
34
  }