@allthings/sdk 6.6.0 → 7.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/dist/lib.esm.js CHANGED
@@ -1,4 +1,3 @@
1
- import { SSMClient, GetParametersCommand, GetParameterCommand } from '@aws-sdk/client-ssm';
2
1
  import querystring from 'query-string';
3
2
  import fetch from 'cross-fetch';
4
3
  import Bottleneck from 'bottleneck';
@@ -10,7 +9,16 @@ import require$$4 from 'https';
10
9
  import require$$5 from 'url';
11
10
  import require$$6 from 'fs';
12
11
 
13
- const version = "6.6.0";
12
+ function createTokenStore(initialToken) {
13
+ const token = new Map(Object.entries(initialToken || {}));
14
+ return {
15
+ get: (key) => token.get(key),
16
+ reset: () => token.clear(),
17
+ set: (update) => Object.entries(update).forEach(([key, value]) => token.set(key, value)),
18
+ };
19
+ }
20
+
21
+ const version = "7.0.0";
14
22
 
15
23
  const REST_API_URL = 'https://api.allthings.me';
16
24
  const OAUTH_URL = 'https://accounts.allthings.me';
@@ -32,81 +40,6 @@ const DEFAULT_API_WRAPPER_OPTIONS = {
32
40
  username: process.env.ALLTHINGS_OAUTH_USERNAME,
33
41
  };
34
42
  const USER_AGENT = `Allthings Node SDK REST Client/${version}`;
35
- const DEFAULT_AWS_CONFIGURATION = {
36
- region: 'eu-central-2',
37
- };
38
-
39
- var __rest$5 = (undefined && undefined.__rest) || function (s, e) {
40
- var t = {};
41
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
42
- t[p] = s[p];
43
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
44
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
45
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
46
- t[p[i]] = s[p[i]];
47
- }
48
- return t;
49
- };
50
- const DEFAULT_CLIENT_CONFIG = {
51
- clientConfig: DEFAULT_AWS_CONFIGURATION,
52
- onlyDefault: false,
53
- prefix: process.env.SSM_PARAM_PATH,
54
- };
55
- const getSecrets = async (ssm, config, params, defaultValue) => {
56
- var _a, _b;
57
- if (config.onlyDefault) {
58
- return [defaultValue];
59
- }
60
- try {
61
- const parameters = await ssm.send(new GetParametersCommand({
62
- Names: params.map((param) => `${config.prefix ? config.prefix : ''}${param}`),
63
- WithDecryption: true,
64
- }));
65
- return ((_b = (_a = parameters === null || parameters === void 0 ? void 0 : parameters.Parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => { var _a; return (_a = parameter.Value) !== null && _a !== void 0 ? _a : defaultValue; })) !== null && _b !== void 0 ? _b : [defaultValue]);
66
- }
67
- catch (e) {
68
- if (config.logger) {
69
- config.logger(e);
70
- }
71
- return [defaultValue];
72
- }
73
- };
74
- const getSecret = async (ssm, config, param, defaultValue) => {
75
- var _a, _b;
76
- if (config.onlyDefault) {
77
- return defaultValue;
78
- }
79
- try {
80
- const parameter = await ssm.send(new GetParameterCommand({
81
- Name: `${config.prefix ? config.prefix : ''}${param}`,
82
- WithDecryption: true,
83
- }));
84
- return (_b = (_a = parameter === null || parameter === void 0 ? void 0 : parameter.Parameter) === null || _a === void 0 ? void 0 : _a.Value) !== null && _b !== void 0 ? _b : defaultValue;
85
- }
86
- catch (e) {
87
- if (config.logger) {
88
- config.logger(e);
89
- }
90
- return defaultValue;
91
- }
92
- };
93
- const parameterStore = (userConfig) => {
94
- const _a = Object.assign(Object.assign({}, DEFAULT_CLIENT_CONFIG), userConfig), { clientConfig } = _a, config = __rest$5(_a, ["clientConfig"]);
95
- const ssm = new SSMClient(clientConfig);
96
- return {
97
- getSecret: (param, defaultValue = '') => getSecret(ssm, config, param, defaultValue),
98
- getSecrets: (params, defaultValue = '') => getSecrets(ssm, config, params, defaultValue),
99
- };
100
- };
101
-
102
- function createTokenStore(initialToken) {
103
- const token = new Map(Object.entries(initialToken || {}));
104
- return {
105
- get: (key) => token.get(key),
106
- reset: () => token.clear(),
107
- set: (update) => Object.entries(update).forEach(([key, value]) => token.set(key, value)),
108
- };
109
- }
110
43
 
111
44
  const RESPONSE_TYPE$1 = 'code';
112
45
  const GRANT_TYPE$3 = 'authorization_code';
@@ -918,322 +851,338 @@ function getDefaultExportFromCjs (x) {
918
851
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
919
852
  }
920
853
 
921
- var Stream$2 = require$$0$1.Stream;
922
- var util$2 = require$$1;
923
-
924
- var delayed_stream = DelayedStream$1;
925
- function DelayedStream$1() {
926
- this.source = null;
927
- this.dataSize = 0;
928
- this.maxDataSize = 1024 * 1024;
929
- this.pauseStream = true;
930
-
931
- this._maxDataSizeExceeded = false;
932
- this._released = false;
933
- this._bufferedEvents = [];
934
- }
935
- util$2.inherits(DelayedStream$1, Stream$2);
854
+ var delayed_stream;
855
+ var hasRequiredDelayed_stream;
856
+
857
+ function requireDelayed_stream () {
858
+ if (hasRequiredDelayed_stream) return delayed_stream;
859
+ hasRequiredDelayed_stream = 1;
860
+ var Stream = require$$0$1.Stream;
861
+ var util = require$$1;
862
+
863
+ delayed_stream = DelayedStream;
864
+ function DelayedStream() {
865
+ this.source = null;
866
+ this.dataSize = 0;
867
+ this.maxDataSize = 1024 * 1024;
868
+ this.pauseStream = true;
869
+
870
+ this._maxDataSizeExceeded = false;
871
+ this._released = false;
872
+ this._bufferedEvents = [];
873
+ }
874
+ util.inherits(DelayedStream, Stream);
936
875
 
937
- DelayedStream$1.create = function(source, options) {
938
- var delayedStream = new this();
876
+ DelayedStream.create = function(source, options) {
877
+ var delayedStream = new this();
939
878
 
940
- options = options || {};
941
- for (var option in options) {
942
- delayedStream[option] = options[option];
943
- }
879
+ options = options || {};
880
+ for (var option in options) {
881
+ delayedStream[option] = options[option];
882
+ }
944
883
 
945
- delayedStream.source = source;
884
+ delayedStream.source = source;
946
885
 
947
- var realEmit = source.emit;
948
- source.emit = function() {
949
- delayedStream._handleEmit(arguments);
950
- return realEmit.apply(source, arguments);
951
- };
886
+ var realEmit = source.emit;
887
+ source.emit = function() {
888
+ delayedStream._handleEmit(arguments);
889
+ return realEmit.apply(source, arguments);
890
+ };
952
891
 
953
- source.on('error', function() {});
954
- if (delayedStream.pauseStream) {
955
- source.pause();
956
- }
892
+ source.on('error', function() {});
893
+ if (delayedStream.pauseStream) {
894
+ source.pause();
895
+ }
957
896
 
958
- return delayedStream;
959
- };
897
+ return delayedStream;
898
+ };
960
899
 
961
- Object.defineProperty(DelayedStream$1.prototype, 'readable', {
962
- configurable: true,
963
- enumerable: true,
964
- get: function() {
965
- return this.source.readable;
966
- }
967
- });
900
+ Object.defineProperty(DelayedStream.prototype, 'readable', {
901
+ configurable: true,
902
+ enumerable: true,
903
+ get: function() {
904
+ return this.source.readable;
905
+ }
906
+ });
968
907
 
969
- DelayedStream$1.prototype.setEncoding = function() {
970
- return this.source.setEncoding.apply(this.source, arguments);
971
- };
908
+ DelayedStream.prototype.setEncoding = function() {
909
+ return this.source.setEncoding.apply(this.source, arguments);
910
+ };
972
911
 
973
- DelayedStream$1.prototype.resume = function() {
974
- if (!this._released) {
975
- this.release();
976
- }
912
+ DelayedStream.prototype.resume = function() {
913
+ if (!this._released) {
914
+ this.release();
915
+ }
977
916
 
978
- this.source.resume();
979
- };
917
+ this.source.resume();
918
+ };
980
919
 
981
- DelayedStream$1.prototype.pause = function() {
982
- this.source.pause();
983
- };
920
+ DelayedStream.prototype.pause = function() {
921
+ this.source.pause();
922
+ };
984
923
 
985
- DelayedStream$1.prototype.release = function() {
986
- this._released = true;
924
+ DelayedStream.prototype.release = function() {
925
+ this._released = true;
987
926
 
988
- this._bufferedEvents.forEach(function(args) {
989
- this.emit.apply(this, args);
990
- }.bind(this));
991
- this._bufferedEvents = [];
992
- };
927
+ this._bufferedEvents.forEach(function(args) {
928
+ this.emit.apply(this, args);
929
+ }.bind(this));
930
+ this._bufferedEvents = [];
931
+ };
993
932
 
994
- DelayedStream$1.prototype.pipe = function() {
995
- var r = Stream$2.prototype.pipe.apply(this, arguments);
996
- this.resume();
997
- return r;
998
- };
933
+ DelayedStream.prototype.pipe = function() {
934
+ var r = Stream.prototype.pipe.apply(this, arguments);
935
+ this.resume();
936
+ return r;
937
+ };
999
938
 
1000
- DelayedStream$1.prototype._handleEmit = function(args) {
1001
- if (this._released) {
1002
- this.emit.apply(this, args);
1003
- return;
1004
- }
939
+ DelayedStream.prototype._handleEmit = function(args) {
940
+ if (this._released) {
941
+ this.emit.apply(this, args);
942
+ return;
943
+ }
1005
944
 
1006
- if (args[0] === 'data') {
1007
- this.dataSize += args[1].length;
1008
- this._checkIfMaxDataSizeExceeded();
1009
- }
945
+ if (args[0] === 'data') {
946
+ this.dataSize += args[1].length;
947
+ this._checkIfMaxDataSizeExceeded();
948
+ }
1010
949
 
1011
- this._bufferedEvents.push(args);
1012
- };
950
+ this._bufferedEvents.push(args);
951
+ };
1013
952
 
1014
- DelayedStream$1.prototype._checkIfMaxDataSizeExceeded = function() {
1015
- if (this._maxDataSizeExceeded) {
1016
- return;
1017
- }
1018
-
1019
- if (this.dataSize <= this.maxDataSize) {
1020
- return;
1021
- }
953
+ DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
954
+ if (this._maxDataSizeExceeded) {
955
+ return;
956
+ }
1022
957
 
1023
- this._maxDataSizeExceeded = true;
1024
- var message =
1025
- 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
1026
- this.emit('error', new Error(message));
1027
- };
958
+ if (this.dataSize <= this.maxDataSize) {
959
+ return;
960
+ }
1028
961
 
1029
- var util$1 = require$$1;
1030
- var Stream$1 = require$$0$1.Stream;
1031
- var DelayedStream = delayed_stream;
1032
-
1033
- var combined_stream = CombinedStream$1;
1034
- function CombinedStream$1() {
1035
- this.writable = false;
1036
- this.readable = true;
1037
- this.dataSize = 0;
1038
- this.maxDataSize = 2 * 1024 * 1024;
1039
- this.pauseStreams = true;
1040
-
1041
- this._released = false;
1042
- this._streams = [];
1043
- this._currentStream = null;
1044
- this._insideLoop = false;
1045
- this._pendingNext = false;
962
+ this._maxDataSizeExceeded = true;
963
+ var message =
964
+ 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
965
+ this.emit('error', new Error(message));
966
+ };
967
+ return delayed_stream;
1046
968
  }
