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