1047
- util$1.inherits(CombinedStream$1, Stream$1);
1048
-
1049
- CombinedStream$1.create = function(options) {
1050
- var combinedStream = new this();
1051
969
 
1052
- options = options || {};
1053
- for (var option in options) {
1054
- combinedStream[option] = options[option];
1055
- }
970
+ var combined_stream;
971
+ var hasRequiredCombined_stream;
972
+
973
+ function requireCombined_stream () {
974
+ if (hasRequiredCombined_stream) return combined_stream;
975
+ hasRequiredCombined_stream = 1;
976
+ var util = require$$1;
977
+ var Stream = require$$0$1.Stream;
978
+ var DelayedStream = requireDelayed_stream();
979
+
980
+ combined_stream = CombinedStream;
981
+ function CombinedStream() {
982
+ this.writable = false;
983
+ this.readable = true;
984
+ this.dataSize = 0;
985
+ this.maxDataSize = 2 * 1024 * 1024;
986
+ this.pauseStreams = true;
987
+
988
+ this._released = false;
989
+ this._streams = [];
990
+ this._currentStream = null;
991
+ this._insideLoop = false;
992
+ this._pendingNext = false;
993
+ }
994
+ util.inherits(CombinedStream, Stream);
1056
995
 
1057
- return combinedStream;
1058
- };
996
+ CombinedStream.create = function(options) {
997
+ var combinedStream = new this();
1059
998
 
1060
- CombinedStream$1.isStreamLike = function(stream) {
1061
- return (typeof stream !== 'function')
1062
- && (typeof stream !== 'string')
1063
- && (typeof stream !== 'boolean')
1064
- && (typeof stream !== 'number')
1065
- && (!Buffer.isBuffer(stream));
1066
- };
1067
-
1068
- CombinedStream$1.prototype.append = function(stream) {
1069
- var isStreamLike = CombinedStream$1.isStreamLike(stream);
1070
-
1071
- if (isStreamLike) {
1072
- if (!(stream instanceof DelayedStream)) {
1073
- var newStream = DelayedStream.create(stream, {
1074
- maxDataSize: Infinity,
1075
- pauseStream: this.pauseStreams,
1076
- });
1077
- stream.on('data', this._checkDataSize.bind(this));
1078
- stream = newStream;
1079
- }
999
+ options = options || {};
1000
+ for (var option in options) {
1001
+ combinedStream[option] = options[option];
1002
+ }
1080
1003
 
1081
- this._handleErrors(stream);
1004
+ return combinedStream;
1005
+ };
1006
+
1007
+ CombinedStream.isStreamLike = function(stream) {
1008
+ return (typeof stream !== 'function')
1009
+ && (typeof stream !== 'string')
1010
+ && (typeof stream !== 'boolean')
1011
+ && (typeof stream !== 'number')
1012
+ && (!Buffer.isBuffer(stream));
1013
+ };
1014
+
1015
+ CombinedStream.prototype.append = function(stream) {
1016
+ var isStreamLike = CombinedStream.isStreamLike(stream);
1017
+
1018
+ if (isStreamLike) {
1019
+ if (!(stream instanceof DelayedStream)) {
1020
+ var newStream = DelayedStream.create(stream, {
1021
+ maxDataSize: Infinity,
1022
+ pauseStream: this.pauseStreams,
1023
+ });
1024
+ stream.on('data', this._checkDataSize.bind(this));
1025
+ stream = newStream;
1026
+ }
1082
1027
 
1083
- if (this.pauseStreams) {
1084
- stream.pause();
1085
- }
1086
- }
1028
+ this._handleErrors(stream);
1087
1029
 
1088
- this._streams.push(stream);
1089
- return this;
1090
- };
1030
+ if (this.pauseStreams) {
1031
+ stream.pause();
1032
+ }
1033
+ }
1091
1034
 
1092
- CombinedStream$1.prototype.pipe = function(dest, options) {
1093
- Stream$1.prototype.pipe.call(this, dest, options);
1094
- this.resume();
1095
- return dest;
1096
- };
1035
+ this._streams.push(stream);
1036
+ return this;
1037
+ };
1097
1038
 
1098
- CombinedStream$1.prototype._getNext = function() {
1099
- this._currentStream = null;
1100
-
1101
- if (this._insideLoop) {
1102
- this._pendingNext = true;
1103
- return; // defer call
1104
- }
1105
-
1106
- this._insideLoop = true;
1107
- try {
1108
- do {
1109
- this._pendingNext = false;
1110
- this._realGetNext();
1111
- } while (this._pendingNext);
1112
- } finally {
1113
- this._insideLoop = false;
1114
- }
1115
- };
1039
+ CombinedStream.prototype.pipe = function(dest, options) {
1040
+ Stream.prototype.pipe.call(this, dest, options);
1041
+ this.resume();
1042
+ return dest;
1043
+ };
1116
1044
 
1117
- CombinedStream$1.prototype._realGetNext = function() {
1118
- var stream = this._streams.shift();
1045
+ CombinedStream.prototype._getNext = function() {
1046
+ this._currentStream = null;
1119
1047
 
1048
+ if (this._insideLoop) {
1049
+ this._pendingNext = true;
1050
+ return; // defer call
1051
+ }
1120
1052
 
1121
- if (typeof stream == 'undefined') {
1122
- this.end();
1123
- return;
1124
- }
1053
+ this._insideLoop = true;
1054
+ try {
1055
+ do {
1056
+ this._pendingNext = false;
1057
+ this._realGetNext();
1058
+ } while (this._pendingNext);
1059
+ } finally {
1060
+ this._insideLoop = false;
1061
+ }
1062
+ };
1125
1063
 
1126
- if (typeof stream !== 'function') {
1127
- this._pipeNext(stream);
1128
- return;
1129
- }
1130
-
1131
- var getStream = stream;
1132
- getStream(function(stream) {
1133
- var isStreamLike = CombinedStream$1.isStreamLike(stream);
1134
- if (isStreamLike) {
1135
- stream.on('data', this._checkDataSize.bind(this));
1136
- this._handleErrors(stream);
1137
- }
1064
+ CombinedStream.prototype._realGetNext = function() {
1065
+ var stream = this._streams.shift();
1138
1066
 
1139
- this._pipeNext(stream);
1140
- }.bind(this));
1141
- };
1142
1067
 
1143
- CombinedStream$1.prototype._pipeNext = function(stream) {
1144
- this._currentStream = stream;
1068
+ if (typeof stream == 'undefined') {
1069
+ this.end();
1070
+ return;
1071
+ }
1145
1072
 
1146
- var isStreamLike = CombinedStream$1.isStreamLike(stream);
1147
- if (isStreamLike) {
1148
- stream.on('end', this._getNext.bind(this));
1149
- stream.pipe(this, {end: false});
1150
- return;
1151
- }
1073
+ if (typeof stream !== 'function') {
1074
+ this._pipeNext(stream);
1075
+ return;
1076
+ }
1152
1077
 
1153
- var value = stream;
1154
- this.write(value);
1155
- this._getNext();
1156
- };
1078
+ var getStream = stream;
1079
+ getStream(function(stream) {
1080
+ var isStreamLike = CombinedStream.isStreamLike(stream);
1081
+ if (isStreamLike) {
1082
+ stream.on('data', this._checkDataSize.bind(this));
1083
+ this._handleErrors(stream);
1084
+ }
1157
1085
 
1158
- CombinedStream$1.prototype._handleErrors = function(stream) {
1159
- var self = this;
1160
- stream.on('error', function(err) {
1161
- self._emitError(err);
1162
- });
1163
- };
1086
+ this._pipeNext(stream);
1087
+ }.bind(this));
1088
+ };
1164
1089
 
1165
- CombinedStream$1.prototype.write = function(data) {
1166
- this.emit('data', data);
1167
- };
1090
+ CombinedStream.prototype._pipeNext = function(stream) {
1091
+ this._currentStream = stream;
1168
1092
 
1169
- CombinedStream$1.prototype.pause = function() {
1170
- if (!this.pauseStreams) {
1171
- return;
1172
- }
1093
+ var isStreamLike = CombinedStream.isStreamLike(stream);
1094
+ if (isStreamLike) {
1095
+ stream.on('end', this._getNext.bind(this));
1096
+ stream.pipe(this, {end: false});
1097
+ return;
1098
+ }
1173
1099
 
1174
- if(this.pauseStreams && this._currentStream && typeof(this._currentStream.pause) == 'function') this._currentStream.pause();
1175
- this.emit('pause');
1176
- };
1100
+ var value = stream;
1101
+ this.write(value);
1102
+ this._getNext();
1103
+ };
1177
1104
 
1178
- CombinedStream$1.prototype.resume = function() {
1179
- if (!this._released) {
1180
- this._released = true;
1181
- this.writable = true;
1182
- this._getNext();
1183
- }
1105
+ CombinedStream.prototype._handleErrors = function(stream) {
1106
+ var self = this;
1107
+ stream.on('error', function(err) {
1108
+ self._emitError(err);
1109
+ });
1110
+ };
1184
1111
 
1185
- if(this.pauseStreams && this._currentStream && typeof(this._currentStream.resume) == 'function') this._currentStream.resume();
1186
- this.emit('resume');
1187
- };
1112
+ CombinedStream.prototype.write = function(data) {
1113
+ this.emit('data', data);
1114
+ };
1188
1115
 
1189
- CombinedStream$1.prototype.end = function() {
1190
- this._reset();
1191
- this.emit('end');
1192
- };
1116
+ CombinedStream.prototype.pause = function() {
1117
+ if (!this.pauseStreams) {
1118
+ return;
1119
+ }
1193
1120
 
1194
- CombinedStream$1.prototype.destroy = function() {
1195
- this._reset();
1196
- this.emit('close');
1197
- };
1121
+ if(this.pauseStreams && this._currentStream && typeof(this._currentStream.pause) == 'function') this._currentStream.pause();
1122
+ this.emit('pause');
1123
+ };
1198
1124
 
1199
- CombinedStream$1.prototype._reset = function() {
1200
- this.writable = false;
1201
- this._streams = [];
1202
- this._currentStream = null;
1203
- };
1125
+ CombinedStream.prototype.resume = function() {
1126
+ if (!this._released) {
1127
+ this._released = true;
1128
+ this.writable = true;
1129
+ this._getNext();
1130
+ }
1204
1131
 
1205
- CombinedStream$1.prototype._checkDataSize = function() {
1206
- this._updateDataSize();
1207
- if (this.dataSize <= this.maxDataSize) {
1208
- return;
1209
- }
1132
+ if(this.pauseStreams && this._currentStream && typeof(this._currentStream.resume) == 'function') this._currentStream.resume();
1133
+ this.emit('resume');
1134
+ };
1135
+
1136
+ CombinedStream.prototype.end = function() {
1137
+ this._reset();
1138
+ this.emit('end');
1139
+ };
1140
+
1141
+ CombinedStream.prototype.destroy = function() {
1142
+ this._reset();
1143
+ this.emit('close');
1144
+ };
1145
+
1146
+ CombinedStream.prototype._reset = function() {
1147
+ this.writable = false;
1148
+ this._streams = [];
1149
+ this._currentStream = null;
1150
+ };
1151
+
1152
+ CombinedStream.prototype._checkDataSize = function() {
1153
+ this._updateDataSize();
1154
+ if (this.dataSize <= this.maxDataSize) {
1155
+ return;
1156
+ }
1210
1157
 
1211
- var message =
1212
- 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
1213
- this._emitError(new Error(message));
1214
- };
1158
+ var message =
1159
+ 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
1160
+ this._emitError(new Error(message));
1161
+ };
1215
1162
 
1216
- CombinedStream$1.prototype._updateDataSize = function() {
1217
- this.dataSize = 0;
1163
+ CombinedStream.prototype._updateDataSize = function() {
1164
+ this.dataSize = 0;
1218
1165
 
1219
- var self = this;
1220
- this._streams.forEach(function(stream) {
1221
- if (!stream.dataSize) {
1222
- return;
1223
- }
1166
+ var self = this;
1167
+ this._streams.forEach(function(stream) {
1168
+ if (!stream.dataSize) {
1169
+ return;
1170
+ }
1224
1171
 
1225
- self.dataSize += stream.dataSize;
1226
- });
1172
+ self.dataSize += stream.dataSize;
1173
+ });
1227
1174
 
1228
- if (this._currentStream && this._currentStream.dataSize) {
1229
- this.dataSize += this._currentStream.dataSize;
1230
- }
1231
- };
1175
+ if (this._currentStream && this._currentStream.dataSize) {
1176
+ this.dataSize += this._currentStream.dataSize;
1177
+ }
1178
+ };
1232
1179
 
1233
- CombinedStream$1.prototype._emitError = function(err) {
1234
- this._reset();
1235
- this.emit('error', err);
1236
- };
1180
+ CombinedStream.prototype._emitError = function(err) {
1181
+ this._reset();
1182
+ this.emit('error', err);
1183
+ };
1184
+ return combined_stream;
1185
+ }
1237
1186
 
1238
1187
  var mimeTypes = {};
1239
1188
 
@@ -11947,11 +11896,19 @@ var require$$0 = {
11947
11896
  * MIT Licensed
11948
11897
  */
11949
11898
 
11950
- /**
11951
- * Module exports.
11952
- */
11899
+ var mimeDb;
11900
+ var hasRequiredMimeDb;
11953
11901
 
11954
- var mimeDb = require$$0;
11902
+ function requireMimeDb () {
11903
+ if (hasRequiredMimeDb) return mimeDb;
11904
+ hasRequiredMimeDb = 1;
11905
+ /**
11906
+ * Module exports.
11907
+ */
11908
+
11909
+ mimeDb = require$$0;
11910
+ return mimeDb;
11911
+ }
11955
11912
 
11956
11913
  /*!
11957
11914
  * mime-types
@@ -11960,1088 +11917,1189 @@ var mimeDb = require$$0;
11960
11917
  * MIT Licensed
11961
11918
  */
11962
11919
 
11963
- (function (exports) {
11920
+ var hasRequiredMimeTypes;
11921
+
11922
+ function requireMimeTypes () {
11923
+ if (hasRequiredMimeTypes) return mimeTypes;
11924
+ hasRequiredMimeTypes = 1;
11925
+ (function (exports) {
11926
+
11927
+ /**
11928
+ * Module dependencies.
11929
+ * @private
11930
+ */
11931
+
11932
+ var db = requireMimeDb();
11933
+ var extname = require$$1$1.extname;
11934
+
11935
+ /**
11936
+ * Module variables.
11937
+ * @private
11938
+ */
11939
+
11940
+ var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
11941
+ var TEXT_TYPE_REGEXP = /^text\//i;
11942
+
11943
+ /**
11944
+ * Module exports.
11945
+ * @public
11946
+ */
11947
+
11948
+ exports.charset = charset;
11949
+ exports.charsets = { lookup: charset };
11950
+ exports.contentType = contentType;
11951
+ exports.extension = extension;
11952
+ exports.extensions = Object.create(null);
11953
+ exports.lookup = lookup;
11954
+ exports.types = Object.create(null);
11955
+
11956
+ // Populate the extensions/types maps
11957
+ populateMaps(exports.extensions, exports.types);
11958
+
11959
+ /**
11960
+ * Get the default charset for a MIME type.
11961
+ *
11962
+ * @param {string} type
11963
+ * @return {boolean|string}
11964
+ */
11965
+
11966
+ function charset (type) {
11967
+ if (!type || typeof type !== 'string') {
11968
+ return false
11969
+ }
11970
+
11971
+ // TODO: use media-typer
11972
+ var match = EXTRACT_TYPE_REGEXP.exec(type);
11973
+ var mime = match && db[match[1].toLowerCase()];
11974
+
11975
+ if (mime && mime.charset) {
11976
+ return mime.charset
11977
+ }
11978
+
11979
+ // default text/* to utf-8
11980
+ if (match && TEXT_TYPE_REGEXP.test(match[1])) {
11981
+ return 'UTF-8'
11982
+ }
11983
+
11984
+ return false
11985
+ }
11986
+
11987
+ /**
11988
+ * Create a full Content-Type header given a MIME type or extension.
11989
+ *
11990
+ * @param {string} str
11991
+ * @return {boolean|string}
11992
+ */
11993
+
11994
+ function contentType (str) {
11995
+ // TODO: should this even be in this module?
11996
+ if (!str || typeof str !== 'string') {
11997
+ return false
11998
+ }
11999
+
12000
+ var mime = str.indexOf('/') === -1
12001
+ ? exports.lookup(str)
12002
+ : str;
12003
+
12004
+ if (!mime) {
12005
+ return false
12006
+ }
12007
+
12008
+ // TODO: use content-type or other module
12009
+ if (mime.indexOf('charset') === -1) {
12010
+ var charset = exports.charset(mime);
12011
+ if (charset) mime += '; charset=' + charset.toLowerCase();
12012
+ }
12013
+
12014
+ return mime
12015
+ }
12016
+
12017
+ /**
12018
+ * Get the default extension for a MIME type.
12019
+ *
12020
+ * @param {string} type
12021
+ * @return {boolean|string}
12022
+ */
12023
+
12024
+ function extension (type) {
12025
+ if (!type || typeof type !== 'string') {
12026
+ return false
12027
+ }
12028
+
12029
+ // TODO: use media-typer
12030
+ var match = EXTRACT_TYPE_REGEXP.exec(type);
12031
+
12032
+ // get extensions
12033
+ var exts = match && exports.extensions[match[1].toLowerCase()];
12034
+
12035
+ if (!exts || !exts.length) {
12036
+ return false
12037
+ }
12038
+
12039
+ return exts[0]
12040
+ }
12041
+
12042
+ /**
12043
+ * Lookup the MIME type for a file path/extension.
12044
+ *
12045
+ * @param {string} path
12046
+ * @return {boolean|string}
12047
+ */
12048
+
12049
+ function lookup (path) {
12050
+ if (!path || typeof path !== 'string') {
12051
+ return false
12052
+ }
12053
+
12054
+ // get the extension ("ext" or ".ext" or full path)
12055
+ var extension = extname('x.' + path)
12056
+ .toLowerCase()
12057
+ .substr(1);
12058
+
12059
+ if (!extension) {
12060
+ return false
12061
+ }
12062
+
12063
+ return exports.types[extension] || false
12064
+ }
12065
+
12066
+ /**
12067
+ * Populate the extensions and types maps.
12068
+ * @private
12069
+ */
12070
+
12071
+ function populateMaps (extensions, types) {
12072
+ // source preference (least -> most)
12073
+ var preference = ['nginx', 'apache', undefined, 'iana'];
12074
+
12075
+ Object.keys(db).forEach(function forEachMimeType (type) {
12076
+ var mime = db[type];
12077
+ var exts = mime.extensions;
12078
+
12079
+ if (!exts || !exts.length) {
12080
+ return
12081
+ }
12082
+
12083
+ // mime -> extensions
12084
+ extensions[type] = exts;
12085
+
12086
+ // extension -> mime
12087
+ for (var i = 0; i < exts.length; i++) {
12088
+ var extension = exts[i];
12089
+
12090
+ if (types[extension]) {
12091
+ var from = preference.indexOf(db[types[extension]].source);
12092
+ var to = preference.indexOf(mime.source);
12093
+
12094
+ if (types[extension] !== 'application/octet-stream' &&
12095
+ (from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) {
12096
+ // skip the remapping
12097
+ continue
12098
+ }
12099
+ }
12100
+
12101
+ // set the extension -> mime
12102
+ types[extension] = type;
12103
+ }
12104
+ });
12105
+ }
12106
+ } (mimeTypes));
12107
+ return mimeTypes;
12108
+ }
11964
12109
 
11965
- /**
11966
- * Module dependencies.
11967
- * @private
11968
- */
12110
+ var defer_1;
12111
+ var hasRequiredDefer;
11969
12112
 
11970
- var db = mimeDb;
11971
- var extname = require$$1$1.extname;
12113
+ function requireDefer () {
12114
+ if (hasRequiredDefer) return defer_1;
12115
+ hasRequiredDefer = 1;
12116
+ defer_1 = defer;
11972
12117
 
11973
12118
  /**
11974
- * Module variables.
11975
- * @private
12119
+ * Runs provided function on next iteration of the event loop
12120
+ *
12121
+ * @param {function} fn - function to run
11976
12122
  */
12123
+ function defer(fn)
12124
+ {
12125
+ var nextTick = typeof setImmediate == 'function'
12126
+ ? setImmediate
12127
+ : (
12128
+ typeof process == 'object' && typeof process.nextTick == 'function'
12129
+ ? process.nextTick
12130
+ : null
12131
+ );
12132
+
12133
+ if (nextTick)
12134
+ {
12135
+ nextTick(fn);
12136
+ }
12137
+ else
12138
+ {
12139
+ setTimeout(fn, 0);
12140
+ }
12141
+ }
12142
+ return defer_1;
12143
+ }
11977
12144
 
11978
- var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
11979
- var TEXT_TYPE_REGEXP = /^text\//i;
11980
-
11981
- /**
11982
- * Module exports.
11983
- * @public
11984
- */
12145
+ var async_1;
12146
+ var hasRequiredAsync;
11985
12147
 
11986
- exports.charset = charset;
11987
- exports.charsets = { lookup: charset };
11988
- exports.contentType = contentType;
11989
- exports.extension = extension;
11990
- exports.extensions = Object.create(null);
11991
- exports.lookup = lookup;
11992
- exports.types = Object.create(null);
12148
+ function requireAsync () {
12149
+ if (hasRequiredAsync) return async_1;
12150
+ hasRequiredAsync = 1;
12151
+ var defer = requireDefer();
11993
12152
 
11994
- // Populate the extensions/types maps
11995
- populateMaps(exports.extensions, exports.types);
12153
+ // API
12154
+ async_1 = async;
11996
12155
 
11997
12156
  /**
11998
- * Get the default charset for a MIME type.
12157
+ * Runs provided callback asynchronously
12158
+ * even if callback itself is not
11999
12159
  *
12000
- * @param {string} type
12001
- * @return {boolean|string}
12160
+ * @param {function} callback - callback to invoke
12161
+ * @returns {function} - augmented callback
12002
12162
  */
12163
+ function async(callback)
12164
+ {
12165
+ var isAsync = false;
12166
+
12167
+ // check if async happened
12168
+ defer(function() { isAsync = true; });
12169
+
12170
+ return function async_callback(err, result)
12171
+ {
12172
+ if (isAsync)
12173
+ {
12174
+ callback(err, result);
12175
+ }
12176
+ else
12177
+ {
12178
+ defer(function nextTick_callback()
12179
+ {
12180
+ callback(err, result);
12181
+ });
12182
+ }
12183
+ };
12184
+ }
12185
+ return async_1;
12186
+ }
12003
12187
 
12004
- function charset (type) {
12005
- if (!type || typeof type !== 'string') {
12006
- return false
12007
- }
12008
-
12009
- // TODO: use media-typer
12010
- var match = EXTRACT_TYPE_REGEXP.exec(type);
12011
- var mime = match && db[match[1].toLowerCase()];
12188
+ var abort_1;
12189
+ var hasRequiredAbort;
12012
12190
 
12013
- if (mime && mime.charset) {
12014
- return mime.charset
12015
- }
12191
+ function requireAbort () {
12192
+ if (hasRequiredAbort) return abort_1;
12193
+ hasRequiredAbort = 1;
12194
+ // API
12195
+ abort_1 = abort;
12016
12196
 
12017
- // default text/* to utf-8
12018
- if (match && TEXT_TYPE_REGEXP.test(match[1])) {
12019
- return 'UTF-8'
12020
- }
12197
+ /**
12198
+ * Aborts leftover active jobs
12199
+ *
12200
+ * @param {object} state - current state object
12201
+ */
12202
+ function abort(state)
12203
+ {
12204
+ Object.keys(state.jobs).forEach(clean.bind(state));
12021
12205
 
12022
- return false
12206
+ // reset leftover jobs
12207
+ state.jobs = {};
12023
12208
  }
12024
12209
 
12025
12210
  /**
12026
- * Create a full Content-Type header given a MIME type or extension.
12211
+ * Cleans up leftover job by invoking abort function for the provided job id
12027
12212
  *
12028
- * @param {string} str
12029
- * @return {boolean|string}
12213
+ * @this state
12214
+ * @param {string|number} key - job id to abort
12030
12215
  */
12031
-
12032
- function contentType (str) {
12033
- // TODO: should this even be in this module?
12034
- if (!str || typeof str !== 'string') {
12035
- return false
12216
+ function clean(key)
12217
+ {
12218
+ if (typeof this.jobs[key] == 'function')
12219
+ {
12220
+ this.jobs[key]();
12036
12221
  }
12222
+ }
12223
+ return abort_1;
12224
+ }
12037
12225
 
12038
- var mime = str.indexOf('/') === -1
12039
- ? exports.lookup(str)
12040
- : str;
12226
+ var iterate_1;
12227
+ var hasRequiredIterate;
12041
12228
 
12042
- if (!mime) {
12043
- return false
12044
- }
12229
+ function requireIterate () {
12230
+ if (hasRequiredIterate) return iterate_1;
12231
+ hasRequiredIterate = 1;
12232
+ var async = requireAsync()
12233
+ , abort = requireAbort()
12234
+ ;
12045
12235
 
12046
- // TODO: use content-type or other module
12047
- if (mime.indexOf('charset') === -1) {
12048
- var charset = exports.charset(mime);
12049
- if (charset) mime += '; charset=' + charset.toLowerCase();
12050
- }
12051
-
12052
- return mime
12053
- }
12236
+ // API
12237
+ iterate_1 = iterate;
12054
12238
 
12055
12239
  /**
12056
- * Get the default extension for a MIME type.
12240
+ * Iterates over each job object
12057
12241
  *
12058
- * @param {string} type
12059
- * @return {boolean|string}
12242
+ * @param {array|object} list - array or object (named list) to iterate over
12243
+ * @param {function} iterator - iterator to run
12244
+ * @param {object} state - current job status
12245
+ * @param {function} callback - invoked when all elements processed
12060
12246
  */
12247
+ function iterate(list, iterator, state, callback)
12248
+ {
12249
+ // store current index
12250
+ var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
12251
+
12252
+ state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
12253
+ {
12254
+ // don't repeat yourself
12255
+ // skip secondary callbacks
12256
+ if (!(key in state.jobs))
12257
+ {
12258
+ return;
12259
+ }
12061
12260
 
12062
- function extension (type) {
12063
- if (!type || typeof type !== 'string') {
12064
- return false
12065
- }
12066
-
12067
- // TODO: use media-typer
12068
- var match = EXTRACT_TYPE_REGEXP.exec(type);
12069
-
12070
- // get extensions
12071
- var exts = match && exports.extensions[match[1].toLowerCase()];
12261
+ // clean up jobs
12262
+ delete state.jobs[key];
12072
12263
 
12073
- if (!exts || !exts.length) {
12074
- return false
12075
- }
12264
+ if (error)
12265
+ {
12266
+ // don't process rest of the results
12267
+ // stop still active jobs
12268
+ // and reset the list
12269
+ abort(state);
12270
+ }
12271
+ else
12272
+ {
12273
+ state.results[key] = output;
12274
+ }
12076
12275
 
12077
- return exts[0]
12276
+ // return salvaged results
12277
+ callback(error, state.results);
12278
+ });
12078
12279
  }
12079
12280
 
12080
12281
  /**
12081
- * Lookup the MIME type for a file path/extension.
12282
+ * Runs iterator over provided job element
12082
12283
  *
12083
- * @param {string} path
12084
- * @return {boolean|string}
12284
+ * @param {function} iterator - iterator to invoke
12285
+ * @param {string|number} key - key/index of the element in the list of jobs
12286
+ * @param {mixed} item - job description
12287
+ * @param {function} callback - invoked after iterator is done with the job
12288
+ * @returns {function|mixed} - job abort function or something else
12085
12289
  */
12086
-
12087
- function lookup (path) {
12088
- if (!path || typeof path !== 'string') {
12089
- return false
12290
+ function runJob(iterator, key, item, callback)
12291
+ {
12292
+ var aborter;
12293
+
12294
+ // allow shortcut if iterator expects only two arguments
12295
+ if (iterator.length == 2)
12296
+ {
12297
+ aborter = iterator(item, async(callback));
12090
12298
  }
12091
-
12092
- // get the extension ("ext" or ".ext" or full path)
12093
- var extension = extname('x.' + path)
12094
- .toLowerCase()
12095
- .substr(1);
12096
-
12097
- if (!extension) {
12098
- return false
12299
+ // otherwise go with full three arguments
12300
+ else
12301
+ {
12302
+ aborter = iterator(item, key, async(callback));
12099
12303
  }
12100
12304
 
12101
- return exports.types[extension] || false
12305
+ return aborter;
12102
12306
  }
12307
+ return iterate_1;
12308
+ }
12103
12309
 
12104
- /**
12105
- * Populate the extensions and types maps.
12106
- * @private
12107
- */
12108
-
12109
- function populateMaps (extensions, types) {
12110
- // source preference (least -> most)
12111
- var preference = ['nginx', 'apache', undefined, 'iana'];
12310
+ var state_1;
12311
+ var hasRequiredState;
12112
12312
 
12113
- Object.keys(db).forEach(function forEachMimeType (type) {
12114
- var mime = db[type];
12115
- var exts = mime.extensions;
12313
+ function requireState () {
12314
+ if (hasRequiredState) return state_1;
12315
+ hasRequiredState = 1;
12316
+ // API
12317
+ state_1 = state;
12116
12318
 
12117
- if (!exts || !exts.length) {
12118
- return
12319
+ /**
12320
+ * Creates initial state object
12321
+ * for iteration over list
12322
+ *
12323
+ * @param {array|object} list - list to iterate over
12324
+ * @param {function|null} sortMethod - function to use for keys sort,
12325
+ * or `null` to keep them as is
12326
+ * @returns {object} - initial state object
12327
+ */
12328
+ function state(list, sortMethod)
12329
+ {
12330
+ var isNamedList = !Array.isArray(list)
12331
+ , initState =
12332
+ {
12333
+ index : 0,
12334
+ keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
12335
+ jobs : {},
12336
+ results : isNamedList ? {} : [],
12337
+ size : isNamedList ? Object.keys(list).length : list.length
12119
12338
  }
12339
+ ;
12340
+
12341
+ if (sortMethod)
12342
+ {
12343
+ // sort array keys based on it's values
12344
+ // sort object's keys just on own merit
12345
+ initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
12346
+ {
12347
+ return sortMethod(list[a], list[b]);
12348
+ });
12349
+ }
12120
12350
 
12121
- // mime -> extensions
12122
- extensions[type] = exts;
12123
-
12124
- // extension -> mime
12125
- for (var i = 0; i < exts.length; i++) {
12126
- var extension = exts[i];
12351
+ return initState;
12352
+ }
12353
+ return state_1;
12354
+ }
12127
12355
 
12128
- if (types[extension]) {
12129
- var from = preference.indexOf(db[types[extension]].source);
12130
- var to = preference.indexOf(mime.source);
12356
+ var terminator_1;
12357
+ var hasRequiredTerminator;
12131
12358
 
12132
- if (types[extension] !== 'application/octet-stream' &&
12133
- (from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) {
12134
- // skip the remapping
12135
- continue
12136
- }
12137
- }
12359
+ function requireTerminator () {
12360
+ if (hasRequiredTerminator) return terminator_1;
12361
+ hasRequiredTerminator = 1;
12362
+ var abort = requireAbort()
12363
+ , async = requireAsync()
12364
+ ;
12138
12365
 
12139
- // set the extension -> mime
12140
- types[extension] = type;
12141
- }
12142
- });
12143
- }
12144
- } (mimeTypes));
12145
-
12146
- var defer_1 = defer$1;
12366
+ // API
12367
+ terminator_1 = terminator;
12147
12368
 
12148
- /**
12149
- * Runs provided function on next iteration of the event loop
12150
- *
12151
- * @param {function} fn - function to run
12152
- */
12153
- function defer$1(fn)
12154
- {
12155
- var nextTick = typeof setImmediate == 'function'
12156
- ? setImmediate
12157
- : (
12158
- typeof process == 'object' && typeof process.nextTick == 'function'
12159
- ? process.nextTick
12160
- : null
12161
- );
12162
-
12163
- if (nextTick)
12164
- {
12165
- nextTick(fn);
12166
- }
12167
- else
12168
- {
12169
- setTimeout(fn, 0);
12170
- }
12171
- }
12369
+ /**
12370
+ * Terminates jobs in the attached state context
12371
+ *
12372
+ * @this AsyncKitState#
12373
+ * @param {function} callback - final callback to invoke after termination
12374
+ */
12375
+ function terminator(callback)
12376
+ {
12377
+ if (!Object.keys(this.jobs).length)
12378
+ {
12379
+ return;
12380
+ }
12172
12381
 
12173
- var defer = defer_1;
12382
+ // fast forward iteration index
12383
+ this.index = this.size;
12174
12384
 
12175
- // API
12176
- var async_1 = async$2;
12385
+ // abort jobs
12386
+ abort(this);
12177
12387
 
12178
- /**
12179
- * Runs provided callback asynchronously
12180
- * even if callback itself is not
12181
- *
12182
- * @param {function} callback - callback to invoke
12183
- * @returns {function} - augmented callback
12184
- */
12185
- function async$2(callback)
12186
- {
12187
- var isAsync = false;
12188
-
12189
- // check if async happened
12190
- defer(function() { isAsync = true; });
12191
-
12192
- return function async_callback(err, result)
12193
- {
12194
- if (isAsync)
12195
- {
12196
- callback(err, result);
12197
- }
12198
- else
12199
- {
12200
- defer(function nextTick_callback()
12201
- {
12202
- callback(err, result);
12203
- });
12204
- }
12205
- };
12388
+ // send back results we have so far
12389
+ async(callback)(null, this.results);
12390
+ }
12391
+ return terminator_1;
12206
12392
  }
12207
12393
 
12208
- // API
12209
- var abort_1 = abort$2;
12394
+ var parallel_1;
12395
+ var hasRequiredParallel;
12210
12396
 
12211
- /**
12212
- * Aborts leftover active jobs
12213
- *
12214
- * @param {object} state - current state object
12215
- */
12216
- function abort$2(state)
12217
- {
12218
- Object.keys(state.jobs).forEach(clean.bind(state));
12397
+ function requireParallel () {
12398
+ if (hasRequiredParallel) return parallel_1;
12399
+ hasRequiredParallel = 1;
12400
+ var iterate = requireIterate()
12401
+ , initState = requireState()
12402
+ , terminator = requireTerminator()
12403
+ ;
12219
12404
 
12220
- // reset leftover jobs
12221
- state.jobs = {};
12222
- }
12405
+ // Public API
12406
+ parallel_1 = parallel;
12223
12407
 
12224
- /**
12225
- * Cleans up leftover job by invoking abort function for the provided job id
12226
- *
12227
- * @this state
12228
- * @param {string|number} key - job id to abort
12229
- */
12230
- function clean(key)
12231
- {
12232
- if (typeof this.jobs[key] == 'function')
12233
- {
12234
- this.jobs[key]();
12235
- }
12236
- }
12408
+ /**
12409
+ * Runs iterator over provided array elements in parallel
12410
+ *
12411
+ * @param {array|object} list - array or object (named list) to iterate over
12412
+ * @param {function} iterator - iterator to run
12413
+ * @param {function} callback - invoked when all elements processed
12414
+ * @returns {function} - jobs terminator
12415
+ */
12416
+ function parallel(list, iterator, callback)
12417
+ {
12418
+ var state = initState(list);
12419
+
12420
+ while (state.index < (state['keyedList'] || list).length)
12421
+ {
12422
+ iterate(list, iterator, state, function(error, result)
12423
+ {
12424
+ if (error)
12425
+ {
12426
+ callback(error, result);
12427
+ return;
12428
+ }
12237
12429
 
12238
- var async$1 = async_1
12239
- , abort$1 = abort_1
12240
- ;
12430
+ // looks like it's the last one
12431
+ if (Object.keys(state.jobs).length === 0)
12432
+ {
12433
+ callback(null, state.results);
12434
+ return;
12435
+ }
12436
+ });
12241
12437
 
12242
- // API
12243
- var iterate_1 = iterate$2;
12438
+ state.index++;
12439
+ }
12244
12440
 
12245
- /**
12246
- * Iterates over each job object
12247
- *
12248
- * @param {array|object} list - array or object (named list) to iterate over
12249
- * @param {function} iterator - iterator to run
12250
- * @param {object} state - current job status
12251
- * @param {function} callback - invoked when all elements processed
12252
- */
12253
- function iterate$2(list, iterator, state, callback)
12254
- {
12255
- // store current index
12256
- var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
12257
-
12258
- state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
12259
- {
12260
- // don't repeat yourself
12261
- // skip secondary callbacks
12262
- if (!(key in state.jobs))
12263
- {
12264
- return;
12265
- }
12441
+ return terminator.bind(state, callback);
12442
+ }
12443
+ return parallel_1;
12444
+ }
12266
12445
 
12267
- // clean up jobs
12268
- delete state.jobs[key];
12446
+ var serialOrdered = {exports: {}};
12269
12447
 
12270
- if (error)
12271
- {
12272
- // don't process rest of the results
12273
- // stop still active jobs
12274
- // and reset the list
12275
- abort$1(state);
12276
- }
12277
- else
12278
- {
12279
- state.results[key] = output;
12280
- }
12448
+ var hasRequiredSerialOrdered;
12281
12449
 
12282
- // return salvaged results
12283
- callback(error, state.results);
12284
- });
12285
- }
12450
+ function requireSerialOrdered () {
12451
+ if (hasRequiredSerialOrdered) return serialOrdered.exports;
12452
+ hasRequiredSerialOrdered = 1;
12453
+ var iterate = requireIterate()
12454
+ , initState = requireState()
12455
+ , terminator = requireTerminator()
12456
+ ;
12286
12457
 
12287
- /**
12288
- * Runs iterator over provided job element
12289
- *
12290
- * @param {function} iterator - iterator to invoke
12291
- * @param {string|number} key - key/index of the element in the list of jobs
12292
- * @param {mixed} item - job description
12293
- * @param {function} callback - invoked after iterator is done with the job
12294
- * @returns {function|mixed} - job abort function or something else
12295
- */
12296
- function runJob(iterator, key, item, callback)
12297
- {
12298
- var aborter;
12299
-
12300
- // allow shortcut if iterator expects only two arguments
12301
- if (iterator.length == 2)
12302
- {
12303
- aborter = iterator(item, async$1(callback));
12304
- }
12305
- // otherwise go with full three arguments
12306
- else
12307
- {
12308
- aborter = iterator(item, key, async$1(callback));
12309
- }
12310
-
12311
- return aborter;
12312
- }
12458
+ // Public API
12459
+ serialOrdered.exports = serialOrdered$1;
12460
+ // sorting helpers
12461
+ serialOrdered.exports.ascending = ascending;
12462
+ serialOrdered.exports.descending = descending;
12313
12463
 
12314
- // API
12315
- var state_1 = state;
12316
-
12317
- /**
12318
- * Creates initial state object
12319
- * for iteration over list
12320
- *
12321
- * @param {array|object} list - list to iterate over
12322
- * @param {function|null} sortMethod - function to use for keys sort,
12323
- * or `null` to keep them as is
12324
- * @returns {object} - initial state object
12325
- */
12326
- function state(list, sortMethod)
12327
- {
12328
- var isNamedList = !Array.isArray(list)
12329
- , initState =
12330
- {
12331
- index : 0,
12332
- keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
12333
- jobs : {},
12334
- results : isNamedList ? {} : [],
12335
- size : isNamedList ? Object.keys(list).length : list.length
12336
- }
12337
- ;
12338
-
12339
- if (sortMethod)
12340
- {
12341
- // sort array keys based on it's values
12342
- // sort object's keys just on own merit
12343
- initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
12344
- {
12345
- return sortMethod(list[a], list[b]);
12346
- });
12347
- }
12464
+ /**
12465
+ * Runs iterator over provided sorted array elements in series
12466
+ *
12467
+ * @param {array|object} list - array or object (named list) to iterate over
12468
+ * @param {function} iterator - iterator to run
12469
+ * @param {function} sortMethod - custom sort function
12470
+ * @param {function} callback - invoked when all elements processed
12471
+ * @returns {function} - jobs terminator
12472
+ */
12473
+ function serialOrdered$1(list, iterator, sortMethod, callback)
12474
+ {
12475
+ var state = initState(list, sortMethod);
12476
+
12477
+ iterate(list, iterator, state, function iteratorHandler(error, result)
12478
+ {
12479
+ if (error)
12480
+ {
12481
+ callback(error, result);
12482
+ return;
12483
+ }
12348
12484
 
12349
- return initState;
12350
- }
12485
+ state.index++;
12351
12486
 
12352
- var abort = abort_1
12353
- , async = async_1
12354
- ;
12487
+ // are we there yet?
12488
+ if (state.index < (state['keyedList'] || list).length)
12489
+ {
12490
+ iterate(list, iterator, state, iteratorHandler);
12491
+ return;
12492
+ }
12355
12493
 
12356
- // API
12357
- var terminator_1 = terminator$2;
12494
+ // done here
12495
+ callback(null, state.results);
12496
+ });
12358
12497
 
12359
- /**
12360
- * Terminates jobs in the attached state context
12361
- *
12362
- * @this AsyncKitState#
12363
- * @param {function} callback - final callback to invoke after termination
12364
- */
12365
- function terminator$2(callback)
12366
- {
12367
- if (!Object.keys(this.jobs).length)
12368
- {
12369
- return;
12370
- }
12498
+ return terminator.bind(state, callback);
12499
+ }
12371
12500
 
12372
- // fast forward iteration index
12373
- this.index = this.size;
12501
+ /*
12502
+ * -- Sort methods
12503
+ */
12374
12504
 
12375
- // abort jobs
12376
- abort(this);
12505
+ /**
12506
+ * sort helper to sort array elements in ascending order
12507
+ *
12508
+ * @param {mixed} a - an item to compare
12509
+ * @param {mixed} b - an item to compare
12510
+ * @returns {number} - comparison result
12511
+ */
12512
+ function ascending(a, b)
12513
+ {
12514
+ return a < b ? -1 : a > b ? 1 : 0;
12515
+ }
12377
12516
 
12378
- // send back results we have so far
12379
- async(callback)(null, this.results);
12517
+ /**
12518
+ * sort helper to sort array elements in descending order
12519
+ *
12520
+ * @param {mixed} a - an item to compare
12521
+ * @param {mixed} b - an item to compare
12522
+ * @returns {number} - comparison result
12523
+ */
12524
+ function descending(a, b)
12525
+ {
12526
+ return -1 * ascending(a, b);
12527
+ }
12528
+ return serialOrdered.exports;
12380
12529
  }
12381
12530
 
12382
- var iterate$1 = iterate_1
12383
- , initState$1 = state_1
12384
- , terminator$1 = terminator_1
12385
- ;
12386
-
12387
- // Public API
12388
- var parallel_1 = parallel;
12389
-
12390
- /**
12391
- * Runs iterator over provided array elements in parallel
12392
- *
12393
- * @param {array|object} list - array or object (named list) to iterate over
12394
- * @param {function} iterator - iterator to run
12395
- * @param {function} callback - invoked when all elements processed
12396
- * @returns {function} - jobs terminator
12397
- */
12398
- function parallel(list, iterator, callback)
12399
- {
12400
- var state = initState$1(list);
12401
-
12402
- while (state.index < (state['keyedList'] || list).length)
12403
- {
12404
- iterate$1(list, iterator, state, function(error, result)
12405
- {
12406
- if (error)
12407
- {
12408
- callback(error, result);
12409
- return;
12410
- }
12531
+ var serial_1;
12532
+ var hasRequiredSerial;
12411
12533
 
12412
- // looks like it's the last one
12413
- if (Object.keys(state.jobs).length === 0)
12414
- {
12415
- callback(null, state.results);
12416
- return;
12417
- }
12418
- });
12534
+ function requireSerial () {
12535
+ if (hasRequiredSerial) return serial_1;
12536
+ hasRequiredSerial = 1;
12537
+ var serialOrdered = requireSerialOrdered();
12419
12538
 
12420
- state.index++;
12421
- }
12539
+ // Public API
12540
+ serial_1 = serial;
12422
12541
 
12423
- return terminator$1.bind(state, callback);
12542
+ /**
12543
+ * Runs iterator over provided array elements in series
12544
+ *
12545
+ * @param {array|object} list - array or object (named list) to iterate over
12546
+ * @param {function} iterator - iterator to run
12547
+ * @param {function} callback - invoked when all elements processed
12548
+ * @returns {function} - jobs terminator
12549
+ */
12550
+ function serial(list, iterator, callback)
12551
+ {
12552
+ return serialOrdered(list, iterator, null, callback);
12553
+ }
12554
+ return serial_1;
12424
12555
  }
12425
12556
 
12426
- var serialOrdered$2 = {exports: {}};
12427
-
12428
- var iterate = iterate_1
12429
- , initState = state_1
12430
- , terminator = terminator_1
12431
- ;
12432
-
12433
- // Public API
12434
- serialOrdered$2.exports = serialOrdered$1;
12435
- // sorting helpers
12436
- serialOrdered$2.exports.ascending = ascending;
12437
- serialOrdered$2.exports.descending = descending;
12438
-
12439
- /**
12440
- * Runs iterator over provided sorted array elements in series
12441
- *
12442
- * @param {array|object} list - array or object (named list) to iterate over
12443
- * @param {function} iterator - iterator to run
12444
- * @param {function} sortMethod - custom sort function
12445
- * @param {function} callback - invoked when all elements processed
12446
- * @returns {function} - jobs terminator
12447
- */
12448
- function serialOrdered$1(list, iterator, sortMethod, callback)
12449
- {
12450
- var state = initState(list, sortMethod);
12451
-
12452
- iterate(list, iterator, state, function iteratorHandler(error, result)
12453
- {
12454
- if (error)
12455
- {
12456
- callback(error, result);
12457
- return;
12458
- }
12557
+ var asynckit;
12558
+ var hasRequiredAsynckit;
12559
+
12560
+ function requireAsynckit () {
12561
+ if (hasRequiredAsynckit) return asynckit;
12562
+ hasRequiredAsynckit = 1;
12563
+ asynckit =
12564
+ {
12565
+ parallel : requireParallel(),
12566
+ serial : requireSerial(),
12567
+ serialOrdered : requireSerialOrdered()
12568
+ };
12569
+ return asynckit;
12570
+ }
12459
12571
 
12460
- state.index++;
12572
+ var populate;
12573
+ var hasRequiredPopulate;
12461
12574
 
12462
- // are we there yet?
12463
- if (state.index < (state['keyedList'] || list).length)
12464
- {
12465
- iterate(list, iterator, state, iteratorHandler);
12466
- return;
12467
- }
12575
+ function requirePopulate () {
12576
+ if (hasRequiredPopulate) return populate;
12577
+ hasRequiredPopulate = 1;
12578
+ // populates missing values
12579
+ populate = function(dst, src) {
12468
12580
 
12469
- // done here
12470
- callback(null, state.results);
12471
- });
12581
+ Object.keys(src).forEach(function(prop)
12582
+ {
12583
+ dst[prop] = dst[prop] || src[prop];
12584
+ });
12472
12585
 
12473
- return terminator.bind(state, callback);
12586
+ return dst;
12587
+ };
12588
+ return populate;
12474
12589
  }
12475
12590
 
12476
- /*
12477
- * -- Sort methods
12478
- */
12591
+ var form_data;
12592
+ var hasRequiredForm_data;
12593
+
12594
+ function requireForm_data () {
12595
+ if (hasRequiredForm_data) return form_data;
12596
+ hasRequiredForm_data = 1;
12597
+ var CombinedStream = requireCombined_stream();
12598
+ var util = require$$1;
12599
+ var path = require$$1$1;
12600
+ var http = require$$3;
12601
+ var https = require$$4;
12602
+ var parseUrl = require$$5.parse;
12603
+ var fs = require$$6;
12604
+ var Stream = require$$0$1.Stream;
12605
+ var mime = requireMimeTypes();
12606
+ var asynckit = requireAsynckit();
12607
+ var populate = requirePopulate();
12608
+
12609
+ // Public API
12610
+ form_data = FormData;
12611
+
12612
+ // make it a Stream
12613
+ util.inherits(FormData, CombinedStream);
12479
12614
 
12480
- /**
12481
- * sort helper to sort array elements in ascending order
12482
- *
12483
- * @param {mixed} a - an item to compare
12484
- * @param {mixed} b - an item to compare
12485
- * @returns {number} - comparison result
12486
- */
12487
- function ascending(a, b)
12488
- {
12489
- return a < b ? -1 : a > b ? 1 : 0;
12490
- }
12615
+ /**
12616
+ * Create readable "multipart/form-data" streams.
12617
+ * Can be used to submit forms
12618
+ * and file uploads to other web applications.
12619
+ *
12620
+ * @constructor
12621
+ * @param {Object} options - Properties to be added/overriden for FormData and CombinedStream
12622
+ */
12623
+ function FormData(options) {
12624
+ if (!(this instanceof FormData)) {
12625
+ return new FormData(options);
12626
+ }
12491
12627
 
12492
- /**
12493
- * sort helper to sort array elements in descending order
12494
- *
12495
- * @param {mixed} a - an item to compare
12496
- * @param {mixed} b - an item to compare
12497
- * @returns {number} - comparison result
12498
- */
12499
- function descending(a, b)
12500
- {
12501
- return -1 * ascending(a, b);
12502
- }
12628
+ this._overheadLength = 0;
12629
+ this._valueLength = 0;
12630
+ this._valuesToMeasure = [];
12503
12631
 
12504
- var serialOrderedExports = serialOrdered$2.exports;
12632
+ CombinedStream.call(this);
12505
12633
 
12506
- var serialOrdered = serialOrderedExports;
12634
+ options = options || {};
12635
+ for (var option in options) {
12636
+ this[option] = options[option];
12637
+ }
12638
+ }
12507
12639
 
12508
- // Public API
12509
- var serial_1 = serial;
12640
+ FormData.LINE_BREAK = '\r\n';
12641
+ FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
12510
12642
 
12511
- /**
12512
- * Runs iterator over provided array elements in series
12513
- *
12514
- * @param {array|object} list - array or object (named list) to iterate over
12515
- * @param {function} iterator - iterator to run
12516
- * @param {function} callback - invoked when all elements processed
12517
- * @returns {function} - jobs terminator
12518
- */
12519
- function serial(list, iterator, callback)
12520
- {
12521
- return serialOrdered(list, iterator, null, callback);
12522
- }
12643
+ FormData.prototype.append = function(field, value, options) {
12523
12644
 
12524
- var asynckit$1 =
12525
- {
12526
- parallel : parallel_1,
12527
- serial : serial_1,
12528
- serialOrdered : serialOrderedExports
12529
- };
12645
+ options = options || {};
12530
12646
 
12531
- // populates missing values
12532
- var populate$1 = function(dst, src) {
12647
+ // allow filename as single option
12648
+ if (typeof options == 'string') {
12649
+ options = {filename: options};
12650
+ }
12533
12651
 
12534
- Object.keys(src).forEach(function(prop)
12535
- {
12536
- dst[prop] = dst[prop] || src[prop];
12537
- });
12652
+ var append = CombinedStream.prototype.append.bind(this);
12538
12653
 
12539
- return dst;
12540
- };
12654
+ // all that streamy business can't handle numbers
12655
+ if (typeof value == 'number') {
12656
+ value = '' + value;
12657
+ }
12541
12658
 
12542
- var CombinedStream = combined_stream;
12543
- var util = require$$1;
12544
- var path = require$$1$1;
12545
- var http = require$$3;
12546
- var https = require$$4;
12547
- var parseUrl = require$$5.parse;
12548
- var fs = require$$6;
12549
- var Stream = require$$0$1.Stream;
12550
- var mime = mimeTypes;
12551
- var asynckit = asynckit$1;
12552
- var populate = populate$1;
12553
-
12554
- // Public API
12555
- var form_data = FormData;
12556
-
12557
- // make it a Stream
12558
- util.inherits(FormData, CombinedStream);
12559
-
12560
- /**
12561
- * Create readable "multipart/form-data" streams.
12562
- * Can be used to submit forms
12563
- * and file uploads to other web applications.
12564
- *
12565
- * @constructor
12566
- * @param {Object} options - Properties to be added/overriden for FormData and CombinedStream
12567
- */
12568
- function FormData(options) {
12569
- if (!(this instanceof FormData)) {
12570
- return new FormData(options);
12571
- }
12659
+ // https://github.com/felixge/node-form-data/issues/38
12660
+ if (Array.isArray(value)) {
12661
+ // Please convert your array into string
12662
+ // the way web server expects it
12663
+ this._error(new Error('Arrays are not supported.'));
12664
+ return;
12665
+ }
12572
12666
 
12573
- this._overheadLength = 0;
12574
- this._valueLength = 0;
12575
- this._valuesToMeasure = [];
12667
+ var header = this._multiPartHeader(field, value, options);
12668
+ var footer = this._multiPartFooter();
12669
+
12670
+ append(header);
12671
+ append(value);
12672
+ append(footer);
12673
+
12674
+ // pass along options.knownLength
12675
+ this._trackLength(header, value, options);
12676
+ };
12677
+
12678
+ FormData.prototype._trackLength = function(header, value, options) {
12679
+ var valueLength = 0;
12680
+
12681
+ // used w/ getLengthSync(), when length is known.
12682
+ // e.g. for streaming directly from a remote server,
12683
+ // w/ a known file a size, and not wanting to wait for
12684
+ // incoming file to finish to get its size.
12685
+ if (options.knownLength != null) {
12686
+ valueLength += +options.knownLength;
12687
+ } else if (Buffer.isBuffer(value)) {
12688
+ valueLength = value.length;
12689
+ } else if (typeof value === 'string') {
12690
+ valueLength = Buffer.byteLength(value);
12691
+ }
12576
12692
 
12577
- CombinedStream.call(this);
12693
+ this._valueLength += valueLength;
12578
12694
 
12579
- options = options || {};
12580
- for (var option in options) {
12581
- this[option] = options[option];
12582
- }
12583
- }
12695
+ // @check why add CRLF? does this account for custom/multiple CRLFs?
12696
+ this._overheadLength +=
12697
+ Buffer.byteLength(header) +
12698
+ FormData.LINE_BREAK.length;
12584
12699
 
12585
- FormData.LINE_BREAK = '\r\n';
12586
- FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
12700
+ // empty or either doesn't have path or not an http response or not a stream
12701
+ if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) && !(value instanceof Stream))) {
12702
+ return;
12703
+ }
12587
12704
 
12588
- FormData.prototype.append = function(field, value, options) {
12705
+ // no need to bother with the length
12706
+ if (!options.knownLength) {
12707
+ this._valuesToMeasure.push(value);
12708
+ }
12709
+ };
12589
12710
 
12590
- options = options || {};
12711
+ FormData.prototype._lengthRetriever = function(value, callback) {
12591
12712
 
12592
- // allow filename as single option
12593
- if (typeof options == 'string') {
12594
- options = {filename: options};
12595
- }
12713
+ if (value.hasOwnProperty('fd')) {
12596
12714
 
12597
- var append = CombinedStream.prototype.append.bind(this);
12715
+ // take read range into a account
12716
+ // `end` = Infinity –> read file till the end
12717
+ //
12718
+ // TODO: Looks like there is bug in Node fs.createReadStream
12719
+ // it doesn't respect `end` options without `start` options
12720
+ // Fix it when node fixes it.
12721
+ // https://github.com/joyent/node/issues/7819
12722
+ if (value.end != undefined && value.end != Infinity && value.start != undefined) {
12598
12723
 
12599
- // all that streamy business can't handle numbers
12600
- if (typeof value == 'number') {
12601
- value = '' + value;
12602
- }
12724
+ // when end specified
12725
+ // no need to calculate range
12726
+ // inclusive, starts with 0
12727
+ callback(null, value.end + 1 - (value.start ? value.start : 0));
12603
12728
 
12604
- // https://github.com/felixge/node-form-data/issues/38
12605
- if (util.isArray(value)) {
12606
- // Please convert your array into string
12607
- // the way web server expects it
12608
- this._error(new Error('Arrays are not supported.'));
12609
- return;
12610
- }
12729
+ // not that fast snoopy
12730
+ } else {
12731
+ // still need to fetch file size from fs
12732
+ fs.stat(value.path, function(err, stat) {
12611
12733
 
12612
- var header = this._multiPartHeader(field, value, options);
12613
- var footer = this._multiPartFooter();
12734
+ var fileSize;
12614
12735
 
12615
- append(header);
12616
- append(value);
12617
- append(footer);
12736
+ if (err) {
12737
+ callback(err);
12738
+ return;
12739
+ }
12618
12740
 
12619
- // pass along options.knownLength
12620
- this._trackLength(header, value, options);
12621
- };
12741
+ // update final size based on the range options
12742
+ fileSize = stat.size - (value.start ? value.start : 0);
12743
+ callback(null, fileSize);
12744
+ });
12745
+ }
12622
12746
 
12623
- FormData.prototype._trackLength = function(header, value, options) {
12624
- var valueLength = 0;
12625
-
12626
- // used w/ getLengthSync(), when length is known.
12627
- // e.g. for streaming directly from a remote server,
12628
- // w/ a known file a size, and not wanting to wait for
12629
- // incoming file to finish to get its size.
12630
- if (options.knownLength != null) {
12631
- valueLength += +options.knownLength;
12632
- } else if (Buffer.isBuffer(value)) {
12633
- valueLength = value.length;
12634
- } else if (typeof value === 'string') {
12635
- valueLength = Buffer.byteLength(value);
12636
- }
12637
-
12638
- this._valueLength += valueLength;
12639
-
12640
- // @check why add CRLF? does this account for custom/multiple CRLFs?
12641
- this._overheadLength +=
12642
- Buffer.byteLength(header) +
12643
- FormData.LINE_BREAK.length;
12644
-
12645
- // empty or either doesn't have path or not an http response or not a stream
12646
- if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) && !(value instanceof Stream))) {
12647
- return;
12648
- }
12747
+ // or http response
12748
+ } else if (value.hasOwnProperty('httpVersion')) {
12749
+ callback(null, +value.headers['content-length']);
12750
+
12751
+ // or request stream http://github.com/mikeal/request
12752
+ } else if (value.hasOwnProperty('httpModule')) {
12753
+ // wait till response come back
12754
+ value.on('response', function(response) {
12755
+ value.pause();
12756
+ callback(null, +response.headers['content-length']);
12757
+ });
12758
+ value.resume();
12759
+
12760
+ // something else
12761
+ } else {
12762
+ callback('Unknown stream');
12763
+ }
12764
+ };
12765
+
12766
+ FormData.prototype._multiPartHeader = function(field, value, options) {
12767
+ // custom header specified (as string)?
12768
+ // it becomes responsible for boundary
12769
+ // (e.g. to handle extra CRLFs on .NET servers)
12770
+ if (typeof options.header == 'string') {
12771
+ return options.header;
12772
+ }
12649
12773
 
12650
- // no need to bother with the length
12651
- if (!options.knownLength) {
12652
- this._valuesToMeasure.push(value);
12653
- }
12654
- };
12774
+ var contentDisposition = this._getContentDisposition(value, options);
12775
+ var contentType = this._getContentType(value, options);
12655
12776
 
12656
- FormData.prototype._lengthRetriever = function(value, callback) {
12777
+ var contents = '';
12778
+ var headers = {
12779
+ // add custom disposition as third element or keep it two elements if not
12780
+ 'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
12781
+ // if no content type. allow it to be empty array
12782
+ 'Content-Type': [].concat(contentType || [])
12783
+ };
12657
12784
 
12658
- if (value.hasOwnProperty('fd')) {
12785
+ // allow custom headers.
12786
+ if (typeof options.header == 'object') {
12787
+ populate(headers, options.header);
12788
+ }
12659
12789
 
12660
- // take read range into a account
12661
- // `end` = Infinity –> read file till the end
12662
- //
12663
- // TODO: Looks like there is bug in Node fs.createReadStream
12664
- // it doesn't respect `end` options without `start` options
12665
- // Fix it when node fixes it.
12666
- // https://github.com/joyent/node/issues/7819
12667
- if (value.end != undefined && value.end != Infinity && value.start != undefined) {
12790
+ var header;
12791
+ for (var prop in headers) {
12792
+ if (!headers.hasOwnProperty(prop)) continue;
12793
+ header = headers[prop];
12668
12794
 
12669
- // when end specified
12670
- // no need to calculate range
12671
- // inclusive, starts with 0
12672
- callback(null, value.end + 1 - (value.start ? value.start : 0));
12795
+ // skip nullish headers.
12796
+ if (header == null) {
12797
+ continue;
12798
+ }
12673
12799
 
12674
- // not that fast snoopy
12675
- } else {
12676
- // still need to fetch file size from fs
12677
- fs.stat(value.path, function(err, stat) {
12800
+ // convert all headers to arrays.
12801
+ if (!Array.isArray(header)) {
12802
+ header = [header];
12803
+ }
12678
12804
 
12679
- var fileSize;
12805
+ // add non-empty headers.
12806
+ if (header.length) {
12807
+ contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK;
12808
+ }
12809
+ }
12680
12810
 
12681
- if (err) {
12682
- callback(err);
12683
- return;
12684
- }
12811
+ return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
12812
+ };
12813
+
12814
+ FormData.prototype._getContentDisposition = function(value, options) {
12815
+
12816
+ var filename
12817
+ , contentDisposition
12818
+ ;
12819
+
12820
+ if (typeof options.filepath === 'string') {
12821
+ // custom filepath for relative paths
12822
+ filename = path.normalize(options.filepath).replace(/\\/g, '/');
12823
+ } else if (options.filename || value.name || value.path) {
12824
+ // custom filename take precedence
12825
+ // formidable and the browser add a name property
12826
+ // fs- and request- streams have path property
12827
+ filename = path.basename(options.filename || value.name || value.path);
12828
+ } else if (value.readable && value.hasOwnProperty('httpVersion')) {
12829
+ // or try http response
12830
+ filename = path.basename(value.client._httpMessage.path || '');
12831
+ }
12685
12832
 
12686
- // update final size based on the range options
12687
- fileSize = stat.size - (value.start ? value.start : 0);
12688
- callback(null, fileSize);
12689
- });
12690
- }
12833
+ if (filename) {
12834
+ contentDisposition = 'filename="' + filename + '"';
12835
+ }
12691
12836
 
12692
- // or http response
12693
- } else if (value.hasOwnProperty('httpVersion')) {
12694
- callback(null, +value.headers['content-length']);
12837
+ return contentDisposition;
12838
+ };
12695
12839
 
12696
- // or request stream http://github.com/mikeal/request
12697
- } else if (value.hasOwnProperty('httpModule')) {
12698
- // wait till response come back
12699
- value.on('response', function(response) {
12700
- value.pause();
12701
- callback(null, +response.headers['content-length']);
12702
- });
12703
- value.resume();
12840
+ FormData.prototype._getContentType = function(value, options) {
12704
12841
 
12705
- // something else
12706
- } else {
12707
- callback('Unknown stream');
12708
- }
12709
- };
12842
+ // use custom content-type above all
12843
+ var contentType = options.contentType;
12710
12844
 
12711
- FormData.prototype._multiPartHeader = function(field, value, options) {
12712
- // custom header specified (as string)?
12713
- // it becomes responsible for boundary
12714
- // (e.g. to handle extra CRLFs on .NET servers)
12715
- if (typeof options.header == 'string') {
12716
- return options.header;
12717
- }
12718
-
12719
- var contentDisposition = this._getContentDisposition(value, options);
12720
- var contentType = this._getContentType(value, options);
12721
-
12722
- var contents = '';
12723
- var headers = {
12724
- // add custom disposition as third element or keep it two elements if not
12725
- 'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
12726
- // if no content type. allow it to be empty array
12727
- 'Content-Type': [].concat(contentType || [])
12728
- };
12729
-
12730
- // allow custom headers.
12731
- if (typeof options.header == 'object') {
12732
- populate(headers, options.header);
12733
- }
12734
-
12735
- var header;
12736
- for (var prop in headers) {
12737
- if (!headers.hasOwnProperty(prop)) continue;
12738
- header = headers[prop];
12739
-
12740
- // skip nullish headers.
12741
- if (header == null) {
12742
- continue;
12743
- }
12845
+ // or try `name` from formidable, browser
12846
+ if (!contentType && value.name) {
12847
+ contentType = mime.lookup(value.name);
12848
+ }
12744
12849
 
12745
- // convert all headers to arrays.
12746
- if (!Array.isArray(header)) {
12747
- header = [header];
12748
- }
12850
+ // or try `path` from fs-, request- streams
12851
+ if (!contentType && value.path) {
12852
+ contentType = mime.lookup(value.path);
12853
+ }
12749
12854
 
12750
- // add non-empty headers.
12751
- if (header.length) {
12752
- contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK;
12753
- }
12754
- }
12855
+ // or if it's http-reponse
12856
+ if (!contentType && value.readable && value.hasOwnProperty('httpVersion')) {
12857
+ contentType = value.headers['content-type'];
12858
+ }
12755
12859
 
12756
- return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
12757
- };
12860
+ // or guess it from the filepath or filename
12861
+ if (!contentType && (options.filepath || options.filename)) {
12862
+ contentType = mime.lookup(options.filepath || options.filename);
12863
+ }
12758
12864
 
12759
- FormData.prototype._getContentDisposition = function(value, options) {
12760
-
12761
- var filename
12762
- , contentDisposition
12763
- ;
12764
-
12765
- if (typeof options.filepath === 'string') {
12766
- // custom filepath for relative paths
12767
- filename = path.normalize(options.filepath).replace(/\\/g, '/');
12768
- } else if (options.filename || value.name || value.path) {
12769
- // custom filename take precedence
12770
- // formidable and the browser add a name property
12771
- // fs- and request- streams have path property
12772
- filename = path.basename(options.filename || value.name || value.path);
12773
- } else if (value.readable && value.hasOwnProperty('httpVersion')) {
12774
- // or try http response
12775
- filename = path.basename(value.client._httpMessage.path || '');
12776
- }
12777
-
12778
- if (filename) {
12779
- contentDisposition = 'filename="' + filename + '"';
12780
- }
12781
-
12782
- return contentDisposition;
12783
- };
12865
+ // fallback to the default content type if `value` is not simple value
12866
+ if (!contentType && typeof value == 'object') {
12867
+ contentType = FormData.DEFAULT_CONTENT_TYPE;
12868
+ }
12784
12869
 
12785
- FormData.prototype._getContentType = function(value, options) {
12870
+ return contentType;
12871
+ };
12786
12872
 
12787
- // use custom content-type above all
12788
- var contentType = options.contentType;
12873
+ FormData.prototype._multiPartFooter = function() {
12874
+ return function(next) {
12875
+ var footer = FormData.LINE_BREAK;
12789
12876
 
12790
- // or try `name` from formidable, browser
12791
- if (!contentType && value.name) {
12792
- contentType = mime.lookup(value.name);
12793
- }
12877
+ var lastPart = (this._streams.length === 0);
12878
+ if (lastPart) {
12879
+ footer += this._lastBoundary();
12880
+ }
12794
12881
 
12795
- // or try `path` from fs-, request- streams
12796
- if (!contentType && value.path) {
12797
- contentType = mime.lookup(value.path);
12798
- }
12882
+ next(footer);
12883
+ }.bind(this);
12884
+ };
12799
12885
 
12800
- // or if it's http-reponse
12801
- if (!contentType && value.readable && value.hasOwnProperty('httpVersion')) {
12802
- contentType = value.headers['content-type'];
12803
- }
12886
+ FormData.prototype._lastBoundary = function() {
12887
+ return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
12888
+ };
12804
12889
 
12805
- // or guess it from the filepath or filename
12806
- if (!contentType && (options.filepath || options.filename)) {
12807
- contentType = mime.lookup(options.filepath || options.filename);
12808
- }
12890
+ FormData.prototype.getHeaders = function(userHeaders) {
12891
+ var header;
12892
+ var formHeaders = {
12893
+ 'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
12894
+ };
12809
12895
 
12810
- // fallback to the default content type if `value` is not simple value
12811
- if (!contentType && typeof value == 'object') {
12812
- contentType = FormData.DEFAULT_CONTENT_TYPE;
12813
- }
12896
+ for (header in userHeaders) {
12897
+ if (userHeaders.hasOwnProperty(header)) {
12898
+ formHeaders[header.toLowerCase()] = userHeaders[header];
12899
+ }
12900
+ }
12814
12901
 
12815
- return contentType;
12816
- };
12902
+ return formHeaders;
12903
+ };
12817
12904
 
12818
- FormData.prototype._multiPartFooter = function() {
12819
- return function(next) {
12820
- var footer = FormData.LINE_BREAK;
12905
+ FormData.prototype.setBoundary = function(boundary) {
12906
+ this._boundary = boundary;
12907
+ };
12821
12908
 
12822
- var lastPart = (this._streams.length === 0);
12823
- if (lastPart) {
12824
- footer += this._lastBoundary();
12825
- }
12909
+ FormData.prototype.getBoundary = function() {
12910
+ if (!this._boundary) {
12911
+ this._generateBoundary();
12912
+ }
12826
12913
 
12827
- next(footer);
12828
- }.bind(this);
12829
- };
12914
+ return this._boundary;
12915
+ };
12830
12916
 
12831
- FormData.prototype._lastBoundary = function() {
12832
- return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
12833
- };
12917
+ FormData.prototype.getBuffer = function() {
12918
+ var dataBuffer = new Buffer.alloc( 0 );
12919
+ var boundary = this.getBoundary();
12834
12920
 
12835
- FormData.prototype.getHeaders = function(userHeaders) {
12836
- var header;
12837
- var formHeaders = {
12838
- 'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
12839
- };
12921
+ // Create the form content. Add Line breaks to the end of data.
12922
+ for (var i = 0, len = this._streams.length; i < len; i++) {
12923
+ if (typeof this._streams[i] !== 'function') {
12840
12924
 
12841
- for (header in userHeaders) {
12842
- if (userHeaders.hasOwnProperty(header)) {
12843
- formHeaders[header.toLowerCase()] = userHeaders[header];
12844
- }
12845
- }
12925
+ // Add content to the buffer.
12926
+ if(Buffer.isBuffer(this._streams[i])) {
12927
+ dataBuffer = Buffer.concat( [dataBuffer, this._streams[i]]);
12928
+ }else {
12929
+ dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(this._streams[i])]);
12930
+ }
12846
12931
 
12847
- return formHeaders;
12848
- };
12932
+ // Add break after content.
12933
+ if (typeof this._streams[i] !== 'string' || this._streams[i].substring( 2, boundary.length + 2 ) !== boundary) {
12934
+ dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(FormData.LINE_BREAK)] );
12935
+ }
12936
+ }
12937
+ }
12849
12938
 
12850
- FormData.prototype.setBoundary = function(boundary) {
12851
- this._boundary = boundary;
12852
- };
12939
+ // Add the footer and return the Buffer object.
12940
+ return Buffer.concat( [dataBuffer, Buffer.from(this._lastBoundary())] );
12941
+ };
12853
12942
 
12854
- FormData.prototype.getBoundary = function() {
12855
- if (!this._boundary) {
12856
- this._generateBoundary();
12857
- }
12943
+ FormData.prototype._generateBoundary = function() {
12944
+ // This generates a 50 character boundary similar to those used by Firefox.
12945
+ // They are optimized for boyer-moore parsing.
12946
+ var boundary = '--------------------------';
12947
+ for (var i = 0; i < 24; i++) {
12948
+ boundary += Math.floor(Math.random() * 10).toString(16);
12949
+ }
12858
12950
 
12859
- return this._boundary;
12860
- };
12951
+ this._boundary = boundary;
12952
+ };
12861
12953
 
12862
- FormData.prototype.getBuffer = function() {
12863
- var dataBuffer = new Buffer.alloc( 0 );
12864
- var boundary = this.getBoundary();
12865
-
12866
- // Create the form content. Add Line breaks to the end of data.
12867
- for (var i = 0, len = this._streams.length; i < len; i++) {
12868
- if (typeof this._streams[i] !== 'function') {
12869
-
12870
- // Add content to the buffer.
12871
- if(Buffer.isBuffer(this._streams[i])) {
12872
- dataBuffer = Buffer.concat( [dataBuffer, this._streams[i]]);
12873
- }else {
12874
- dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(this._streams[i])]);
12875
- }
12876
-
12877
- // Add break after content.
12878
- if (typeof this._streams[i] !== 'string' || this._streams[i].substring( 2, boundary.length + 2 ) !== boundary) {
12879
- dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(FormData.LINE_BREAK)] );
12880
- }
12881
- }
12882
- }
12954
+ // Note: getLengthSync DOESN'T calculate streams length
12955
+ // As workaround one can calculate file size manually
12956
+ // and add it as knownLength option
12957
+ FormData.prototype.getLengthSync = function() {
12958
+ var knownLength = this._overheadLength + this._valueLength;
12883
12959
 
12884
- // Add the footer and return the Buffer object.
12885
- return Buffer.concat( [dataBuffer, Buffer.from(this._lastBoundary())] );
12886
- };
12960
+ // Don't get confused, there are 3 "internal" streams for each keyval pair
12961
+ // so it basically checks if there is any value added to the form
12962
+ if (this._streams.length) {
12963
+ knownLength += this._lastBoundary().length;
12964
+ }
12887
12965
 
12888
- FormData.prototype._generateBoundary = function() {
12889
- // This generates a 50 character boundary similar to those used by Firefox.
12890
- // They are optimized for boyer-moore parsing.
12891
- var boundary = '--------------------------';
12892
- for (var i = 0; i < 24; i++) {
12893
- boundary += Math.floor(Math.random() * 10).toString(16);
12894
- }
12966
+ // https://github.com/form-data/form-data/issues/40
12967
+ if (!this.hasKnownLength()) {
12968
+ // Some async length retrievers are present
12969
+ // therefore synchronous length calculation is false.
12970
+ // Please use getLength(callback) to get proper length
12971
+ this._error(new Error('Cannot calculate proper length in synchronous way.'));
12972
+ }
12895
12973
 
12896
- this._boundary = boundary;
12897
- };
12974
+ return knownLength;
12975
+ };
12898
12976
 
12899
- // Note: getLengthSync DOESN'T calculate streams length
12900
- // As workaround one can calculate file size manually
12901
- // and add it as knownLength option
12902
- FormData.prototype.getLengthSync = function() {
12903
- var knownLength = this._overheadLength + this._valueLength;
12904
-
12905
- // Don't get confused, there are 3 "internal" streams for each keyval pair
12906
- // so it basically checks if there is any value added to the form
12907
- if (this._streams.length) {
12908
- knownLength += this._lastBoundary().length;
12909
- }
12910
-
12911
- // https://github.com/form-data/form-data/issues/40
12912
- if (!this.hasKnownLength()) {
12913
- // Some async length retrievers are present
12914
- // therefore synchronous length calculation is false.
12915
- // Please use getLength(callback) to get proper length
12916
- this._error(new Error('Cannot calculate proper length in synchronous way.'));
12917
- }
12918
-
12919
- return knownLength;
12920
- };
12977
+ // Public API to check if length of added values is known
12978
+ // https://github.com/form-data/form-data/issues/196
12979
+ // https://github.com/form-data/form-data/issues/262
12980
+ FormData.prototype.hasKnownLength = function() {
12981
+ var hasKnownLength = true;
12921
12982
 
12922
- // Public API to check if length of added values is known
12923
- // https://github.com/form-data/form-data/issues/196
12924
- // https://github.com/form-data/form-data/issues/262
12925
- FormData.prototype.hasKnownLength = function() {
12926
- var hasKnownLength = true;
12983
+ if (this._valuesToMeasure.length) {
12984
+ hasKnownLength = false;
12985
+ }
12927
12986
 
12928
- if (this._valuesToMeasure.length) {
12929
- hasKnownLength = false;
12930
- }
12987
+ return hasKnownLength;
12988
+ };
12931
12989
 
12932
- return hasKnownLength;
12933
- };
12990
+ FormData.prototype.getLength = function(cb) {
12991
+ var knownLength = this._overheadLength + this._valueLength;
12934
12992
 
12935
- FormData.prototype.getLength = function(cb) {
12936
- var knownLength = this._overheadLength + this._valueLength;
12993
+ if (this._streams.length) {
12994
+ knownLength += this._lastBoundary().length;
12995
+ }
12937
12996
 
12938
- if (this._streams.length) {
12939
- knownLength += this._lastBoundary().length;
12940
- }
12997
+ if (!this._valuesToMeasure.length) {
12998
+ process.nextTick(cb.bind(this, null, knownLength));
12999
+ return;
13000
+ }
12941
13001
 
12942
- if (!this._valuesToMeasure.length) {
12943
- process.nextTick(cb.bind(this, null, knownLength));
12944
- return;
12945
- }
13002
+ asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
13003
+ if (err) {
13004
+ cb(err);
13005
+ return;
13006
+ }
12946
13007
 
12947
- asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
12948
- if (err) {
12949
- cb(err);
12950
- return;
12951
- }
13008
+ values.forEach(function(length) {
13009
+ knownLength += length;
13010
+ });
12952
13011
 
12953
- values.forEach(function(length) {
12954
- knownLength += length;
12955
- });
13012
+ cb(null, knownLength);
13013
+ });
13014
+ };
13015
+
13016
+ FormData.prototype.submit = function(params, cb) {
13017
+ var request
13018
+ , options
13019
+ , defaults = {method: 'post'}
13020
+ ;
13021
+
13022
+ // parse provided url if it's string
13023
+ // or treat it as options object
13024
+ if (typeof params == 'string') {
13025
+
13026
+ params = parseUrl(params);
13027
+ options = populate({
13028
+ port: params.port,
13029
+ path: params.pathname,
13030
+ host: params.hostname,
13031
+ protocol: params.protocol
13032
+ }, defaults);
13033
+
13034
+ // use custom params
13035
+ } else {
13036
+
13037
+ options = populate(params, defaults);
13038
+ // if no port provided use default one
13039
+ if (!options.port) {
13040
+ options.port = options.protocol == 'https:' ? 443 : 80;
13041
+ }
13042
+ }
12956
13043
 
12957
- cb(null, knownLength);
12958
- });
12959
- };
13044
+ // put that good code in getHeaders to some use
13045
+ options.headers = this.getHeaders(params.headers);
12960
13046
 
12961
- FormData.prototype.submit = function(params, cb) {
12962
- var request
12963
- , options
12964
- , defaults = {method: 'post'}
12965
- ;
12966
-
12967
- // parse provided url if it's string
12968
- // or treat it as options object
12969
- if (typeof params == 'string') {
12970
-
12971
- params = parseUrl(params);
12972
- options = populate({
12973
- port: params.port,
12974
- path: params.pathname,
12975
- host: params.hostname,
12976
- protocol: params.protocol
12977
- }, defaults);
12978
-
12979
- // use custom params
12980
- } else {
12981
-
12982
- options = populate(params, defaults);
12983
- // if no port provided use default one
12984
- if (!options.port) {
12985
- options.port = options.protocol == 'https:' ? 443 : 80;
12986
- }
12987
- }
12988
-
12989
- // put that good code in getHeaders to some use
12990
- options.headers = this.getHeaders(params.headers);
12991
-
12992
- // https if specified, fallback to http in any other case
12993
- if (options.protocol == 'https:') {
12994
- request = https.request(options);
12995
- } else {
12996
- request = http.request(options);
12997
- }
12998
-
12999
- // get content length and fire away
13000
- this.getLength(function(err, length) {
13001
- if (err && err !== 'Unknown stream') {
13002
- this._error(err);
13003
- return;
13004
- }
13047
+ // https if specified, fallback to http in any other case
13048
+ if (options.protocol == 'https:') {
13049
+ request = https.request(options);
13050
+ } else {
13051
+ request = http.request(options);
13052
+ }
13005
13053
 
13006
- // add content length
13007
- if (length) {
13008
- request.setHeader('Content-Length', length);
13009
- }
13054
+ // get content length and fire away
13055
+ this.getLength(function(err, length) {
13056
+ if (err && err !== 'Unknown stream') {
13057
+ this._error(err);
13058
+ return;
13059
+ }
13010
13060
 
13011
- this.pipe(request);
13012
- if (cb) {
13013
- var onResponse;
13061
+ // add content length
13062
+ if (length) {
13063
+ request.setHeader('Content-Length', length);
13064
+ }
13014
13065
 
13015
- var callback = function (error, responce) {
13016
- request.removeListener('error', callback);
13017
- request.removeListener('response', onResponse);
13066
+ this.pipe(request);
13067
+ if (cb) {
13068
+ var onResponse;
13018
13069
 
13019
- return cb.call(this, error, responce);
13020
- };
13070
+ var callback = function (error, responce) {
13071
+ request.removeListener('error', callback);
13072
+ request.removeListener('response', onResponse);
13021
13073
 
13022
- onResponse = callback.bind(this, null);
13074
+ return cb.call(this, error, responce);
13075
+ };
13023
13076
 
13024
- request.on('error', callback);
13025
- request.on('response', onResponse);
13026
- }
13027
- }.bind(this));
13077
+ onResponse = callback.bind(this, null);
13028
13078
 
13029
- return request;
13030
- };
13079
+ request.on('error', callback);
13080
+ request.on('response', onResponse);
13081
+ }
13082
+ }.bind(this));
13031
13083
 
13032
- FormData.prototype._error = function(err) {
13033
- if (!this.error) {
13034
- this.error = err;
13035
- this.pause();
13036
- this.emit('error', err);
13037
- }
13038
- };
13084
+ return request;
13085
+ };
13039
13086
 
13040
- FormData.prototype.toString = function () {
13041
- return '[object FormData]';
13042
- };
13087
+ FormData.prototype._error = function(err) {
13088
+ if (!this.error) {
13089
+ this.error = err;
13090
+ this.pause();
13091
+ this.emit('error', err);
13092
+ }
13093
+ };
13094
+
13095
+ FormData.prototype.toString = function () {
13096
+ return '[object FormData]';
13097
+ };
13098
+ return form_data;
13099
+ }
13043
13100
 
13044
- var FormDataModule = /*@__PURE__*/getDefaultExportFromCjs(form_data);
13101
+ var form_dataExports = requireForm_data();
13102
+ var FormDataModule = /*@__PURE__*/getDefaultExportFromCjs(form_dataExports);
13045
13103
 
13046
13104
  const GRANT_TYPE$1 = 'client_credentials';
13047
13105
  const castClientOptionsToRequestParams = (clientOptions) => {
@@ -13460,4 +13518,4 @@ var EnumLookupUserType;
13460
13518
  EnumLookupUserType["tenant"] = "tenant";
13461
13519
  })(EnumLookupUserType || (EnumLookupUserType = {}));
13462
13520
 
13463
- export { DEFAULT_CLIENT_CONFIG as DEFAULT_PARAMETER_STORE_CLIENT_CONFIG, EnumCommunicationMethodType, EnumCommunicationPreferenceChannel, EnumCountryCode, EnumInputChannel, EnumLocale, EnumLookupUserType, EnumResource, EnumServiceProviderType, EnumTimezone, EnumUnitObjectType, EnumUnitType, EnumUserPermissionObjectType, EnumUserPermissionRole, EnumUserRelationType, EnumUtilisationPeriodType, createTokenStore, parameterStore, restClient };
13521
+ export { EnumCommunicationMethodType, EnumCommunicationPreferenceChannel, EnumCountryCode, EnumInputChannel, EnumLocale, EnumLookupUserType, EnumResource, EnumServiceProviderType, EnumTimezone, EnumUnitObjectType, EnumUnitType, EnumUserPermissionObjectType, EnumUserPermissionRole, EnumUserRelationType, EnumUtilisationPeriodType, createTokenStore, restClient };