|
// AWS SDK for JavaScript v2.0.0-rc.20 |
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
|
// License at https://sdk.amazonaws.com/js/BUNDLE_LICENSE.txt |
|
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
|
|
|
},{}],2:[function(require,module,exports){ |
|
|
|
|
|
var base64 = require('base64-js') |
|
var ieee754 = require('ieee754') |
|
|
|
exports.Buffer = Buffer |
|
exports.SlowBuffer = Buffer |
|
exports.INSPECT_MAX_BYTES = 50 |
|
Buffer.poolSize = 8192 |
|
|
|
|
|
Buffer._useTypedArrays = (function () { |
|
try { |
|
var buf = new ArrayBuffer(0) |
|
var arr = new Uint8Array(buf) |
|
arr.foo = function () { return 42 } |
|
return 42 === arr.foo() && |
|
typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray` |
|
} catch (e) { |
|
return false |
|
} |
|
})() |
|
|
|
|
|
function Buffer (subject, encoding, noZero) { |
|
if (!(this instanceof Buffer)) |
|
return new Buffer(subject, encoding, noZero) |
|
|
|
var type = typeof subject |
|
|
|
if (encoding === 'base64' && type === 'string') { |
|
subject = stringtrim(subject) |
|
while (subject.length % 4 !== 0) { |
|
subject = subject + '=' |
|
} |
|
} |
|
|
|
var length |
|
if (type === 'number') |
|
length = coerce(subject) |
|
else if (type === 'string') |
|
length = Buffer.byteLength(subject, encoding) |
|
else if (type === 'object') |
|
length = coerce(subject.length) // assume that object is array-like |
|
else |
|
throw new Error('First argument needs to be a number, array or string.') |
|
|
|
var buf |
|
if (Buffer._useTypedArrays) { |
|
buf = Buffer._augment(new Uint8Array(length)) |
|
} else { |
|
buf = this |
|
buf.length = length |
|
buf._isBuffer = true |
|
} |
|
|
|
var i |
|
if (Buffer._useTypedArrays && typeof subject.byteLength === 'number') { |
|
buf._set(subject) |
|
} else if (isArrayish(subject)) { |
|
for (i = 0; i < length; i++) { |
|
if (Buffer.isBuffer(subject)) |
|
buf[i] = subject.readUInt8(i) |
|
else |
|
buf[i] = subject[i] |
|
} |
|
} else if (type === 'string') { |
|
buf.write(subject, 0, encoding) |
|
} else if (type === 'number' && !Buffer._useTypedArrays && !noZero) { |
|
for (i = 0; i < length; i++) { |
|
buf[i] = 0 |
|
} |
|
} |
|
|
|
return buf |
|
} |
|
|
|
|
|
Buffer.isEncoding = function (encoding) { |
|
switch (String(encoding).toLowerCase()) { |
|
case 'hex': |
|
case 'utf8': |
|
case 'utf-8': |
|
case 'ascii': |
|
case 'binary': |
|
case 'base64': |
|
case 'raw': |
|
case 'ucs2': |
|
case 'ucs-2': |
|
case 'utf16le': |
|
case 'utf-16le': |
|
return true |
|
default: |
|
return false |
|
} |
|
} |
|
|
|
Buffer.isBuffer = function (b) { |
|
return !!(b !== null && b !== undefined && b._isBuffer) |
|
} |
|
|
|
Buffer.byteLength = function (str, encoding) { |
|
var ret |
|
str = str + '' |
|
switch (encoding || 'utf8') { |
|
case 'hex': |
|
ret = str.length / 2 |
|
break |
|
case 'utf8': |
|
case 'utf-8': |
|
ret = utf8ToBytes(str).length |
|
break |
|
case 'ascii': |
|
case 'binary': |
|
case 'raw': |
|
ret = str.length |
|
break |
|
case 'base64': |
|
ret = base64ToBytes(str).length |
|
break |
|
case 'ucs2': |
|
case 'ucs-2': |
|
case 'utf16le': |
|
case 'utf-16le': |
|
ret = str.length * 2 |
|
break |
|
default: |
|
throw new Error('Unknown encoding') |
|
} |
|
return ret |
|
} |
|
|
|
Buffer.concat = function (list, totalLength) { |
|
assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' + |
|
'list should be an Array.') |
|
|
|
if (list.length === 0) { |
|
return new Buffer(0) |
|
} else if (list.length === 1) { |
|
return list[0] |
|
} |
|
|
|
var i |
|
if (typeof totalLength !== 'number') { |
|
totalLength = 0 |
|
for (i = 0; i < list.length; i++) { |
|
totalLength += list[i].length |
|
} |
|
} |
|
|
|
var buf = new Buffer(totalLength) |
|
var pos = 0 |
|
for (i = 0; i < list.length; i++) { |
|
var item = list[i] |
|
item.copy(buf, pos) |
|
pos += item.length |
|
} |
|
return buf |
|
} |
|
|
|
|
|
function _hexWrite (buf, string, offset, length) { |
|
offset = Number(offset) || 0 |
|
var remaining = buf.length - offset |
|
if (!length) { |
|
length = remaining |
|
} else { |
|
length = Number(length) |
|
if (length > remaining) { |
|
length = remaining |
|
} |
|
} |
|
|
|
var strLen = string.length |
|
assert(strLen % 2 === 0, 'Invalid hex string') |
|
|
|
if (length > strLen / 2) { |
|
length = strLen / 2 |
|
} |
|
for (var i = 0; i < length; i++) { |
|
var byte = parseInt(string.substr(i * 2, 2), 16) |
|
assert(!isNaN(byte), 'Invalid hex string') |
|
buf[offset + i] = byte |
|
} |
|
Buffer._charsWritten = i * 2 |
|
return i |
|
} |
|
|
|
function _utf8Write (buf, string, offset, length) { |
|
var charsWritten = Buffer._charsWritten = |
|
blitBuffer(utf8ToBytes(string), buf, offset, length) |
|
return charsWritten |
|
} |
|
|
|
function _asciiWrite (buf, string, offset, length) { |
|
var charsWritten = Buffer._charsWritten = |
|
blitBuffer(asciiToBytes(string), buf, offset, length) |
|
return charsWritten |
|
} |
|
|
|
function _binaryWrite (buf, string, offset, length) { |
|
return _asciiWrite(buf, string, offset, length) |
|
} |
|
|
|
function _base64Write (buf, string, offset, length) { |
|
var charsWritten = Buffer._charsWritten = |
|
blitBuffer(base64ToBytes(string), buf, offset, length) |
|
return charsWritten |
|
} |
|
|
|
function _utf16leWrite (buf, string, offset, length) { |
|
var charsWritten = Buffer._charsWritten = |
|
blitBuffer(utf16leToBytes(string), buf, offset, length) |
|
return charsWritten |
|
} |
|
|
|
Buffer.prototype.write = function (string, offset, length, encoding) { |
|
if (isFinite(offset)) { |
|
if (!isFinite(length)) { |
|
encoding = length |
|
length = undefined |
|
} |
|
} else { // legacy |
|
var swap = encoding |
|
encoding = offset |
|
offset = length |
|
length = swap |
|
} |
|
|
|
offset = Number(offset) || 0 |
|
var remaining = this.length - offset |
|
if (!length) { |
|
length = remaining |
|
} else { |
|
length = Number(length) |
|
if (length > remaining) { |
|
length = remaining |
|
} |
|
} |
|
encoding = String(encoding || 'utf8').toLowerCase() |
|
|
|
var ret |
|
switch (encoding) { |
|
case 'hex': |
|
ret = _hexWrite(this, string, offset, length) |
|
break |
|
case 'utf8': |
|
case 'utf-8': |
|
ret = _utf8Write(this, string, offset, length) |
|
break |
|
case 'ascii': |
|
ret = _asciiWrite(this, string, offset, length) |
|
break |
|
case 'binary': |
|
ret = _binaryWrite(this, string, offset, length) |
|
break |
|
case 'base64': |
|
ret = _base64Write(this, string, offset, length) |
|
break |
|
case 'ucs2': |
|
case 'ucs-2': |
|
case 'utf16le': |
|
case 'utf-16le': |
|
ret = _utf16leWrite(this, string, offset, length) |
|
break |
|
default: |
|
throw new Error('Unknown encoding') |
|
} |
|
return ret |
|
} |
|
|
|
Buffer.prototype.toString = function (encoding, start, end) { |
|
var self = this |
|
|
|
encoding = String(encoding || 'utf8').toLowerCase() |
|
start = Number(start) || 0 |
|
end = (end !== undefined) |
|
? Number(end) |
|
: end = self.length |
|
|
|
if (end === start) |
|
return '' |
|
|
|
var ret |
|
switch (encoding) { |
|
case 'hex': |
|
ret = _hexSlice(self, start, end) |
|
break |
|
case 'utf8': |
|
case 'utf-8': |
|
ret = _utf8Slice(self, start, end) |
|
break |
|
case 'ascii': |
|
ret = _asciiSlice(self, start, end) |
|
break |
|
case 'binary': |
|
ret = _binarySlice(self, start, end) |
|
break |
|
case 'base64': |
|
ret = _base64Slice(self, start, end) |
|
break |
|
case 'ucs2': |
|
case 'ucs-2': |
|
case 'utf16le': |
|
case 'utf-16le': |
|
ret = _utf16leSlice(self, start, end) |
|
break |
|
default: |
|
throw new Error('Unknown encoding') |
|
} |
|
return ret |
|
} |
|
|
|
Buffer.prototype.toJSON = function () { |
|
return { |
|
type: 'Buffer', |
|
data: Array.prototype.slice.call(this._arr || this, 0) |
|
} |
|
} |
|
|
|
Buffer.prototype.copy = function (target, target_start, start, end) { |
|
var source = this |
|
|
|
if (!start) start = 0 |
|
if (!end && end !== 0) end = this.length |
|
if (!target_start) target_start = 0 |
|
|
|
if (end === start) return |
|
if (target.length === 0 || source.length === 0) return |
|
|
|
assert(end >= start, 'sourceEnd < sourceStart') |
|
assert(target_start >= 0 && target_start < target.length, |
|
'targetStart out of bounds') |
|
assert(start >= 0 && start < source.length, 'sourceStart out of bounds') |
|
assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds') |
|
|
|
if (end > this.length) |
|
end = this.length |
|
if (target.length - target_start < end - start) |
|
end = target.length - target_start + start |
|
|
|
var len = end - start |
|
|
|
if (len < 100 || !Buffer._useTypedArrays) { |
|
for (var i = 0; i < len; i++) |
|
target[i + target_start] = this[i + start] |
|
} else { |
|
target._set(this.subarray(start, start + len), target_start) |
|
} |
|
} |
|
|
|
function _base64Slice (buf, start, end) { |
|
if (start === 0 && end === buf.length) { |
|
return base64.fromByteArray(buf) |
|
} else { |
|
return base64.fromByteArray(buf.slice(start, end)) |
|
} |
|
} |
|
|
|
function _utf8Slice (buf, start, end) { |
|
var res = '' |
|
var tmp = '' |
|
end = Math.min(buf.length, end) |
|
|
|
for (var i = start; i < end; i++) { |
|
if (buf[i] <= 0x7F) { |
|
res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) |
|
tmp = '' |
|
} else { |
|
tmp += '%' + buf[i].toString(16) |
|
} |
|
} |
|
|
|
return res + decodeUtf8Char(tmp) |
|
} |
|
|
|
function _asciiSlice (buf, start, end) { |
|
var ret = '' |
|
end = Math.min(buf.length, end) |
|
|
|
for (var i = start; i < end; i++) |
|
ret += String.fromCharCode(buf[i]) |
|
return ret |
|
} |
|
|
|
function _binarySlice (buf, start, end) { |
|
return _asciiSlice(buf, start, end) |
|
} |
|
|
|
function _hexSlice (buf, start, end) { |
|
var len = buf.length |
|
|
|
if (!start || start < 0) start = 0 |
|
if (!end || end < 0 || end > len) end = len |
|
|
|
var out = '' |
|
for (var i = start; i < end; i++) { |
|
out += toHex(buf[i]) |
|
} |
|
return out |
|
} |
|
|
|
function _utf16leSlice (buf, start, end) { |
|
var bytes = buf.slice(start, end) |
|
var res = '' |
|
for (var i = 0; i < bytes.length; i += 2) { |
|
res += String.fromCharCode(bytes[i] + bytes[i+1] * 256) |
|
} |
|
return res |
|
} |
|
|
|
Buffer.prototype.slice = function (start, end) { |
|
var len = this.length |
|
start = clamp(start, len, 0) |
|
end = clamp(end, len, len) |
|
|
|
if (Buffer._useTypedArrays) { |
|
return Buffer._augment(this.subarray(start, end)) |
|
} else { |
|
var sliceLen = end - start |
|
var newBuf = new Buffer(sliceLen, undefined, true) |
|
for (var i = 0; i < sliceLen; i++) { |
|
newBuf[i] = this[i + start] |
|
} |
|
return newBuf |
|
} |
|
} |
|
|
|
Buffer.prototype.get = function (offset) { |
|
console.log('.get() is deprecated. Access using array indexes instead.') |
|
return this.readUInt8(offset) |
|
} |
|
|
|
Buffer.prototype.set = function (v, offset) { |
|
console.log('.set() is deprecated. Access using array indexes instead.') |
|
return this.writeUInt8(v, offset) |
|
} |
|
|
|
Buffer.prototype.readUInt8 = function (offset, noAssert) { |
|
if (!noAssert) { |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset < this.length, 'Trying to read beyond buffer length') |
|
} |
|
|
|
if (offset >= this.length) |
|
return |
|
|
|
return this[offset] |
|
} |
|
|
|
function _readUInt16 (buf, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 1 < buf.length, 'Trying to read beyond buffer length') |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
var val |
|
if (littleEndian) { |
|
val = buf[offset] |
|
if (offset + 1 < len) |
|
val |= buf[offset + 1] << 8 |
|
} else { |
|
val = buf[offset] << 8 |
|
if (offset + 1 < len) |
|
val |= buf[offset + 1] |
|
} |
|
return val |
|
} |
|
|
|
Buffer.prototype.readUInt16LE = function (offset, noAssert) { |
|
return _readUInt16(this, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.readUInt16BE = function (offset, noAssert) { |
|
return _readUInt16(this, offset, false, noAssert) |
|
} |
|
|
|
function _readUInt32 (buf, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
var val |
|
if (littleEndian) { |
|
if (offset + 2 < len) |
|
val = buf[offset + 2] << 16 |
|
if (offset + 1 < len) |
|
val |= buf[offset + 1] << 8 |
|
val |= buf[offset] |
|
if (offset + 3 < len) |
|
val = val + (buf[offset + 3] << 24 >>> 0) |
|
} else { |
|
if (offset + 1 < len) |
|
val = buf[offset + 1] << 16 |
|
if (offset + 2 < len) |
|
val |= buf[offset + 2] << 8 |
|
if (offset + 3 < len) |
|
val |= buf[offset + 3] |
|
val = val + (buf[offset] << 24 >>> 0) |
|
} |
|
return val |
|
} |
|
|
|
Buffer.prototype.readUInt32LE = function (offset, noAssert) { |
|
return _readUInt32(this, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.readUInt32BE = function (offset, noAssert) { |
|
return _readUInt32(this, offset, false, noAssert) |
|
} |
|
|
|
Buffer.prototype.readInt8 = function (offset, noAssert) { |
|
if (!noAssert) { |
|
assert(offset !== undefined && offset !== null, |
|
'missing offset') |
|
assert(offset < this.length, 'Trying to read beyond buffer length') |
|
} |
|
|
|
if (offset >= this.length) |
|
return |
|
|
|
var neg = this[offset] & 0x80 |
|
if (neg) |
|
return (0xff - this[offset] + 1) * -1 |
|
else |
|
return this[offset] |
|
} |
|
|
|
function _readInt16 (buf, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 1 < buf.length, 'Trying to read beyond buffer length') |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
var val = _readUInt16(buf, offset, littleEndian, true) |
|
var neg = val & 0x8000 |
|
if (neg) |
|
return (0xffff - val + 1) * -1 |
|
else |
|
return val |
|
} |
|
|
|
Buffer.prototype.readInt16LE = function (offset, noAssert) { |
|
return _readInt16(this, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.readInt16BE = function (offset, noAssert) { |
|
return _readInt16(this, offset, false, noAssert) |
|
} |
|
|
|
function _readInt32 (buf, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
var val = _readUInt32(buf, offset, littleEndian, true) |
|
var neg = val & 0x80000000 |
|
if (neg) |
|
return (0xffffffff - val + 1) * -1 |
|
else |
|
return val |
|
} |
|
|
|
Buffer.prototype.readInt32LE = function (offset, noAssert) { |
|
return _readInt32(this, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.readInt32BE = function (offset, noAssert) { |
|
return _readInt32(this, offset, false, noAssert) |
|
} |
|
|
|
function _readFloat (buf, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') |
|
} |
|
|
|
return ieee754.read(buf, offset, littleEndian, 23, 4) |
|
} |
|
|
|
Buffer.prototype.readFloatLE = function (offset, noAssert) { |
|
return _readFloat(this, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.readFloatBE = function (offset, noAssert) { |
|
return _readFloat(this, offset, false, noAssert) |
|
} |
|
|
|
function _readDouble (buf, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset + 7 < buf.length, 'Trying to read beyond buffer length') |
|
} |
|
|
|
return ieee754.read(buf, offset, littleEndian, 52, 8) |
|
} |
|
|
|
Buffer.prototype.readDoubleLE = function (offset, noAssert) { |
|
return _readDouble(this, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.readDoubleBE = function (offset, noAssert) { |
|
return _readDouble(this, offset, false, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeUInt8 = function (value, offset, noAssert) { |
|
if (!noAssert) { |
|
assert(value !== undefined && value !== null, 'missing value') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset < this.length, 'trying to write beyond buffer length') |
|
verifuint(value, 0xff) |
|
} |
|
|
|
if (offset >= this.length) return |
|
|
|
this[offset] = value |
|
} |
|
|
|
function _writeUInt16 (buf, value, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(value !== undefined && value !== null, 'missing value') |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 1 < buf.length, 'trying to write beyond buffer length') |
|
verifuint(value, 0xffff) |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) { |
|
buf[offset + i] = |
|
(value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> |
|
(littleEndian ? i : 1 - i) * 8 |
|
} |
|
} |
|
|
|
Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) { |
|
_writeUInt16(this, value, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) { |
|
_writeUInt16(this, value, offset, false, noAssert) |
|
} |
|
|
|
function _writeUInt32 (buf, value, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(value !== undefined && value !== null, 'missing value') |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 3 < buf.length, 'trying to write beyond buffer length') |
|
verifuint(value, 0xffffffff) |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) { |
|
buf[offset + i] = |
|
(value >>> (littleEndian ? i : 3 - i) * 8) & 0xff |
|
} |
|
} |
|
|
|
Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) { |
|
_writeUInt32(this, value, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) { |
|
_writeUInt32(this, value, offset, false, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeInt8 = function (value, offset, noAssert) { |
|
if (!noAssert) { |
|
assert(value !== undefined && value !== null, 'missing value') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset < this.length, 'Trying to write beyond buffer length') |
|
verifsint(value, 0x7f, -0x80) |
|
} |
|
|
|
if (offset >= this.length) |
|
return |
|
|
|
if (value >= 0) |
|
this.writeUInt8(value, offset, noAssert) |
|
else |
|
this.writeUInt8(0xff + value + 1, offset, noAssert) |
|
} |
|
|
|
function _writeInt16 (buf, value, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(value !== undefined && value !== null, 'missing value') |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 1 < buf.length, 'Trying to write beyond buffer length') |
|
verifsint(value, 0x7fff, -0x8000) |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
if (value >= 0) |
|
_writeUInt16(buf, value, offset, littleEndian, noAssert) |
|
else |
|
_writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeInt16LE = function (value, offset, noAssert) { |
|
_writeInt16(this, value, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeInt16BE = function (value, offset, noAssert) { |
|
_writeInt16(this, value, offset, false, noAssert) |
|
} |
|
|
|
function _writeInt32 (buf, value, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(value !== undefined && value !== null, 'missing value') |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 3 < buf.length, 'Trying to write beyond buffer length') |
|
verifsint(value, 0x7fffffff, -0x80000000) |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
if (value >= 0) |
|
_writeUInt32(buf, value, offset, littleEndian, noAssert) |
|
else |
|
_writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeInt32LE = function (value, offset, noAssert) { |
|
_writeInt32(this, value, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeInt32BE = function (value, offset, noAssert) { |
|
_writeInt32(this, value, offset, false, noAssert) |
|
} |
|
|
|
function _writeFloat (buf, value, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(value !== undefined && value !== null, 'missing value') |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 3 < buf.length, 'Trying to write beyond buffer length') |
|
verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38) |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
ieee754.write(buf, value, offset, littleEndian, 23, 4) |
|
} |
|
|
|
Buffer.prototype.writeFloatLE = function (value, offset, noAssert) { |
|
_writeFloat(this, value, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeFloatBE = function (value, offset, noAssert) { |
|
_writeFloat(this, value, offset, false, noAssert) |
|
} |
|
|
|
function _writeDouble (buf, value, offset, littleEndian, noAssert) { |
|
if (!noAssert) { |
|
assert(value !== undefined && value !== null, 'missing value') |
|
assert(typeof littleEndian === 'boolean', 'missing or invalid endian') |
|
assert(offset !== undefined && offset !== null, 'missing offset') |
|
assert(offset + 7 < buf.length, |
|
'Trying to write beyond buffer length') |
|
verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308) |
|
} |
|
|
|
var len = buf.length |
|
if (offset >= len) |
|
return |
|
|
|
ieee754.write(buf, value, offset, littleEndian, 52, 8) |
|
} |
|
|
|
Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) { |
|
_writeDouble(this, value, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) { |
|
_writeDouble(this, value, offset, false, noAssert) |
|
} |
|
|
|
Buffer.prototype.fill = function (value, start, end) { |
|
if (!value) value = 0 |
|
if (!start) start = 0 |
|
if (!end) end = this.length |
|
|
|
if (typeof value === 'string') { |
|
value = value.charCodeAt(0) |
|
} |
|
|
|
assert(typeof value === 'number' && !isNaN(value), 'value is not a number') |
|
assert(end >= start, 'end < start') |
|
|
|
if (end === start) return |
|
if (this.length === 0) return |
|
|
|
assert(start >= 0 && start < this.length, 'start out of bounds') |
|
assert(end >= 0 && end <= this.length, 'end out of bounds') |
|
|
|
for (var i = start; i < end; i++) { |
|
this[i] = value |
|
} |
|
} |
|
|
|
Buffer.prototype.inspect = function () { |
|
var out = [] |
|
var len = this.length |
|
for (var i = 0; i < len; i++) { |
|
out[i] = toHex(this[i]) |
|
if (i === exports.INSPECT_MAX_BYTES) { |
|
out[i + 1] = '...' |
|
break |
|
} |
|
} |
|
return '<Buffer ' + out.join(' ') + '>' |
|
} |
|
|
|
|
|
Buffer.prototype.toArrayBuffer = function () { |
|
if (typeof Uint8Array !== 'undefined') { |
|
if (Buffer._useTypedArrays) { |
|
return (new Buffer(this)).buffer |
|
} else { |
|
var buf = new Uint8Array(this.length) |
|
for (var i = 0, len = buf.length; i < len; i += 1) |
|
buf[i] = this[i] |
|
return buf.buffer |
|
} |
|
} else { |
|
throw new Error('Buffer.toArrayBuffer not supported in this browser') |
|
} |
|
} |
|
|
|
|
|
function stringtrim (str) { |
|
if (str.trim) return str.trim() |
|
return str.replace(/^\s+|\s+$/g, '') |
|
} |
|
|
|
var BP = Buffer.prototype |
|
|
|
|
|
Buffer._augment = function (arr) { |
|
arr._isBuffer = true |
|
|
|
arr._get = arr.get |
|
arr._set = arr.set |
|
|
|
arr.get = BP.get |
|
arr.set = BP.set |
|
|
|
arr.write = BP.write |
|
arr.toString = BP.toString |
|
arr.toLocaleString = BP.toString |
|
arr.toJSON = BP.toJSON |
|
arr.copy = BP.copy |
|
arr.slice = BP.slice |
|
arr.readUInt8 = BP.readUInt8 |
|
arr.readUInt16LE = BP.readUInt16LE |
|
arr.readUInt16BE = BP.readUInt16BE |
|
arr.readUInt32LE = BP.readUInt32LE |
|
arr.readUInt32BE = BP.readUInt32BE |
|
arr.readInt8 = BP.readInt8 |
|
arr.readInt16LE = BP.readInt16LE |
|
arr.readInt16BE = BP.readInt16BE |
|
arr.readInt32LE = BP.readInt32LE |
|
arr.readInt32BE = BP.readInt32BE |
|
arr.readFloatLE = BP.readFloatLE |
|
arr.readFloatBE = BP.readFloatBE |
|
arr.readDoubleLE = BP.readDoubleLE |
|
arr.readDoubleBE = BP.readDoubleBE |
|
arr.writeUInt8 = BP.writeUInt8 |
|
arr.writeUInt16LE = BP.writeUInt16LE |
|
arr.writeUInt16BE = BP.writeUInt16BE |
|
arr.writeUInt32LE = BP.writeUInt32LE |
|
arr.writeUInt32BE = BP.writeUInt32BE |
|
arr.writeInt8 = BP.writeInt8 |
|
arr.writeInt16LE = BP.writeInt16LE |
|
arr.writeInt16BE = BP.writeInt16BE |
|
arr.writeInt32LE = BP.writeInt32LE |
|
arr.writeInt32BE = BP.writeInt32BE |
|
arr.writeFloatLE = BP.writeFloatLE |
|
arr.writeFloatBE = BP.writeFloatBE |
|
arr.writeDoubleLE = BP.writeDoubleLE |
|
arr.writeDoubleBE = BP.writeDoubleBE |
|
arr.fill = BP.fill |
|
arr.inspect = BP.inspect |
|
arr.toArrayBuffer = BP.toArrayBuffer |
|
|
|
return arr |
|
} |
|
|
|
function clamp (index, len, defaultValue) { |
|
if (typeof index !== 'number') return defaultValue |
|
index = ~~index; // Coerce to integer. |
|
if (index >= len) return len |
|
if (index >= 0) return index |
|
index += len |
|
if (index >= 0) return index |
|
return 0 |
|
} |
|
|
|
function coerce (length) { |
|
length = ~~Math.ceil(+length) |
|
return length < 0 ? 0 : length |
|
} |
|
|
|
function isArray (subject) { |
|
return (Array.isArray || function (subject) { |
|
return Object.prototype.toString.call(subject) === '[object Array]' |
|
})(subject) |
|
} |
|
|
|
function isArrayish (subject) { |
|
return isArray(subject) || Buffer.isBuffer(subject) || |
|
subject && typeof subject === 'object' && |
|
typeof subject.length === 'number' |
|
} |
|
|
|
function toHex (n) { |
|
if (n < 16) return '0' + n.toString(16) |
|
return n.toString(16) |
|
} |
|
|
|
function utf8ToBytes (str) { |
|
var byteArray = [] |
|
for (var i = 0; i < str.length; i++) { |
|
var b = str.charCodeAt(i) |
|
if (b <= 0x7F) |
|
byteArray.push(str.charCodeAt(i)) |
|
else { |
|
var start = i |
|
if (b >= 0xD800 && b <= 0xDFFF) i++ |
|
var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%') |
|
for (var j = 0; j < h.length; j++) |
|
byteArray.push(parseInt(h[j], 16)) |
|
} |
|
} |
|
return byteArray |
|
} |
|
|
|
function asciiToBytes (str) { |
|
var byteArray = [] |
|
for (var i = 0; i < str.length; i++) { |
|
byteArray.push(str.charCodeAt(i) & 0xFF) |
|
} |
|
return byteArray |
|
} |
|
|
|
function utf16leToBytes (str) { |
|
var c, hi, lo |
|
var byteArray = [] |
|
for (var i = 0; i < str.length; i++) { |
|
c = str.charCodeAt(i) |
|
hi = c >> 8 |
|
lo = c % 256 |
|
byteArray.push(lo) |
|
byteArray.push(hi) |
|
} |
|
|
|
return byteArray |
|
} |
|
|
|
function base64ToBytes (str) { |
|
return base64.toByteArray(str) |
|
} |
|
|
|
function blitBuffer (src, dst, offset, length) { |
|
var pos |
|
for (var i = 0; i < length; i++) { |
|
if ((i + offset >= dst.length) || (i >= src.length)) |
|
break |
|
dst[i + offset] = src[i] |
|
} |
|
return i |
|
} |
|
|
|
function decodeUtf8Char (str) { |
|
try { |
|
return decodeURIComponent(str) |
|
} catch (err) { |
|
return String.fromCharCode(0xFFFD) // UTF 8 invalid char |
|
} |
|
} |
|
|
|
|
|
function verifuint (value, max) { |
|
assert(typeof value === 'number', 'cannot write a non-number as a number') |
|
assert(value >= 0, 'specified a negative value for writing an unsigned value') |
|
assert(value <= max, 'value is larger than maximum value for type') |
|
assert(Math.floor(value) === value, 'value has a fractional component') |
|
} |
|
|
|
function verifsint (value, max, min) { |
|
assert(typeof value === 'number', 'cannot write a non-number as a number') |
|
assert(value <= max, 'value larger than maximum allowed value') |
|
assert(value >= min, 'value smaller than minimum allowed value') |
|
assert(Math.floor(value) === value, 'value has a fractional component') |
|
} |
|
|
|
function verifIEEE754 (value, max, min) { |
|
assert(typeof value === 'number', 'cannot write a non-number as a number') |
|
assert(value <= max, 'value larger than maximum allowed value') |
|
assert(value >= min, 'value smaller than minimum allowed value') |
|
} |
|
|
|
function assert (test, message) { |
|
if (!test) throw new Error(message || 'Failed assertion') |
|
} |
|
|
|
},{"base64-js":3,"ieee754":4}],3:[function(require,module,exports){ |
|
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
|
|
;(function (exports) { |
|
'use strict'; |
|
|
|
var Arr = (typeof Uint8Array !== 'undefined') |
|
? Uint8Array |
|
: Array |
|
|
|
var PLUS = '+'.charCodeAt(0) |
|
var SLASH = '/'.charCodeAt(0) |
|
var NUMBER = '0'.charCodeAt(0) |
|
var LOWER = 'a'.charCodeAt(0) |
|
var UPPER = 'A'.charCodeAt(0) |
|
|
|
function decode (elt) { |
|
var code = elt.charCodeAt(0) |
|
if (code === PLUS) |
|
return 62 // '+' |
|
if (code === SLASH) |
|
return 63 // '/' |
|
if (code < NUMBER) |
|
return -1 //no match |
|
if (code < NUMBER + 10) |
|
return code - NUMBER + 26 + 26 |
|
if (code < UPPER + 26) |
|
return code - UPPER |
|
if (code < LOWER + 26) |
|
return code - LOWER + 26 |
|
} |
|
|
|
function b64ToByteArray (b64) { |
|
var i, j, l, tmp, placeHolders, arr |
|
|
|
if (b64.length % 4 > 0) { |
|
throw new Error('Invalid string. Length must be a multiple of 4') |
|
} |
|
|
|
var len = b64.length |
|
placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 |
|
|
|
arr = new Arr(b64.length * 3 / 4 - placeHolders) |
|
|
|
l = placeHolders > 0 ? b64.length - 4 : b64.length |
|
|
|
var L = 0 |
|
|
|
function push (v) { |
|
arr[L++] = v |
|
} |
|
|
|
for (i = 0, j = 0; i < l; i += 4, j += 3) { |
|
tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) |
|
push((tmp & 0xFF0000) >> 16) |
|
push((tmp & 0xFF00) >> 8) |
|
push(tmp & 0xFF) |
|
} |
|
|
|
if (placeHolders === 2) { |
|
tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) |
|
push(tmp & 0xFF) |
|
} else if (placeHolders === 1) { |
|
tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) |
|
push((tmp >> 8) & 0xFF) |
|
push(tmp & 0xFF) |
|
} |
|
|
|
return arr |
|
} |
|
|
|
function uint8ToBase64 (uint8) { |
|
var i, |
|
extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes |
|
output = "", |
|
temp, length |
|
|
|
function encode (num) { |
|
return lookup.charAt(num) |
|
} |
|
|
|
function tripletToBase64 (num) { |
|
return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) |
|
} |
|
|
|
for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { |
|
temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) |
|
output += tripletToBase64(temp) |
|
} |
|
|
|
switch (extraBytes) { |
|
case 1: |
|
temp = uint8[uint8.length - 1] |
|
output += encode(temp >> 2) |
|
output += encode((temp << 4) & 0x3F) |
|
output += '==' |
|
break |
|
case 2: |
|
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) |
|
output += encode(temp >> 10) |
|
output += encode((temp >> 4) & 0x3F) |
|
output += encode((temp << 2) & 0x3F) |
|
output += '=' |
|
break |
|
} |
|
|
|
return output |
|
} |
|
|
|
exports.toByteArray = b64ToByteArray |
|
exports.fromByteArray = uint8ToBase64 |
|
}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) |
|
|
|
},{}],4:[function(require,module,exports){ |
|
exports.read = function(buffer, offset, isLE, mLen, nBytes) { |
|
var e, m, |
|
eLen = nBytes * 8 - mLen - 1, |
|
eMax = (1 << eLen) - 1, |
|
eBias = eMax >> 1, |
|
nBits = -7, |
|
i = isLE ? (nBytes - 1) : 0, |
|
d = isLE ? -1 : 1, |
|
s = buffer[offset + i]; |
|
|
|
i += d; |
|
|
|
e = s & ((1 << (-nBits)) - 1); |
|
s >>= (-nBits); |
|
nBits += eLen; |
|
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); |
|
|
|
m = e & ((1 << (-nBits)) - 1); |
|
e >>= (-nBits); |
|
nBits += mLen; |
|
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); |
|
|
|
if (e === 0) { |
|
e = 1 - eBias; |
|
} else if (e === eMax) { |
|
return m ? NaN : ((s ? -1 : 1) * Infinity); |
|
} else { |
|
m = m + Math.pow(2, mLen); |
|
e = e - eBias; |
|
} |
|
return (s ? -1 : 1) * m * Math.pow(2, e - mLen); |
|
}; |
|
|
|
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) { |
|
var e, m, c, |
|
eLen = nBytes * 8 - mLen - 1, |
|
eMax = (1 << eLen) - 1, |
|
eBias = eMax >> 1, |
|
rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), |
|
i = isLE ? 0 : (nBytes - 1), |
|
d = isLE ? 1 : -1, |
|
s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; |
|
|
|
value = Math.abs(value); |
|
|
|
if (isNaN(value) || value === Infinity) { |
|
m = isNaN(value) ? 1 : 0; |
|
e = eMax; |
|
} else { |
|
e = Math.floor(Math.log(value) / Math.LN2); |
|
if (value * (c = Math.pow(2, -e)) < 1) { |
|
e--; |
|
c *= 2; |
|
} |
|
if (e + eBias >= 1) { |
|
value += rt / c; |
|
} else { |
|
value += rt * Math.pow(2, 1 - eBias); |
|
} |
|
if (value * c >= 2) { |
|
e++; |
|
c /= 2; |
|
} |
|
|
|
if (e + eBias >= eMax) { |
|
m = 0; |
|
e = eMax; |
|
} else if (e + eBias >= 1) { |
|
m = (value * c - 1) * Math.pow(2, mLen); |
|
e = e + eBias; |
|
} else { |
|
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); |
|
e = 0; |
|
} |
|
} |
|
|
|
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); |
|
|
|
e = (e << mLen) | m; |
|
eLen += mLen; |
|
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); |
|
|
|
buffer[offset + i - d] |= s * 128; |
|
}; |
|
|
|
},{}],5:[function(require,module,exports){ |
|
var Buffer = require('buffer').Buffer; |
|
var intSize = 4; |
|
var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0); |
|
var chrsz = 8; |
|
|
|
function toArray(buf, bigEndian) { |
|
if ((buf.length % intSize) !== 0) { |
|
var len = buf.length + (intSize - (buf.length % intSize)); |
|
buf = Buffer.concat([buf, zeroBuffer], len); |
|
} |
|
|
|
var arr = []; |
|
var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE; |
|
for (var i = 0; i < buf.length; i += intSize) { |
|
arr.push(fn.call(buf, i)); |
|
} |
|
return arr; |
|
} |
|
|
|
function toBuffer(arr, size, bigEndian) { |
|
var buf = new Buffer(size); |
|
var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE; |
|
for (var i = 0; i < arr.length; i++) { |
|
fn.call(buf, arr[i], i * 4, true); |
|
} |
|
return buf; |
|
} |
|
|
|
function hash(buf, fn, hashSize, bigEndian) { |
|
if (!Buffer.isBuffer(buf)) buf = new Buffer(buf); |
|
var arr = fn(toArray(buf, bigEndian), buf.length * chrsz); |
|
return toBuffer(arr, hashSize, bigEndian); |
|
} |
|
|
|
module.exports = { hash: hash }; |
|
|
|
},{"buffer":2}],6:[function(require,module,exports){ |
|
var Buffer = require('buffer').Buffer |
|
var sha = require('./sha') |
|
var sha256 = require('./sha256') |
|
var rng = require('./rng') |
|
var md5 = require('./md5') |
|
|
|
var algorithms = { |
|
sha1: sha, |
|
sha256: sha256, |
|
md5: md5 |
|
} |
|
|
|
var blocksize = 64 |
|
var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0) |
|
function hmac(fn, key, data) { |
|
if(!Buffer.isBuffer(key)) key = new Buffer(key) |
|
if(!Buffer.isBuffer(data)) data = new Buffer(data) |
|
|
|
if(key.length > blocksize) { |
|
key = fn(key) |
|
} else if(key.length < blocksize) { |
|
key = Buffer.concat([key, zeroBuffer], blocksize) |
|
} |
|
|
|
var ipad = new Buffer(blocksize), opad = new Buffer(blocksize) |
|
for(var i = 0; i < blocksize; i++) { |
|
ipad[i] = key[i] ^ 0x36 |
|
opad[i] = key[i] ^ 0x5C |
|
} |
|
|
|
var hash = fn(Buffer.concat([ipad, data])) |
|
return fn(Buffer.concat([opad, hash])) |
|
} |
|
|
|
function hash(alg, key) { |
|
alg = alg || 'sha1' |
|
var fn = algorithms[alg] |
|
var bufs = [] |
|
var length = 0 |
|
if(!fn) error('algorithm:', alg, 'is not yet supported') |
|
return { |
|
update: function (data) { |
|
if(!Buffer.isBuffer(data)) data = new Buffer(data) |
|
|
|
bufs.push(data) |
|
length += data.length |
|
return this |
|
}, |
|
digest: function (enc) { |
|
var buf = Buffer.concat(bufs) |
|
var r = key ? hmac(fn, key, buf) : fn(buf) |
|
bufs = null |
|
return enc ? r.toString(enc) : r |
|
} |
|
} |
|
} |
|
|
|
function error () { |
|
var m = [].slice.call(arguments).join(' ') |
|
throw new Error([ |
|
m, |
|
'we accept pull requests', |
|
'http://github.com/dominictarr/crypto-browserify' |
|
].join('\n')) |
|
} |
|
|
|
exports.createHash = function (alg) { return hash(alg) } |
|
exports.createHmac = function (alg, key) { return hash(alg, key) } |
|
exports.randomBytes = function(size, callback) { |
|
if (callback && callback.call) { |
|
try { |
|
callback.call(this, undefined, new Buffer(rng(size))) |
|
} catch (err) { callback(err) } |
|
} else { |
|
return new Buffer(rng(size)) |
|
} |
|
} |
|
|
|
function each(a, f) { |
|
for(var i in a) |
|
f(a[i], i) |
|
} |
|
|
|
each(['createCredentials' |
|
, 'createCipher' |
|
, 'createCipheriv' |
|
, 'createDecipher' |
|
, 'createDecipheriv' |
|
, 'createSign' |
|
, 'createVerify' |
|
, 'createDiffieHellman' |
|
, 'pbkdf2'], function (name) { |
|
exports[name] = function () { |
|
error('sorry,', name, 'is not implemented yet') |
|
} |
|
}) |
|
|
|
},{"./md5":7,"./rng":8,"./sha":9,"./sha256":10,"buffer":2}],7:[function(require,module,exports){ |
|
|
|
|
|
var helpers = require('./helpers'); |
|
|
|
|
|
function md5_vm_test() |
|
{ |
|
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; |
|
} |
|
|
|
|
|
function core_md5(x, len) |
|
{ |
|
|
|
x[len >> 5] |= 0x80 << ((len) % 32); |
|
x[(((len + 64) >>> 9) << 4) + 14] = len; |
|
|
|
var a = 1732584193; |
|
var b = -271733879; |
|
var c = -1732584194; |
|
var d = 271733878; |
|
|
|
for(var i = 0; i < x.length; i += 16) |
|
{ |
|
var olda = a; |
|
var oldb = b; |
|
var oldc = c; |
|
var oldd = d; |
|
|
|
a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); |
|
d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); |
|
c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); |
|
b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); |
|
a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); |
|
d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); |
|
c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); |
|
b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); |
|
a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); |
|
d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); |
|
c = md5_ff(c, d, a, b, x[i+10], 17, -42063); |
|
b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); |
|
a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); |
|
d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); |
|
c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); |
|
b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); |
|
|
|
a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); |
|
d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); |
|
c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); |
|
b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); |
|
a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); |
|
d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); |
|
c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); |
|
b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); |
|
a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); |
|
d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); |
|
c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); |
|
b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); |
|
a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); |
|
d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); |
|
c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); |
|
b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); |
|
|
|
a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); |
|
d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); |
|
c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); |
|
b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); |
|
a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); |
|
d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); |
|
c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); |
|
b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); |
|
a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); |
|
d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); |
|
c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); |
|
b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); |
|
a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); |
|
d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); |
|
c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); |
|
b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); |
|
|
|
a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); |
|
d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); |
|
c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); |
|
b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); |
|
a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); |
|
d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); |
|
c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); |
|
b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); |
|
a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); |
|
d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); |
|
c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); |
|
b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); |
|
a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); |
|
d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); |
|
c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); |
|
b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); |
|
|
|
a = safe_add(a, olda); |
|
b = safe_add(b, oldb); |
|
c = safe_add(c, oldc); |
|
d = safe_add(d, oldd); |
|
} |
|
return Array(a, b, c, d); |
|
|
|
} |
|
|
|
|
|
function md5_cmn(q, a, b, x, s, t) |
|
{ |
|
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); |
|
} |
|
function md5_ff(a, b, c, d, x, s, t) |
|
{ |
|
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); |
|
} |
|
function md5_gg(a, b, c, d, x, s, t) |
|
{ |
|
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); |
|
} |
|
function md5_hh(a, b, c, d, x, s, t) |
|
{ |
|
return md5_cmn(b ^ c ^ d, a, b, x, s, t); |
|
} |
|
function md5_ii(a, b, c, d, x, s, t) |
|
{ |
|
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); |
|
} |
|
|
|
|
|
function safe_add(x, y) |
|
{ |
|
var lsw = (x & 0xFFFF) + (y & 0xFFFF); |
|
var msw = (x >> 16) + (y >> 16) + (lsw >> 16); |
|
return (msw << 16) | (lsw & 0xFFFF); |
|
} |
|
|
|
|
|
function bit_rol(num, cnt) |
|
{ |
|
return (num << cnt) | (num >>> (32 - cnt)); |
|
} |
|
|
|
module.exports = function md5(buf) { |
|
return helpers.hash(buf, core_md5, 16); |
|
}; |
|
|
|
},{"./helpers":5}],8:[function(require,module,exports){ |
|
(function() { |
|
var _global = this; |
|
|
|
var mathRNG, whatwgRNG; |
|
|
|
mathRNG = function(size) { |
|
var bytes = new Array(size); |
|
var r; |
|
|
|
for (var i = 0, r; i < size; i++) { |
|
if ((i & 0x03) == 0) r = Math.random() * 0x100000000; |
|
bytes[i] = r >>> ((i & 0x03) << 3) & 0xff; |
|
} |
|
|
|
return bytes; |
|
} |
|
|
|
if (_global.crypto && crypto.getRandomValues) { |
|
whatwgRNG = function(size) { |
|
var bytes = new Uint8Array(size); |
|
crypto.getRandomValues(bytes); |
|
return bytes; |
|
} |
|
} |
|
|
|
module.exports = whatwgRNG || mathRNG; |
|
|
|
}()) |
|
|
|
},{}],9:[function(require,module,exports){ |
|
|
|
|
|
var helpers = require('./helpers'); |
|
|
|
|
|
function core_sha1(x, len) |
|
{ |
|
|
|
x[len >> 5] |= 0x80 << (24 - len % 32); |
|
x[((len + 64 >> 9) << 4) + 15] = len; |
|
|
|
var w = Array(80); |
|
var a = 1732584193; |
|
var b = -271733879; |
|
var c = -1732584194; |
|
var d = 271733878; |
|
var e = -1009589776; |
|
|
|
for(var i = 0; i < x.length; i += 16) |
|
{ |
|
var olda = a; |
|
var oldb = b; |
|
var oldc = c; |
|
var oldd = d; |
|
var olde = e; |
|
|
|
for(var j = 0; j < 80; j++) |
|
{ |
|
if(j < 16) w[j] = x[i + j]; |
|
else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); |
|
var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), |
|
safe_add(safe_add(e, w[j]), sha1_kt(j))); |
|
e = d; |
|
d = c; |
|
c = rol(b, 30); |
|
b = a; |
|
a = t; |
|
} |
|
|
|
a = safe_add(a, olda); |
|
b = safe_add(b, oldb); |
|
c = safe_add(c, oldc); |
|
d = safe_add(d, oldd); |
|
e = safe_add(e, olde); |
|
} |
|
return Array(a, b, c, d, e); |
|
|
|
} |
|
|
|
|
|
function sha1_ft(t, b, c, d) |
|
{ |
|
if(t < 20) return (b & c) | ((~b) & d); |
|
if(t < 40) return b ^ c ^ d; |
|
if(t < 60) return (b & c) | (b & d) | (c & d); |
|
return b ^ c ^ d; |
|
} |
|
|
|
|
|
function sha1_kt(t) |
|
{ |
|
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : |
|
(t < 60) ? -1894007588 : -899497514; |
|
} |
|
|
|
|
|
function safe_add(x, y) |
|
{ |
|
var lsw = (x & 0xFFFF) + (y & 0xFFFF); |
|
var msw = (x >> 16) + (y >> 16) + (lsw >> 16); |
|
return (msw << 16) | (lsw & 0xFFFF); |
|
} |
|
|
|
|
|
function rol(num, cnt) |
|
{ |
|
return (num << cnt) | (num >>> (32 - cnt)); |
|
} |
|
|
|
module.exports = function sha1(buf) { |
|
return helpers.hash(buf, core_sha1, 20, true); |
|
}; |
|
|
|
},{"./helpers":5}],10:[function(require,module,exports){ |
|
|
|
|
|
|
|
var helpers = require('./helpers'); |
|
|
|
var safe_add = function(x, y) { |
|
var lsw = (x & 0xFFFF) + (y & 0xFFFF); |
|
var msw = (x >> 16) + (y >> 16) + (lsw >> 16); |
|
return (msw << 16) | (lsw & 0xFFFF); |
|
}; |
|
|
|
var S = function(X, n) { |
|
return (X >>> n) | (X << (32 - n)); |
|
}; |
|
|
|
var R = function(X, n) { |
|
return (X >>> n); |
|
}; |
|
|
|
var Ch = function(x, y, z) { |
|
return ((x & y) ^ ((~x) & z)); |
|
}; |
|
|
|
var Maj = function(x, y, z) { |
|
return ((x & y) ^ (x & z) ^ (y & z)); |
|
}; |
|
|
|
var Sigma0256 = function(x) { |
|
return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); |
|
}; |
|
|
|
var Sigma1256 = function(x) { |
|
return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); |
|
}; |
|
|
|
var Gamma0256 = function(x) { |
|
return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); |
|
}; |
|
|
|
var Gamma1256 = function(x) { |
|
return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); |
|
}; |
|
|
|
var core_sha256 = function(m, l) { |
|
var K = new Array(0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0xFC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x6CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2); |
|
var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19); |
|
var W = new Array(64); |
|
var a, b, c, d, e, f, g, h, i, j; |
|
var T1, T2; |
|
|
|
m[l >> 5] |= 0x80 << (24 - l % 32); |
|
m[((l + 64 >> 9) << 4) + 15] = l; |
|
for (var i = 0; i < m.length; i += 16) { |
|
a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7]; |
|
for (var j = 0; j < 64; j++) { |
|
if (j < 16) { |
|
W[j] = m[j + i]; |
|
} else { |
|
W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]); |
|
} |
|
T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]); |
|
T2 = safe_add(Sigma0256(a), Maj(a, b, c)); |
|
h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2); |
|
} |
|
HASH[0] = safe_add(a, HASH[0]); HASH[1] = safe_add(b, HASH[1]); HASH[2] = safe_add(c, HASH[2]); HASH[3] = safe_add(d, HASH[3]); |
|
HASH[4] = safe_add(e, HASH[4]); HASH[5] = safe_add(f, HASH[5]); HASH[6] = safe_add(g, HASH[6]); HASH[7] = safe_add(h, HASH[7]); |
|
} |
|
return HASH; |
|
}; |
|
|
|
module.exports = function sha256(buf) { |
|
return helpers.hash(buf, core_sha256, 32, true); |
|
}; |
|
|
|
},{"./helpers":5}],11:[function(require,module,exports){ |
|
|
|
function EventEmitter() { |
|
this._events = this._events || {}; |
|
this._maxListeners = this._maxListeners || undefined; |
|
} |
|
module.exports = EventEmitter; |
|
|
|
EventEmitter.EventEmitter = EventEmitter; |
|
|
|
EventEmitter.prototype._events = undefined; |
|
EventEmitter.prototype._maxListeners = undefined; |
|
|
|
EventEmitter.defaultMaxListeners = 10; |
|
|
|
EventEmitter.prototype.setMaxListeners = function(n) { |
|
if (!isNumber(n) || n < 0 || isNaN(n)) |
|
throw TypeError('n must be a positive number'); |
|
this._maxListeners = n; |
|
return this; |
|
}; |
|
|
|
EventEmitter.prototype.emit = function(type) { |
|
var er, handler, len, args, i, listeners; |
|
|
|
if (!this._events) |
|
this._events = {}; |
|
|
|
if (type === 'error') { |
|
if (!this._events.error || |
|
(isObject(this._events.error) && !this._events.error.length)) { |
|
er = arguments[1]; |
|
if (er instanceof Error) { |
|
throw er; // Unhandled 'error' event |
|
} else { |
|
throw TypeError('Uncaught, unspecified "error" event.'); |
|
} |
|
return false; |
|
} |
|
} |
|
|
|
handler = this._events[type]; |
|
|
|
if (isUndefined(handler)) |
|
return false; |
|
|
|
if (isFunction(handler)) { |
|
switch (arguments.length) { |
|
case 1: |
|
handler.call(this); |
|
break; |
|
case 2: |
|
handler.call(this, arguments[1]); |
|
break; |
|
case 3: |
|
handler.call(this, arguments[1], arguments[2]); |
|
break; |
|
default: |
|
len = arguments.length; |
|
args = new Array(len - 1); |
|
for (i = 1; i < len; i++) |
|
args[i - 1] = arguments[i]; |
|
handler.apply(this, args); |
|
} |
|
} else if (isObject(handler)) { |
|
len = arguments.length; |
|
args = new Array(len - 1); |
|
for (i = 1; i < len; i++) |
|
args[i - 1] = arguments[i]; |
|
|
|
listeners = handler.slice(); |
|
len = listeners.length; |
|
for (i = 0; i < len; i++) |
|
listeners[i].apply(this, args); |
|
} |
|
|
|
return true; |
|
}; |
|
|
|
EventEmitter.prototype.addListener = function(type, listener) { |
|
var m; |
|
|
|
if (!isFunction(listener)) |
|
throw TypeError('listener must be a function'); |
|
|
|
if (!this._events) |
|
this._events = {}; |
|
|
|
if (this._events.newListener) |
|
this.emit('newListener', type, |
|
isFunction(listener.listener) ? |
|
listener.listener : listener); |
|
|
|
if (!this._events[type]) |
|
this._events[type] = listener; |
|
else if (isObject(this._events[type])) |
|
this._events[type].push(listener); |
|
else |
|
this._events[type] = [this._events[type], listener]; |
|
|
|
if (isObject(this._events[type]) && !this._events[type].warned) { |
|
var m; |
|
if (!isUndefined(this._maxListeners)) { |
|
m = this._maxListeners; |
|
} else { |
|
m = EventEmitter.defaultMaxListeners; |
|
} |
|
|
|
if (m && m > 0 && this._events[type].length > m) { |
|
this._events[type].warned = true; |
|
console.error('(node) warning: possible EventEmitter memory ' + |
|
'leak detected. %d listeners added. ' + |
|
'Use emitter.setMaxListeners() to increase limit.', |
|
this._events[type].length); |
|
if (typeof console.trace === 'function') { |
|
console.trace(); |
|
} |
|
} |
|
} |
|
|
|
return this; |
|
}; |
|
|
|
EventEmitter.prototype.on = EventEmitter.prototype.addListener; |
|
|
|
EventEmitter.prototype.once = function(type, listener) { |
|
if (!isFunction(listener)) |
|
throw TypeError('listener must be a function'); |
|
|
|
var fired = false; |
|
|
|
function g() { |
|
this.removeListener(type, g); |
|
|
|
if (!fired) { |
|
fired = true; |
|
listener.apply(this, arguments); |
|
} |
|
} |
|
|
|
g.listener = listener; |
|
this.on(type, g); |
|
|
|
return this; |
|
}; |
|
|
|
EventEmitter.prototype.removeListener = function(type, listener) { |
|
var list, position, length, i; |
|
|
|
if (!isFunction(listener)) |
|
throw TypeError('listener must be a function'); |
|
|
|
if (!this._events || !this._events[type]) |
|
return this; |
|
|
|
list = this._events[type]; |
|
length = list.length; |
|
position = -1; |
|
|
|
if (list === listener || |
|
(isFunction(list.listener) && list.listener === listener)) { |
|
delete this._events[type]; |
|
if (this._events.removeListener) |
|
this.emit('removeListener', type, listener); |
|
|
|
} else if (isObject(list)) { |
|
for (i = length; i-- > 0;) { |
|
if (list[i] === listener || |
|
(list[i].listener && list[i].listener === listener)) { |
|
position = i; |
|
break; |
|
} |
|
} |
|
|
|
if (position < 0) |
|
return this; |
|
|
|
if (list.length === 1) { |
|
list.length = 0; |
|
delete this._events[type]; |
|
} else { |
|
list.splice(position, 1); |
|
} |
|
|
|
if (this._events.removeListener) |
|
this.emit('removeListener', type, listener); |
|
} |
|
|
|
return this; |
|
}; |
|
|
|
EventEmitter.prototype.removeAllListeners = function(type) { |
|
var key, listeners; |
|
|
|
if (!this._events) |
|
return this; |
|
|
|
if (!this._events.removeListener) { |
|
if (arguments.length === 0) |
|
this._events = {}; |
|
else if (this._events[type]) |
|
delete this._events[type]; |
|
return this; |
|
} |
|
|
|
if (arguments.length === 0) { |
|
for (key in this._events) { |
|
if (key === 'removeListener') continue; |
|
this.removeAllListeners(key); |
|
} |
|
this.removeAllListeners('removeListener'); |
|
this._events = {}; |
|
return this; |
|
} |
|
|
|
listeners = this._events[type]; |
|
|
|
if (isFunction(listeners)) { |
|
this.removeListener(type, listeners); |
|
} else { |
|
while (listeners.length) |
|
this.removeListener(type, listeners[listeners.length - 1]); |
|
} |
|
delete this._events[type]; |
|
|
|
return this; |
|
}; |
|
|
|
EventEmitter.prototype.listeners = function(type) { |
|
var ret; |
|
if (!this._events || !this._events[type]) |
|
ret = []; |
|
else if (isFunction(this._events[type])) |
|
ret = [this._events[type]]; |
|
else |
|
ret = this._events[type].slice(); |
|
return ret; |
|
}; |
|
|
|
EventEmitter.listenerCount = function(emitter, type) { |
|
var ret; |
|
if (!emitter._events || !emitter._events[type]) |
|
ret = 0; |
|
else if (isFunction(emitter._events[type])) |
|
ret = 1; |
|
else |
|
ret = emitter._events[type].length; |
|
return ret; |
|
}; |
|
|
|
function isFunction(arg) { |
|
return typeof arg === 'function'; |
|
} |
|
|
|
function isNumber(arg) { |
|
return typeof arg === 'number'; |
|
} |
|
|
|
function isObject(arg) { |
|
return typeof arg === 'object' && arg !== null; |
|
} |
|
|
|
function isUndefined(arg) { |
|
return arg === void 0; |
|
} |
|
|
|
},{}],12:[function(require,module,exports){ |
|
if (typeof Object.create === 'function') { |
|
module.exports = function inherits(ctor, superCtor) { |
|
ctor.super_ = superCtor |
|
ctor.prototype = Object.create(superCtor.prototype, { |
|
constructor: { |
|
value: ctor, |
|
enumerable: false, |
|
writable: true, |
|
configurable: true |
|
} |
|
}); |
|
}; |
|
} else { |
|
module.exports = function inherits(ctor, superCtor) { |
|
ctor.super_ = superCtor |
|
var TempCtor = function () {} |
|
TempCtor.prototype = superCtor.prototype |
|
ctor.prototype = new TempCtor() |
|
ctor.prototype.constructor = ctor |
|
} |
|
} |
|
|
|
},{}],13:[function(require,module,exports){ |
|
|
|
var process = module.exports = {}; |
|
|
|
process.nextTick = (function () { |
|
var canSetImmediate = typeof window !== 'undefined' |
|
&& window.setImmediate; |
|
var canPost = typeof window !== 'undefined' |
|
&& window.postMessage && window.addEventListener |
|
; |
|
|
|
if (canSetImmediate) { |
|
return function (f) { return window.setImmediate(f) }; |
|
} |
|
|
|
if (canPost) { |
|
var queue = []; |
|
window.addEventListener('message', function (ev) { |
|
var source = ev.source; |
|
if ((source === window || source === null) && ev.data === 'process-tick') { |
|
ev.stopPropagation(); |
|
if (queue.length > 0) { |
|
var fn = queue.shift(); |
|
fn(); |
|
} |
|
} |
|
}, true); |
|
|
|
return function nextTick(fn) { |
|
queue.push(fn); |
|
window.postMessage('process-tick', '*'); |
|
}; |
|
} |
|
|
|
return function nextTick(fn) { |
|
setTimeout(fn, 0); |
|
}; |
|
})(); |
|
|
|
process.title = 'browser'; |
|
process.browser = true; |
|
process.env = {}; |
|
process.argv = []; |
|
|
|
function noop() {} |
|
|
|
process.on = noop; |
|
process.addListener = noop; |
|
process.once = noop; |
|
process.off = noop; |
|
process.removeListener = noop; |
|
process.removeAllListeners = noop; |
|
process.emit = noop; |
|
|
|
process.binding = function (name) { |
|
throw new Error('process.binding is not supported'); |
|
} |
|
|
|
process.cwd = function () { return '/' }; |
|
process.chdir = function (dir) { |
|
throw new Error('process.chdir is not supported'); |
|
}; |
|
|
|
},{}],14:[function(require,module,exports){ |
|
(function (global){ |
|
|
|
;(function(root) { |
|
|
|
|
|
var freeExports = typeof exports == 'object' && exports; |
|
var freeModule = typeof module == 'object' && module && |
|
module.exports == freeExports && module; |
|
var freeGlobal = typeof global == 'object' && global; |
|
if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { |
|
root = freeGlobal; |
|
} |
|
|
|
|
|
var punycode, |
|
|
|
|
|
maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 |
|
|
|
|
|
base = 36, |
|
tMin = 1, |
|
tMax = 26, |
|
skew = 38, |
|
damp = 700, |
|
initialBias = 72, |
|
initialN = 128, // 0x80 |
|
delimiter = '-', // '\x2D' |
|
|
|
|
|
regexPunycode = /^xn--/, |
|
regexNonASCII = /[^ -~]/, // unprintable ASCII chars + non-ASCII chars |
|
regexSeparators = /\x2E|\u3002|\uFF0E|\uFF61/g, // RFC 3490 separators |
|
|
|
|
|
errors = { |
|
'overflow': 'Overflow: input needs wider integers to process', |
|
'not-basic': 'Illegal input >= 0x80 (not a basic code point)', |
|
'invalid-input': 'Invalid input' |
|
}, |
|
|
|
|
|
baseMinusTMin = base - tMin, |
|
floor = Math.floor, |
|
stringFromCharCode = String.fromCharCode, |
|
|
|
|
|
key; |
|
|
|
|
|
|
|
|
|
function error(type) { |
|
throw RangeError(errors[type]); |
|
} |
|
|
|
|
|
function map(array, fn) { |
|
var length = array.length; |
|
while (length--) { |
|
array[length] = fn(array[length]); |
|
} |
|
return array; |
|
} |
|
|
|
|
|
function mapDomain(string, fn) { |
|
return map(string.split(regexSeparators), fn).join('.'); |
|
} |
|
|
|
|
|
function ucs2decode(string) { |
|
var output = [], |
|
counter = 0, |
|
length = string.length, |
|
value, |
|
extra; |
|
while (counter < length) { |
|
value = string.charCodeAt(counter++); |
|
if (value >= 0xD800 && value <= 0xDBFF && counter < length) { |
|
extra = string.charCodeAt(counter++); |
|
if ((extra & 0xFC00) == 0xDC00) { // low surrogate |
|
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); |
|
} else { |
|
output.push(value); |
|
counter--; |
|
} |
|
} else { |
|
output.push(value); |
|
} |
|
} |
|
return output; |
|
} |
|
|
|
|
|
function ucs2encode(array) { |
|
return map(array, function(value) { |
|
var output = ''; |
|
if (value > 0xFFFF) { |
|
value -= 0x10000; |
|
output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); |
|
value = 0xDC00 | value & 0x3FF; |
|
} |
|
output += stringFromCharCode(value); |
|
return output; |
|
}).join(''); |
|
} |
|
|
|
|
|
function basicToDigit(codePoint) { |
|
if (codePoint - 48 < 10) { |
|
return codePoint - 22; |
|
} |
|
if (codePoint - 65 < 26) { |
|
return codePoint - 65; |
|
} |
|
if (codePoint - 97 < 26) { |
|
return codePoint - 97; |
|
} |
|
return base; |
|
} |
|
|
|
|
|
function digitToBasic(digit, flag) { |
|
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); |
|
} |
|
|
|
|
|
function adapt(delta, numPoints, firstTime) { |
|
var k = 0; |
|
delta = firstTime ? floor(delta / damp) : delta >> 1; |
|
delta += floor(delta / numPoints); |
|
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { |
|
delta = floor(delta / baseMinusTMin); |
|
} |
|
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); |
|
} |
|
|
|
|
|
function decode(input) { |
|
var output = [], |
|
inputLength = input.length, |
|
out, |
|
i = 0, |
|
n = initialN, |
|
bias = initialBias, |
|
basic, |
|
j, |
|
index, |
|
oldi, |
|
w, |
|
k, |
|
digit, |
|
t, |
|
|
|
baseMinusT; |
|
|
|
|
|
basic = input.lastIndexOf(delimiter); |
|
if (basic < 0) { |
|
basic = 0; |
|
} |
|
|
|
for (j = 0; j < basic; ++j) { |
|
if (input.charCodeAt(j) >= 0x80) { |
|
error('not-basic'); |
|
} |
|
output.push(input.charCodeAt(j)); |
|
} |
|
|
|
|
|
for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { |
|
|
|
for (oldi = i, w = 1, k = base; /* no condition */; k += base) { |
|
|
|
if (index >= inputLength) { |
|
error('invalid-input'); |
|
} |
|
|
|
digit = basicToDigit(input.charCodeAt(index++)); |
|
|
|
if (digit >= base || digit > floor((maxInt - i) / w)) { |
|
error('overflow'); |
|
} |
|
|
|
i += digit * w; |
|
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); |
|
|
|
if (digit < t) { |
|
break; |
|
} |
|
|
|
baseMinusT = base - t; |
|
if (w > floor(maxInt / baseMinusT)) { |
|
error('overflow'); |
|
} |
|
|
|
w *= baseMinusT; |
|
|
|
} |
|
|
|
out = output.length + 1; |
|
bias = adapt(i - oldi, out, oldi == 0); |
|
|
|
if (floor(i / out) > maxInt - n) { |
|
error('overflow'); |
|
} |
|
|
|
n += floor(i / out); |
|
i %= out; |
|
|
|
output.splice(i++, 0, n); |
|
|
|
} |
|
|
|
return ucs2encode(output); |
|
} |
|
|
|
|
|
function encode(input) { |
|
var n, |
|
delta, |
|
handledCPCount, |
|
basicLength, |
|
bias, |
|
j, |
|
m, |
|
q, |
|
k, |
|
t, |
|
currentValue, |
|
output = [], |
|
|
|
inputLength, |
|
|
|
handledCPCountPlusOne, |
|
baseMinusT, |
|
qMinusT; |
|
|
|
input = ucs2decode(input); |
|
|
|
inputLength = input.length; |
|
|
|
n = initialN; |
|
delta = 0; |
|
bias = initialBias; |
|
|
|
for (j = 0; j < inputLength; ++j) { |
|
currentValue = input[j]; |
|
if (currentValue < 0x80) { |
|
output.push(stringFromCharCode(currentValue)); |
|
} |
|
} |
|
|
|
handledCPCount = basicLength = output.length; |
|
|
|
|
|
if (basicLength) { |
|
output.push(delimiter); |
|
} |
|
|
|
while (handledCPCount < inputLength) { |
|
|
|
for (m = maxInt, j = 0; j < inputLength; ++j) { |
|
currentValue = input[j]; |
|
if (currentValue >= n && currentValue < m) { |
|
m = currentValue; |
|
} |
|
} |
|
|
|
handledCPCountPlusOne = handledCPCount + 1; |
|
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { |
|
error('overflow'); |
|
} |
|
|
|
delta += (m - n) * handledCPCountPlusOne; |
|
n = m; |
|
|
|
for (j = 0; j < inputLength; ++j) { |
|
currentValue = input[j]; |
|
|
|
if (currentValue < n && ++delta > maxInt) { |
|
error('overflow'); |
|
} |
|
|
|
if (currentValue == n) { |
|
for (q = delta, k = base; /* no condition */; k += base) { |
|
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); |
|
if (q < t) { |
|
break; |
|
} |
|
qMinusT = q - t; |
|
baseMinusT = base - t; |
|
output.push( |
|
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) |
|
); |
|
q = floor(qMinusT / baseMinusT); |
|
} |
|
|
|
output.push(stringFromCharCode(digitToBasic(q, 0))); |
|
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); |
|
delta = 0; |
|
++handledCPCount; |
|
} |
|
} |
|
|
|
++delta; |
|
++n; |
|
|
|
} |
|
return output.join(''); |
|
} |
|
|
|
|
|
function toUnicode(domain) { |
|
return mapDomain(domain, function(string) { |
|
return regexPunycode.test(string) |
|
? decode(string.slice(4).toLowerCase()) |
|
: string; |
|
}); |
|
} |
|
|
|
|
|
function toASCII(domain) { |
|
return mapDomain(domain, function(string) { |
|
return regexNonASCII.test(string) |
|
? 'xn--' + encode(string) |
|
: string; |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
punycode = { |
|
|
|
'version': '1.2.4', |
|
|
|
'ucs2': { |
|
'decode': ucs2decode, |
|
'encode': ucs2encode |
|
}, |
|
'decode': decode, |
|
'encode': encode, |
|
'toASCII': toASCII, |
|
'toUnicode': toUnicode |
|
}; |
|
|
|
|
|
if ( |
|
typeof define == 'function' && |
|
typeof define.amd == 'object' && |
|
define.amd |
|
) { |
|
define('punycode', function() { |
|
return punycode; |
|
}); |
|
} else if (freeExports && !freeExports.nodeType) { |
|
if (freeModule) { // in Node.js or RingoJS v0.8.0+ |
|
freeModule.exports = punycode; |
|
} else { // in Narwhal or RingoJS v0.7.0- |
|
for (key in punycode) { |
|
punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); |
|
} |
|
} |
|
} else { // in Rhino or a web browser |
|
root.punycode = punycode; |
|
} |
|
|
|
}(this)); |
|
|
|
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
|
},{}],15:[function(require,module,exports){ |
|
|
|
'use strict'; |
|
|
|
function hasOwnProperty(obj, prop) { |
|
return Object.prototype.hasOwnProperty.call(obj, prop); |
|
} |
|
|
|
module.exports = function(qs, sep, eq, options) { |
|
sep = sep || '&'; |
|
eq = eq || '='; |
|
var obj = {}; |
|
|
|
if (typeof qs !== 'string' || qs.length === 0) { |
|
return obj; |
|
} |
|
|
|
var regexp = /\+/g; |
|
qs = qs.split(sep); |
|
|
|
var maxKeys = 1000; |
|
if (options && typeof options.maxKeys === 'number') { |
|
maxKeys = options.maxKeys; |
|
} |
|
|
|
var len = qs.length; |
|
if (maxKeys > 0 && len > maxKeys) { |
|
len = maxKeys; |
|
} |
|
|
|
for (var i = 0; i < len; ++i) { |
|
var x = qs[i].replace(regexp, '%20'), |
|
idx = x.indexOf(eq), |
|
kstr, vstr, k, v; |
|
|
|
if (idx >= 0) { |
|
kstr = x.substr(0, idx); |
|
vstr = x.substr(idx + 1); |
|
} else { |
|
kstr = x; |
|
vstr = ''; |
|
} |
|
|
|
k = decodeURIComponent(kstr); |
|
v = decodeURIComponent(vstr); |
|
|
|
if (!hasOwnProperty(obj, k)) { |
|
obj[k] = v; |
|
} else if (isArray(obj[k])) { |
|
obj[k].push(v); |
|
} else { |
|
obj[k] = [obj[k], v]; |
|
} |
|
} |
|
|
|
return obj; |
|
}; |
|
|
|
var isArray = Array.isArray || function (xs) { |
|
return Object.prototype.toString.call(xs) === '[object Array]'; |
|
}; |
|
|
|
},{}],16:[function(require,module,exports){ |
|
|
|
'use strict'; |
|
|
|
var stringifyPrimitive = function(v) { |
|
switch (typeof v) { |
|
case 'string': |
|
return v; |
|
|
|
case 'boolean': |
|
return v ? 'true' : 'false'; |
|
|
|
case 'number': |
|
return isFinite(v) ? v : ''; |
|
|
|
default: |
|
return ''; |
|
} |
|
}; |
|
|
|
module.exports = function(obj, sep, eq, name) { |
|
sep = sep || '&'; |
|
eq = eq || '='; |
|
if (obj === null) { |
|
obj = undefined; |
|
} |
|
|
|
if (typeof obj === 'object') { |
|
return map(objectKeys(obj), function(k) { |
|
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; |
|
if (isArray(obj[k])) { |
|
return obj[k].map(function(v) { |
|
return ks + encodeURIComponent(stringifyPrimitive(v)); |
|
}).join(sep); |
|
} else { |
|
return ks + encodeURIComponent(stringifyPrimitive(obj[k])); |
|
} |
|
}).join(sep); |
|
|
|
} |
|
|
|
if (!name) return ''; |
|
return encodeURIComponent(stringifyPrimitive(name)) + eq + |
|
encodeURIComponent(stringifyPrimitive(obj)); |
|
}; |
|
|
|
var isArray = Array.isArray || function (xs) { |
|
return Object.prototype.toString.call(xs) === '[object Array]'; |
|
}; |
|
|
|
function map (xs, f) { |
|
if (xs.map) return xs.map(f); |
|
var res = []; |
|
for (var i = 0; i < xs.length; i++) { |
|
res.push(f(xs[i], i)); |
|
} |
|
return res; |
|
} |
|
|
|
var objectKeys = Object.keys || function (obj) { |
|
var res = []; |
|
for (var key in obj) { |
|
if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); |
|
} |
|
return res; |
|
}; |
|
|
|
},{}],17:[function(require,module,exports){ |
|
'use strict'; |
|
|
|
exports.decode = exports.parse = require('./decode'); |
|
exports.encode = exports.stringify = require('./encode'); |
|
|
|
},{"./decode":15,"./encode":16}],18:[function(require,module,exports){ |
|
|
|
var punycode = require('punycode'); |
|
|
|
exports.parse = urlParse; |
|
exports.resolve = urlResolve; |
|
exports.resolveObject = urlResolveObject; |
|
exports.format = urlFormat; |
|
|
|
exports.Url = Url; |
|
|
|
function Url() { |
|
this.protocol = null; |
|
this.slashes = null; |
|
this.auth = null; |
|
this.host = null; |
|
this.port = null; |
|
this.hostname = null; |
|
this.hash = null; |
|
this.search = null; |
|
this.query = null; |
|
this.pathname = null; |
|
this.path = null; |
|
this.href = null; |
|
} |
|
|
|
|
|
var protocolPattern = /^([a-z0-9.+-]+:)/i, |
|
portPattern = /:[0-9]*$/, |
|
|
|
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'], |
|
|
|
unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims), |
|
|
|
autoEscape = ['\''].concat(unwise), |
|
nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape), |
|
hostEndingChars = ['/', '?', '#'], |
|
hostnameMaxLen = 255, |
|
hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/, |
|
hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/, |
|
unsafeProtocol = { |
|
'javascript': true, |
|
'javascript:': true |
|
}, |
|
hostlessProtocol = { |
|
'javascript': true, |
|
'javascript:': true |
|
}, |
|
slashedProtocol = { |
|
'http': true, |
|
'https': true, |
|
'ftp': true, |
|
'gopher': true, |
|
'file': true, |
|
'http:': true, |
|
'https:': true, |
|
'ftp:': true, |
|
'gopher:': true, |
|
'file:': true |
|
}, |
|
querystring = require('querystring'); |
|
|
|
function urlParse(url, parseQueryString, slashesDenoteHost) { |
|
if (url && isObject(url) && url instanceof Url) return url; |
|
|
|
var u = new Url; |
|
u.parse(url, parseQueryString, slashesDenoteHost); |
|
return u; |
|
} |
|
|
|
Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { |
|
if (!isString(url)) { |
|
throw new TypeError("Parameter 'url' must be a string, not " + typeof url); |
|
} |
|
|
|
var rest = url; |
|
|
|
rest = rest.trim(); |
|
|
|
var proto = protocolPattern.exec(rest); |
|
if (proto) { |
|
proto = proto[0]; |
|
var lowerProto = proto.toLowerCase(); |
|
this.protocol = lowerProto; |
|
rest = rest.substr(proto.length); |
|
} |
|
|
|
if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { |
|
var slashes = rest.substr(0, 2) === '//'; |
|
if (slashes && !(proto && hostlessProtocol[proto])) { |
|
rest = rest.substr(2); |
|
this.slashes = true; |
|
} |
|
} |
|
|
|
if (!hostlessProtocol[proto] && |
|
(slashes || (proto && !slashedProtocol[proto]))) { |
|
|
|
|
|
|
|
var hostEnd = -1; |
|
for (var i = 0; i < hostEndingChars.length; i++) { |
|
var hec = rest.indexOf(hostEndingChars[i]); |
|
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) |
|
hostEnd = hec; |
|
} |
|
|
|
var auth, atSign; |
|
if (hostEnd === -1) { |
|
atSign = rest.lastIndexOf('@'); |
|
} else { |
|
atSign = rest.lastIndexOf('@', hostEnd); |
|
} |
|
|
|
if (atSign !== -1) { |
|
auth = rest.slice(0, atSign); |
|
rest = rest.slice(atSign + 1); |
|
this.auth = decodeURIComponent(auth); |
|
} |
|
|
|
hostEnd = -1; |
|
for (var i = 0; i < nonHostChars.length; i++) { |
|
var hec = rest.indexOf(nonHostChars[i]); |
|
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) |
|
hostEnd = hec; |
|
} |
|
if (hostEnd === -1) |
|
hostEnd = rest.length; |
|
|
|
this.host = rest.slice(0, hostEnd); |
|
rest = rest.slice(hostEnd); |
|
|
|
this.parseHost(); |
|
|
|
this.hostname = this.hostname || ''; |
|
|
|
var ipv6Hostname = this.hostname[0] === '[' && |
|
this.hostname[this.hostname.length - 1] === ']'; |
|
|
|
if (!ipv6Hostname) { |
|
var hostparts = this.hostname.split(/\./); |
|
for (var i = 0, l = hostparts.length; i < l; i++) { |
|
var part = hostparts[i]; |
|
if (!part) continue; |
|
if (!part.match(hostnamePartPattern)) { |
|
var newpart = ''; |
|
for (var j = 0, k = part.length; j < k; j++) { |
|
if (part.charCodeAt(j) > 127) { |
|
newpart += 'x'; |
|
} else { |
|
newpart += part[j]; |
|
} |
|
} |
|
if (!newpart.match(hostnamePartPattern)) { |
|
var validParts = hostparts.slice(0, i); |
|
var notHost = hostparts.slice(i + 1); |
|
var bit = part.match(hostnamePartStart); |
|
if (bit) { |
|
validParts.push(bit[1]); |
|
notHost.unshift(bit[2]); |
|
} |
|
if (notHost.length) { |
|
rest = '/' + notHost.join('.') + rest; |
|
} |
|
this.hostname = validParts.join('.'); |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
|
|
if (this.hostname.length > hostnameMaxLen) { |
|
this.hostname = ''; |
|
} else { |
|
this.hostname = this.hostname.toLowerCase(); |
|
} |
|
|
|
if (!ipv6Hostname) { |
|
var domainArray = this.hostname.split('.'); |
|
var newOut = []; |
|
for (var i = 0; i < domainArray.length; ++i) { |
|
var s = domainArray[i]; |
|
newOut.push(s.match(/[^A-Za-z0-9_-]/) ? |
|
'xn--' + punycode.encode(s) : s); |
|
} |
|
this.hostname = newOut.join('.'); |
|
} |
|
|
|
var p = this.port ? ':' + this.port : ''; |
|
var h = this.hostname || ''; |
|
this.host = h + p; |
|
this.href += this.host; |
|
|
|
if (ipv6Hostname) { |
|
this.hostname = this.hostname.substr(1, this.hostname.length - 2); |
|
if (rest[0] !== '/') { |
|
rest = '/' + rest; |
|
} |
|
} |
|
} |
|
|
|
if (!unsafeProtocol[lowerProto]) { |
|
|
|
for (var i = 0, l = autoEscape.length; i < l; i++) { |
|
var ae = autoEscape[i]; |
|
var esc = encodeURIComponent(ae); |
|
if (esc === ae) { |
|
esc = escape(ae); |
|
} |
|
rest = rest.split(ae).join(esc); |
|
} |
|
} |
|
|
|
|
|
var hash = rest.indexOf('#'); |
|
if (hash !== -1) { |
|
this.hash = rest.substr(hash); |
|
rest = rest.slice(0, hash); |
|
} |
|
var qm = rest.indexOf('?'); |
|
if (qm !== -1) { |
|
this.search = rest.substr(qm); |
|
this.query = rest.substr(qm + 1); |
|
if (parseQueryString) { |
|
this.query = querystring.parse(this.query); |
|
} |
|
rest = rest.slice(0, qm); |
|
} else if (parseQueryString) { |
|
this.search = ''; |
|
this.query = {}; |
|
} |
|
if (rest) this.pathname = rest; |
|
if (slashedProtocol[lowerProto] && |
|
this.hostname && !this.pathname) { |
|
this.pathname = '/'; |
|
} |
|
|
|
if (this.pathname || this.search) { |
|
var p = this.pathname || ''; |
|
var s = this.search || ''; |
|
this.path = p + s; |
|
} |
|
|
|
this.href = this.format(); |
|
return this; |
|
}; |
|
|
|
function urlFormat(obj) { |
|
if (isString(obj)) obj = urlParse(obj); |
|
if (!(obj instanceof Url)) return Url.prototype.format.call(obj); |
|
return obj.format(); |
|
} |
|
|
|
Url.prototype.format = function() { |
|
var auth = this.auth || ''; |
|
if (auth) { |
|
auth = encodeURIComponent(auth); |
|
auth = auth.replace(/%3A/i, ':'); |
|
auth += '@'; |
|
} |
|
|
|
var protocol = this.protocol || '', |
|
pathname = this.pathname || '', |
|
hash = this.hash || '', |
|
host = false, |
|
query = ''; |
|
|
|
if (this.host) { |
|
host = auth + this.host; |
|
} else if (this.hostname) { |
|
host = auth + (this.hostname.indexOf(':') === -1 ? |
|
this.hostname : |
|
'[' + this.hostname + ']'); |
|
if (this.port) { |
|
host += ':' + this.port; |
|
} |
|
} |
|
|
|
if (this.query && |
|
isObject(this.query) && |
|
Object.keys(this.query).length) { |
|
query = querystring.stringify(this.query); |
|
} |
|
|
|
var search = this.search || (query && ('?' + query)) || ''; |
|
|
|
if (protocol && protocol.substr(-1) !== ':') protocol += ':'; |
|
|
|
if (this.slashes || |
|
(!protocol || slashedProtocol[protocol]) && host !== false) { |
|
host = '//' + (host || ''); |
|
if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname; |
|
} else if (!host) { |
|
host = ''; |
|
} |
|
|
|
if (hash && hash.charAt(0) !== '#') hash = '#' + hash; |
|
if (search && search.charAt(0) !== '?') search = '?' + search; |
|
|
|
pathname = pathname.replace(/[?#]/g, function(match) { |
|
return encodeURIComponent(match); |
|
}); |
|
search = search.replace('#', '%23'); |
|
|
|
return protocol + host + pathname + search + hash; |
|
}; |
|
|
|
function urlResolve(source, relative) { |
|
return urlParse(source, false, true).resolve(relative); |
|
} |
|
|
|
Url.prototype.resolve = function(relative) { |
|
return this.resolveObject(urlParse(relative, false, true)).format(); |
|
}; |
|
|
|
function urlResolveObject(source, relative) { |
|
if (!source) return relative; |
|
return urlParse(source, false, true).resolveObject(relative); |
|
} |
|
|
|
Url.prototype.resolveObject = function(relative) { |
|
if (isString(relative)) { |
|
var rel = new Url(); |
|
rel.parse(relative, false, true); |
|
relative = rel; |
|
} |
|
|
|
var result = new Url(); |
|
Object.keys(this).forEach(function(k) { |
|
result[k] = this[k]; |
|
}, this); |
|
|
|
result.hash = relative.hash; |
|
|
|
if (relative.href === '') { |
|
result.href = result.format(); |
|
return result; |
|
} |
|
|
|
if (relative.slashes && !relative.protocol) { |
|
Object.keys(relative).forEach(function(k) { |
|
if (k !== 'protocol') |
|
result[k] = relative[k]; |
|
}); |
|
|
|
if (slashedProtocol[result.protocol] && |
|
result.hostname && !result.pathname) { |
|
result.path = result.pathname = '/'; |
|
} |
|
|
|
result.href = result.format(); |
|
return result; |
|
} |
|
|
|
if (relative.protocol && relative.protocol !== result.protocol) { |
|
if (!slashedProtocol[relative.protocol]) { |
|
Object.keys(relative).forEach(function(k) { |
|
result[k] = relative[k]; |
|
}); |
|
result.href = result.format(); |
|
return result; |
|
} |
|
|
|
result.protocol = relative.protocol; |
|
if (!relative.host && !hostlessProtocol[relative.protocol]) { |
|
var relPath = (relative.pathname || '').split('/'); |
|
while (relPath.length && !(relative.host = relPath.shift())); |
|
if (!relative.host) relative.host = ''; |
|
if (!relative.hostname) relative.hostname = ''; |
|
if (relPath[0] !== '') relPath.unshift(''); |
|
if (relPath.length < 2) relPath.unshift(''); |
|
result.pathname = relPath.join('/'); |
|
} else { |
|
result.pathname = relative.pathname; |
|
} |
|
result.search = relative.search; |
|
result.query = relative.query; |
|
result.host = relative.host || ''; |
|
result.auth = relative.auth; |
|
result.hostname = relative.hostname || relative.host; |
|
result.port = relative.port; |
|
if (result.pathname || result.search) { |
|
var p = result.pathname || ''; |
|
var s = result.search || ''; |
|
result.path = p + s; |
|
} |
|
result.slashes = result.slashes || relative.slashes; |
|
result.href = result.format(); |
|
return result; |
|
} |
|
|
|
var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'), |
|
isRelAbs = ( |
|
relative.host || |
|
relative.pathname && relative.pathname.charAt(0) === '/' |
|
), |
|
mustEndAbs = (isRelAbs || isSourceAbs || |
|
(result.host && relative.pathname)), |
|
removeAllDots = mustEndAbs, |
|
srcPath = result.pathname && result.pathname.split('/') || [], |
|
relPath = relative.pathname && relative.pathname.split('/') || [], |
|
psychotic = result.protocol && !slashedProtocol[result.protocol]; |
|
|
|
if (psychotic) { |
|
result.hostname = ''; |
|
result.port = null; |
|
if (result.host) { |
|
if (srcPath[0] === '') srcPath[0] = result.host; |
|
else srcPath.unshift(result.host); |
|
} |
|
result.host = ''; |
|
if (relative.protocol) { |
|
relative.hostname = null; |
|
relative.port = null; |
|
if (relative.host) { |
|
if (relPath[0] === '') relPath[0] = relative.host; |
|
else relPath.unshift(relative.host); |
|
} |
|
relative.host = null; |
|
} |
|
mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === ''); |
|
} |
|
|
|
if (isRelAbs) { |
|
result.host = (relative.host || relative.host === '') ? |
|
relative.host : result.host; |
|
result.hostname = (relative.hostname || relative.hostname === '') ? |
|
relative.hostname : result.hostname; |
|
result.search = relative.search; |
|
result.query = relative.query; |
|
srcPath = relPath; |
|
} else if (relPath.length) { |
|
if (!srcPath) srcPath = []; |
|
srcPath.pop(); |
|
srcPath = srcPath.concat(relPath); |
|
result.search = relative.search; |
|
result.query = relative.query; |
|
} else if (!isNullOrUndefined(relative.search)) { |
|
if (psychotic) { |
|
result.hostname = result.host = srcPath.shift(); |
|
var authInHost = result.host && result.host.indexOf('@') > 0 ? |
|
result.host.split('@') : false; |
|
if (authInHost) { |
|
result.auth = authInHost.shift(); |
|
result.host = result.hostname = authInHost.shift(); |
|
} |
|
} |
|
result.search = relative.search; |
|
result.query = relative.query; |
|
if (!isNull(result.pathname) || !isNull(result.search)) { |
|
result.path = (result.pathname ? result.pathname : '') + |
|
(result.search ? result.search : ''); |
|
} |
|
result.href = result.format(); |
|
return result; |
|
} |
|
|
|
if (!srcPath.length) { |
|
result.pathname = null; |
|
if (result.search) { |
|
result.path = '/' + result.search; |
|
} else { |
|
result.path = null; |
|
} |
|
result.href = result.format(); |
|
return result; |
|
} |
|
|
|
var last = srcPath.slice(-1)[0]; |
|
var hasTrailingSlash = ( |
|
(result.host || relative.host) && (last === '.' || last === '..') || |
|
last === ''); |
|
|
|
var up = 0; |
|
for (var i = srcPath.length; i >= 0; i--) { |
|
last = srcPath[i]; |
|
if (last == '.') { |
|
srcPath.splice(i, 1); |
|
} else if (last === '..') { |
|
srcPath.splice(i, 1); |
|
up++; |
|
} else if (up) { |
|
srcPath.splice(i, 1); |
|
up--; |
|
} |
|
} |
|
|
|
if (!mustEndAbs && !removeAllDots) { |
|
for (; up--; up) { |
|
srcPath.unshift('..'); |
|
} |
|
} |
|
|
|
if (mustEndAbs && srcPath[0] !== '' && |
|
(!srcPath[0] || srcPath[0].charAt(0) !== '/')) { |
|
srcPath.unshift(''); |
|
} |
|
|
|
if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) { |
|
srcPath.push(''); |
|
} |
|
|
|
var isAbsolute = srcPath[0] === '' || |
|
(srcPath[0] && srcPath[0].charAt(0) === '/'); |
|
|
|
if (psychotic) { |
|
result.hostname = result.host = isAbsolute ? '' : |
|
srcPath.length ? srcPath.shift() : ''; |
|
var authInHost = result.host && result.host.indexOf('@') > 0 ? |
|
result.host.split('@') : false; |
|
if (authInHost) { |
|
result.auth = authInHost.shift(); |
|
result.host = result.hostname = authInHost.shift(); |
|
} |
|
} |
|
|
|
mustEndAbs = mustEndAbs || (result.host && srcPath.length); |
|
|
|
if (mustEndAbs && !isAbsolute) { |
|
srcPath.unshift(''); |
|
} |
|
|
|
if (!srcPath.length) { |
|
result.pathname = null; |
|
result.path = null; |
|
} else { |
|
result.pathname = srcPath.join('/'); |
|
} |
|
|
|
if (!isNull(result.pathname) || !isNull(result.search)) { |
|
result.path = (result.pathname ? result.pathname : '') + |
|
(result.search ? result.search : ''); |
|
} |
|
result.auth = relative.auth || result.auth; |
|
result.slashes = result.slashes || relative.slashes; |
|
result.href = result.format(); |
|
return result; |
|
}; |
|
|
|
Url.prototype.parseHost = function() { |
|
var host = this.host; |
|
var port = portPattern.exec(host); |
|
if (port) { |
|
port = port[0]; |
|
if (port !== ':') { |
|
this.port = port.substr(1); |
|
} |
|
host = host.substr(0, host.length - port.length); |
|
} |
|
if (host) this.hostname = host; |
|
}; |
|
|
|
function isString(arg) { |
|
return typeof arg === "string"; |
|
} |
|
|
|
function isObject(arg) { |
|
return typeof arg === 'object' && arg !== null; |
|
} |
|
|
|
function isNull(arg) { |
|
return arg === null; |
|
} |
|
function isNullOrUndefined(arg) { |
|
return arg == null; |
|
} |
|
|
|
},{"punycode":14,"querystring":17}],19:[function(require,module,exports){ |
|
module.exports = function isBuffer(arg) { |
|
return arg && typeof arg === 'object' |
|
&& typeof arg.copy === 'function' |
|
&& typeof arg.fill === 'function' |
|
&& typeof arg.readUInt8 === 'function'; |
|
} |
|
},{}],20:[function(require,module,exports){ |
|
(function (process,global){ |
|
|
|
var formatRegExp = /%[sdj%]/g; |
|
exports.format = function(f) { |
|
if (!isString(f)) { |
|
var objects = []; |
|
for (var i = 0; i < arguments.length; i++) { |
|
objects.push(inspect(arguments[i])); |
|
} |
|
return objects.join(' '); |
|
} |
|
|
|
var i = 1; |
|
var args = arguments; |
|
var len = args.length; |
|
var str = String(f).replace(formatRegExp, function(x) { |
|
if (x === '%') return '%'; |
|
if (i >= len) return x; |
|
switch (x) { |
|
case '%s': return String(args[i++]); |
|
case '%d': return Number(args[i++]); |
|
case '%j': |
|
try { |
|
return JSON.stringify(args[i++]); |
|
} catch (_) { |
|
return '[Circular]'; |
|
} |
|
default: |
|
return x; |
|
} |
|
}); |
|
for (var x = args[i]; i < len; x = args[++i]) { |
|
if (isNull(x) || !isObject(x)) { |
|
str += ' ' + x; |
|
} else { |
|
str += ' ' + inspect(x); |
|
} |
|
} |
|
return str; |
|
}; |
|
|
|
|
|
exports.deprecate = function(fn, msg) { |
|
if (isUndefined(global.process)) { |
|
return function() { |
|
return exports.deprecate(fn, msg).apply(this, arguments); |
|
}; |
|
} |
|
|
|
if (process.noDeprecation === true) { |
|
return fn; |
|
} |
|
|
|
var warned = false; |
|
function deprecated() { |
|
if (!warned) { |
|
if (process.throwDeprecation) { |
|
throw new Error(msg); |
|
} else if (process.traceDeprecation) { |
|
console.trace(msg); |
|
} else { |
|
console.error(msg); |
|
} |
|
warned = true; |
|
} |
|
return fn.apply(this, arguments); |
|
} |
|
|
|
return deprecated; |
|
}; |
|
|
|
|
|
var debugs = {}; |
|
var debugEnviron; |
|
exports.debuglog = function(set) { |
|
if (isUndefined(debugEnviron)) |
|
debugEnviron = process.env.NODE_DEBUG || ''; |
|
set = set.toUpperCase(); |
|
if (!debugs[set]) { |
|
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { |
|
var pid = process.pid; |
|
debugs[set] = function() { |
|
var msg = exports.format.apply(exports, arguments); |
|
console.error('%s %d: %s', set, pid, msg); |
|
}; |
|
} else { |
|
debugs[set] = function() {}; |
|
} |
|
} |
|
return debugs[set]; |
|
}; |
|
|
|
|
|
|
|
|
|
function inspect(obj, opts) { |
|
var ctx = { |
|
seen: [], |
|
stylize: stylizeNoColor |
|
}; |
|
if (arguments.length >= 3) ctx.depth = arguments[2]; |
|
if (arguments.length >= 4) ctx.colors = arguments[3]; |
|
if (isBoolean(opts)) { |
|
ctx.showHidden = opts; |
|
} else if (opts) { |
|
exports._extend(ctx, opts); |
|
} |
|
if (isUndefined(ctx.showHidden)) ctx.showHidden = false; |
|
if (isUndefined(ctx.depth)) ctx.depth = 2; |
|
if (isUndefined(ctx.colors)) ctx.colors = false; |
|
if (isUndefined(ctx.customInspect)) ctx.customInspect = true; |
|
if (ctx.colors) ctx.stylize = stylizeWithColor; |
|
return formatValue(ctx, obj, ctx.depth); |
|
} |
|
exports.inspect = inspect; |
|
|
|
|
|
inspect.colors = { |
|
'bold' : [1, 22], |
|
'italic' : [3, 23], |
|
'underline' : [4, 24], |
|
'inverse' : [7, 27], |
|
'white' : [37, 39], |
|
'grey' : [90, 39], |
|
'black' : [30, 39], |
|
'blue' : [34, 39], |
|
'cyan' : [36, 39], |
|
'green' : [32, 39], |
|
'magenta' : [35, 39], |
|
'red' : [31, 39], |
|
'yellow' : [33, 39] |
|
}; |
|
|
|
inspect.styles = { |
|
'special': 'cyan', |
|
'number': 'yellow', |
|
'boolean': 'yellow', |
|
'undefined': 'grey', |
|
'null': 'bold', |
|
'string': 'green', |
|
'date': 'magenta', |
|
'regexp': 'red' |
|
}; |
|
|
|
|
|
function stylizeWithColor(str, styleType) { |
|
var style = inspect.styles[styleType]; |
|
|
|
if (style) { |
|
return '\u001b[' + inspect.colors[style][0] + 'm' + str + |
|
'\u001b[' + inspect.colors[style][1] + 'm'; |
|
} else { |
|
return str; |
|
} |
|
} |
|
|
|
|
|
function stylizeNoColor(str, styleType) { |
|
return str; |
|
} |
|
|
|
|
|
function arrayToHash(array) { |
|
var hash = {}; |
|
|
|
array.forEach(function(val, idx) { |
|
hash[val] = true; |
|
}); |
|
|
|
return hash; |
|
} |
|
|
|
|
|
function formatValue(ctx, value, recurseTimes) { |
|
if (ctx.customInspect && |
|
value && |
|
isFunction(value.inspect) && |
|
value.inspect !== exports.inspect && |
|
!(value.constructor && value.constructor.prototype === value)) { |
|
var ret = value.inspect(recurseTimes, ctx); |
|
if (!isString(ret)) { |
|
ret = formatValue(ctx, ret, recurseTimes); |
|
} |
|
return ret; |
|
} |
|
|
|
var primitive = formatPrimitive(ctx, value); |
|
if (primitive) { |
|
return primitive; |
|
} |
|
|
|
var keys = Object.keys(value); |
|
var visibleKeys = arrayToHash(keys); |
|
|
|
if (ctx.showHidden) { |
|
keys = Object.getOwnPropertyNames(value); |
|
} |
|
|
|
if (isError(value) |
|
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { |
|
return formatError(value); |
|
} |
|
|
|
if (keys.length === 0) { |
|
if (isFunction(value)) { |
|
var name = value.name ? ': ' + value.name : ''; |
|
return ctx.stylize('[Function' + name + ']', 'special'); |
|
} |
|
if (isRegExp(value)) { |
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); |
|
} |
|
if (isDate(value)) { |
|
return ctx.stylize(Date.prototype.toString.call(value), 'date'); |
|
} |
|
if (isError(value)) { |
|
return formatError(value); |
|
} |
|
} |
|
|
|
var base = '', array = false, braces = ['{', '}']; |
|
|
|
if (isArray(value)) { |
|
array = true; |
|
braces = ['[', ']']; |
|
} |
|
|
|
if (isFunction(value)) { |
|
var n = value.name ? ': ' + value.name : ''; |
|
base = ' [Function' + n + ']'; |
|
} |
|
|
|
if (isRegExp(value)) { |
|
base = ' ' + RegExp.prototype.toString.call(value); |
|
} |
|
|
|
if (isDate(value)) { |
|
base = ' ' + Date.prototype.toUTCString.call(value); |
|
} |
|
|
|
if (isError(value)) { |
|
base = ' ' + formatError(value); |
|
} |
|
|
|
if (keys.length === 0 && (!array || value.length == 0)) { |
|
return braces[0] + base + braces[1]; |
|
} |
|
|
|
if (recurseTimes < 0) { |
|
if (isRegExp(value)) { |
|
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); |
|
} else { |
|
return ctx.stylize('[Object]', 'special'); |
|
} |
|
} |
|
|
|
ctx.seen.push(value); |
|
|
|
var output; |
|
if (array) { |
|
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); |
|
} else { |
|
output = keys.map(function(key) { |
|
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); |
|
}); |
|
} |
|
|
|
ctx.seen.pop(); |
|
|
|
return reduceToSingleString(output, base, braces); |
|
} |
|
|
|
|
|
function formatPrimitive(ctx, value) { |
|
if (isUndefined(value)) |
|
return ctx.stylize('undefined', 'undefined'); |
|
if (isString(value)) { |
|
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') |
|
.replace(/'/g, "\\'") |
|
.replace(/\\"/g, '"') + '\''; |
|
return ctx.stylize(simple, 'string'); |
|
} |
|
if (isNumber(value)) |
|
return ctx.stylize('' + value, 'number'); |
|
if (isBoolean(value)) |
|
return ctx.stylize('' + value, 'boolean'); |
|
if (isNull(value)) |
|
return ctx.stylize('null', 'null'); |
|
} |
|
|
|
|
|
function formatError(value) { |
|
return '[' + Error.prototype.toString.call(value) + ']'; |
|
} |
|
|
|
|
|
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { |
|
var output = []; |
|
for (var i = 0, l = value.length; i < l; ++i) { |
|
if (hasOwnProperty(value, String(i))) { |
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, |
|
String(i), true)); |
|
} else { |
|
output.push(''); |
|
} |
|
} |
|
keys.forEach(function(key) { |
|
if (!key.match(/^\d+$/)) { |
|
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, |
|
key, true)); |
|
} |
|
}); |
|
return output; |
|
} |
|
|
|
|
|
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { |
|
var name, str, desc; |
|
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; |
|
if (desc.get) { |
|
if (desc.set) { |
|
str = ctx.stylize('[Getter/Setter]', 'special'); |
|
} else { |
|
str = ctx.stylize('[Getter]', 'special'); |
|
} |
|
} else { |
|
if (desc.set) { |
|
str = ctx.stylize('[Setter]', 'special'); |
|
} |
|
} |
|
if (!hasOwnProperty(visibleKeys, key)) { |
|
name = '[' + key + ']'; |
|
} |
|
if (!str) { |
|
if (ctx.seen.indexOf(desc.value) < 0) { |
|
if (isNull(recurseTimes)) { |
|
str = formatValue(ctx, desc.value, null); |
|
} else { |
|
str = formatValue(ctx, desc.value, recurseTimes - 1); |
|
} |
|
if (str.indexOf('\n') > -1) { |
|
if (array) { |
|
str = str.split('\n').map(function(line) { |
|
return ' ' + line; |
|
}).join('\n').substr(2); |
|
} else { |
|
str = '\n' + str.split('\n').map(function(line) { |
|
return ' ' + line; |
|
}).join('\n'); |
|
} |
|
} |
|
} else { |
|
str = ctx.stylize('[Circular]', 'special'); |
|
} |
|
} |
|
if (isUndefined(name)) { |
|
if (array && key.match(/^\d+$/)) { |
|
return str; |
|
} |
|
name = JSON.stringify('' + key); |
|
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { |
|
name = name.substr(1, name.length - 2); |
|
name = ctx.stylize(name, 'name'); |
|
} else { |
|
name = name.replace(/'/g, "\\'") |
|
.replace(/\\"/g, '"') |
|
.replace(/(^"|"$)/g, "'"); |
|
name = ctx.stylize(name, 'string'); |
|
} |
|
} |
|
|
|
return name + ': ' + str; |
|
} |
|
|
|
|
|
function reduceToSingleString(output, base, braces) { |
|
var numLinesEst = 0; |
|
var length = output.reduce(function(prev, cur) { |
|
numLinesEst++; |
|
if (cur.indexOf('\n') >= 0) numLinesEst++; |
|
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; |
|
}, 0); |
|
|
|
if (length > 60) { |
|
return braces[0] + |
|
(base === '' ? '' : base + '\n ') + |
|
' ' + |
|
output.join(',\n ') + |
|
' ' + |
|
braces[1]; |
|
} |
|
|
|
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; |
|
} |
|
|
|
|
|
function isArray(ar) { |
|
return Array.isArray(ar); |
|
} |
|
exports.isArray = isArray; |
|
|
|
function isBoolean(arg) { |
|
return typeof arg === 'boolean'; |
|
} |
|
exports.isBoolean = isBoolean; |
|
|
|
function isNull(arg) { |
|
return arg === null; |
|
} |
|
exports.isNull = isNull; |
|
|
|
function isNullOrUndefined(arg) { |
|
return arg == null; |
|
} |
|
exports.isNullOrUndefined = isNullOrUndefined; |
|
|
|
function isNumber(arg) { |
|
return typeof arg === 'number'; |
|
} |
|
exports.isNumber = isNumber; |
|
|
|
function isString(arg) { |
|
return typeof arg === 'string'; |
|
} |
|
exports.isString = isString; |
|
|
|
function isSymbol(arg) { |
|
return typeof arg === 'symbol'; |
|
} |
|
exports.isSymbol = isSymbol; |
|
|
|
function isUndefined(arg) { |
|
return arg === void 0; |
|
} |
|
exports.isUndefined = isUndefined; |
|
|
|
function isRegExp(re) { |
|
return isObject(re) && objectToString(re) === '[object RegExp]'; |
|
} |
|
exports.isRegExp = isRegExp; |
|
|
|
function isObject(arg) { |
|
return typeof arg === 'object' && arg !== null; |
|
} |
|
exports.isObject = isObject; |
|
|
|
function isDate(d) { |
|
return isObject(d) && objectToString(d) === '[object Date]'; |
|
} |
|
exports.isDate = isDate; |
|
|
|
function isError(e) { |
|
return isObject(e) && |
|
(objectToString(e) === '[object Error]' || e instanceof Error); |
|
} |
|
exports.isError = isError; |
|
|
|
function isFunction(arg) { |
|
return typeof arg === 'function'; |
|
} |
|
exports.isFunction = isFunction; |
|
|
|
function isPrimitive(arg) { |
|
return arg === null || |
|
typeof arg === 'boolean' || |
|
typeof arg === 'number' || |
|
typeof arg === 'string' || |
|
typeof arg === 'symbol' || // ES6 symbol |
|
typeof arg === 'undefined'; |
|
} |
|
exports.isPrimitive = isPrimitive; |
|
|
|
exports.isBuffer = require('./support/isBuffer'); |
|
|
|
function objectToString(o) { |
|
return Object.prototype.toString.call(o); |
|
} |
|
|
|
|
|
function pad(n) { |
|
return n < 10 ? '0' + n.toString(10) : n.toString(10); |
|
} |
|
|
|
|
|
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', |
|
'Oct', 'Nov', 'Dec']; |
|
|
|
function timestamp() { |
|
var d = new Date(); |
|
var time = [pad(d.getHours()), |
|
pad(d.getMinutes()), |
|
pad(d.getSeconds())].join(':'); |
|
return [d.getDate(), months[d.getMonth()], time].join(' '); |
|
} |
|
|
|
|
|
exports.log = function() { |
|
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); |
|
}; |
|
|
|
|
|
|
|
exports.inherits = require('inherits'); |
|
|
|
exports._extend = function(origin, add) { |
|
if (!add || !isObject(add)) return origin; |
|
|
|
var keys = Object.keys(add); |
|
var i = keys.length; |
|
while (i--) { |
|
origin[keys[i]] = add[keys[i]]; |
|
} |
|
return origin; |
|
}; |
|
|
|
function hasOwnProperty(obj, prop) { |
|
return Object.prototype.hasOwnProperty.call(obj, prop); |
|
} |
|
|
|
}).call(this,require("G+mPsH"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
|
},{"./support/isBuffer":19,"G+mPsH":13,"inherits":12}],21:[function(require,module,exports){ |
|
var AWS = require('./core'); |
|
|
|
AWS.XML.Parser = require('./xml/browser_parser'); |
|
|
|
require('./http/xhr'); |
|
|
|
if (typeof window !== 'undefined') window.AWS = AWS; |
|
|
|
},{"./core":23,"./http/xhr":31,"./xml/browser_parser":61}],22:[function(require,module,exports){ |
|
var AWS = require('./core'); |
|
require('./credentials'); |
|
require('./credentials/credential_provider_chain'); |
|
|
|
|
|
AWS.Config = AWS.util.inherit({ |
|
|
|
|
|
constructor: function Config(options) { |
|
if (options === undefined) options = {}; |
|
options = this.extractCredentials(options); |
|
|
|
AWS.util.each.call(this, this.keys, function (key, value) { |
|
this.set(key, options[key], value); |
|
}); |
|
}, |
|
|
|
|
|
update: function update(options, allowUnknownKeys) { |
|
allowUnknownKeys = allowUnknownKeys || false; |
|
options = this.extractCredentials(options); |
|
AWS.util.each.call(this, options, function (key, value) { |
|
if (allowUnknownKeys || this.keys.hasOwnProperty(key)) this[key] = value; |
|
}); |
|
}, |
|
|
|
|
|
getCredentials: function getCredentials(callback) { |
|
var self = this; |
|
|
|
function finish(err) { |
|
callback(err, err ? null : self.credentials); |
|
} |
|
|
|
function credError(msg, err) { |
|
return new AWS.util.error(err || new Error(), { |
|
code: 'CredentialsError', message: msg |
|
}); |
|
} |
|
|
|
function getAsyncCredentials() { |
|
self.credentials.get(function(err) { |
|
if (err) { |
|
var msg = 'Could not load credentials from ' + |
|
self.credentials.constructor.name; |
|
err = credError(msg, err); |
|
} |
|
finish(err); |
|
}); |
|
} |
|
|
|
function getStaticCredentials() { |
|
var err = null; |
|
if (!self.credentials.accessKeyId || !self.credentials.secretAccessKey) { |
|
err = credError('Missing credentials'); |
|
} |
|
finish(err); |
|
} |
|
|
|
if (self.credentials) { |
|
if (typeof self.credentials.get === 'function') { |
|
getAsyncCredentials(); |
|
} else { // static credentials |
|
getStaticCredentials(); |
|
} |
|
} else if (self.credentialProvider) { |
|
self.credentialProvider.resolve(function(err, creds) { |
|
if (err) { |
|
err = credError('Could not load credentials from any providers', err); |
|
} |
|
self.credentials = creds; |
|
finish(err); |
|
}); |
|
} else { |
|
finish(credError('No credentials to load')); |
|
} |
|
}, |
|
|
|
|
|
loadFromPath: function loadFromPath(path) { |
|
this.clear(); |
|
|
|
var options = JSON.parse(AWS.util.readFileSync(path)); |
|
var fileSystemCreds = new AWS.FileSystemCredentials(path); |
|
var chain = new AWS.CredentialProviderChain(); |
|
chain.providers.unshift(fileSystemCreds); |
|
chain.resolve(function (err, creds) { |
|
if (err) throw err; |
|
else options.credentials = creds; |
|
}); |
|
|
|
this.constructor(options); |
|
|
|
return this; |
|
}, |
|
|
|
|
|
clear: function clear() { |
|
|
|
AWS.util.each.call(this, this.keys, function (key) { |
|
delete this[key]; |
|
}); |
|
|
|
this.set('credentials', undefined); |
|
this.set('credentialProvider', undefined); |
|
}, |
|
|
|
|
|
set: function set(property, value, defaultValue) { |
|
if (value === undefined) { |
|
if (defaultValue === undefined) { |
|
defaultValue = this.keys[property]; |
|
} |
|
if (typeof defaultValue === 'function') { |
|
this[property] = defaultValue.call(this); |
|
} else { |
|
this[property] = defaultValue; |
|
} |
|
} else { |
|
this[property] = value; |
|
} |
|
}, |
|
|
|
|
|
keys: { |
|
credentials: null, |
|
credentialProvider: null, |
|
region: null, |
|
logger: null, |
|
apiVersions: {}, |
|
apiVersion: null, |
|
endpoint: undefined, |
|
httpOptions: {}, |
|
maxRetries: undefined, |
|
maxRedirects: 10, |
|
paramValidation: true, |
|
sslEnabled: true, |
|
s3ForcePathStyle: false, |
|
computeChecksums: true, |
|
convertResponseTypes: true, |
|
dynamoDbCrc32: true, |
|
signatureVersion: null |
|
}, |
|
|
|
|
|
extractCredentials: function extractCredentials(options) { |
|
if (options.accessKeyId && options.secretAccessKey) { |
|
options = AWS.util.copy(options); |
|
options.credentials = new AWS.Credentials(options); |
|
} |
|
return options; |
|
} |
|
}); |
|
|
|
|
|
AWS.config = new AWS.Config(); |
|
|
|
},{"./core":23,"./credentials":24,"./credentials/credential_provider_chain":25}],23:[function(require,module,exports){ |
|
|
|
var AWS = { util: require('./util') }; |
|
|
|
|
|
var _hidden = {}; _hidden = {}; // hack to parse macro |
|
|
|
module.exports = AWS; |
|
|
|
AWS.util.update(AWS, { |
|
|
|
|
|
VERSION: '2.0.0-rc.20', |
|
|
|
|
|
Signers: {}, |
|
|
|
|
|
Protocol: { |
|
Json: require('./protocol/json'), |
|
Query: require('./protocol/query'), |
|
Rest: require('./protocol/rest'), |
|
RestJson: require('./protocol/rest_json'), |
|
RestXml: require('./protocol/rest_xml') |
|
}, |
|
|
|
|
|
XML: { |
|
Builder: require('./xml/builder'), |
|
Parser: null // conditionally set based on environment |
|
}, |
|
|
|
|
|
JSON: { |
|
Builder: require('./json/builder'), |
|
Parser: require('./json/parser') |
|
}, |
|
|
|
|
|
Model: { |
|
Api: require('./model/api'), |
|
Operation: require('./model/operation'), |
|
Shape: require('./model/shape'), |
|
Paginator: require('./model/paginator'), |
|
ResourceWaiter: require('./model/resource_waiter') |
|
}, |
|
|
|
util: require('./util') |
|
}); |
|
|
|
require('./service'); |
|
|
|
require('./credentials'); |
|
require('./credentials/credential_provider_chain'); |
|
require('./credentials/temporary_credentials'); |
|
require('./credentials/web_identity_credentials'); |
|
require('./credentials/saml_credentials'); |
|
|
|
require('./config'); |
|
require('./http'); |
|
require('./sequential_executor'); |
|
require('./event_listeners'); |
|
require('./request'); |
|
require('./response'); |
|
require('./resource_waiter'); |
|
require('./signers/request_signer'); |
|
require('./param_validator'); |
|
|
|
|
|
AWS.events = new AWS.SequentialExecutor(); |
|
|
|
},{"./config":22,"./credentials":24,"./credentials/credential_provider_chain":25,"./credentials/saml_credentials":26,"./credentials/temporary_credentials":27,"./credentials/web_identity_credentials":28,"./event_listeners":29,"./http":30,"./json/builder":32,"./json/parser":33,"./model/api":34,"./model/operation":36,"./model/paginator":37,"./model/resource_waiter":38,"./model/shape":39,"./param_validator":40,"./protocol/json":41,"./protocol/query":42,"./protocol/rest":43,"./protocol/rest_json":44,"./protocol/rest_xml":45,"./request":47,"./resource_waiter":48,"./response":49,"./sequential_executor":50,"./service":51,"./signers/request_signer":53,"./util":60,"./xml/builder":62}],24:[function(require,module,exports){ |
|
var AWS = require('./core'); |
|
|
|
|
|
AWS.Credentials = AWS.util.inherit({ |
|
|
|
constructor: function Credentials() { |
|
AWS.util.hideProperties(this, ['secretAccessKey']); |
|
|
|
this.expired = false; |
|
this.expireTime = null; |
|
if (arguments.length === 1 && typeof arguments[0] === 'object') { |
|
var creds = arguments[0].credentials || arguments[0]; |
|
this.accessKeyId = creds.accessKeyId; |
|
this.secretAccessKey = creds.secretAccessKey; |
|
this.sessionToken = creds.sessionToken; |
|
} else { |
|
this.accessKeyId = arguments[0]; |
|
this.secretAccessKey = arguments[1]; |
|
this.sessionToken = arguments[2]; |
|
} |
|
}, |
|
|
|
|
|
expiryWindow: 15, |
|
|
|
|
|
needsRefresh: function needsRefresh() { |
|
var currentTime = AWS.util.date.getDate().getTime(); |
|
var adjustedTime = new Date(currentTime + this.expiryWindow * 1000); |
|
|
|
if (this.expireTime && adjustedTime > this.expireTime) { |
|
return true; |
|
} else { |
|
return this.expired || !this.accessKeyId || !this.secretAccessKey; |
|
} |
|
}, |
|
|
|
|
|
get: function get(callback) { |
|
var self = this; |
|
if (this.needsRefresh()) { |
|
this.refresh(function(err) { |
|
if (!err) self.expired = false; // reset expired flag |
|
if (callback) callback(err); |
|
}); |
|
} else if (callback) { |
|
callback(); |
|
} |
|
}, |
|
|
|
|
|
refresh: function refresh(callback) { |
|
this.expired = false; |
|
callback(); |
|
} |
|
}); |
|
|
|
},{"./core":23}],25:[function(require,module,exports){ |
|
var AWS = require('../core'); |
|
|
|
|
|
AWS.CredentialProviderChain = AWS.util.inherit(AWS.Credentials, { |
|
|
|
|
|
constructor: function CredentialProviderChain(providers) { |
|
if (providers) { |
|
this.providers = providers; |
|
} else { |
|
this.providers = AWS.CredentialProviderChain.defaultProviders.slice(0); |
|
} |
|
}, |
|
|
|
|
|
resolve: function resolve(callback) { |
|
if (this.providers.length === 0) { |
|
callback(new Error('No providers')); |
|
return this; |
|
} |
|
|
|
var index = 0; |
|
var providers = this.providers.slice(0); |
|
|
|
function resolveNext(err, creds) { |
|
if ((!err && creds) || index === providers.length) { |
|
callback(err, creds); |
|
return; |
|
} |
|
|
|
var provider = providers[index++]; |
|
if (typeof provider === 'function') { |
|
creds = provider.call(); |
|
} else { |
|
creds = provider; |
|
} |
|
|
|
if (creds.get) { |
|
creds.get(function(err) { |
|
resolveNext(err, err ? null : creds); |
|
}); |
|
} else { |
|
resolveNext(null, creds); |
|
} |
|
} |
|
|
|
resolveNext(); |
|
return this; |
|
} |
|
|
|
}); |
|
|
|
|
|
AWS.CredentialProviderChain.defaultProviders = []; |
|
|
|
},{"../core":23}],26:[function(require,module,exports){ |
|
var AWS = require('../core'); |
|
|
|
|
|
AWS.SAMLCredentials = AWS.util.inherit(AWS.Credentials, { |
|
|
|
constructor: function SAMLCredentials(params) { |
|
AWS.Credentials.call(this); |
|
this.expired = true; |
|
this.service = new AWS.STS(); |
|
this.params = params; |
|
}, |
|
|
|
|
|
refresh: function refresh(callback) { |
|
var self = this; |
|
if (!callback) callback = function(err) { if (err) throw err; }; |
|
|
|
self.service.assumeRoleWithSAML(self.params, function (err, data) { |
|
if (!err) { |
|
self.service.credentialsFrom(data, self); |
|
} |
|
callback(err); |
|
}); |
|
} |
|
}); |
|
|
|
},{"../core":23}],27:[function(require,module,exports){ |
|
var AWS = require('../core'); |
|
|
|
|
|
AWS.TemporaryCredentials = AWS.util.inherit(AWS.Credentials, { |
|
|
|
constructor: function TemporaryCredentials(params) { |
|
AWS.Credentials.call(this); |
|
this.loadMasterCredentials(); |
|
this.service = new AWS.STS(); |
|
this.expired = true; |
|
|
|
this.params = params || {}; |
|
if (this.params.RoleArn) { |
|
this.params.RoleSessionName = |
|
this.params.RoleSessionName || 'temporary-credentials'; |
|
} |
|
}, |
|
|
|
|
|
refresh: function refresh(callback) { |
|
var self = this; |
|
if (!callback) callback = function(err) { if (err) throw err; }; |
|
|
|
self.service.config.credentials = self.masterCredentials; |
|
var operation = self.params.RoleArn ? |
|
self.service.assumeRole : self.service.getSessionToken; |
|
operation.call(self.service, self.params, function (err, data) { |
|
if (!err) { |
|
self.service.credentialsFrom(data, self); |
|
} |
|
callback(err); |
|
}); |
|
}, |
|
|
|
|
|
loadMasterCredentials: function loadMasterCredentials() { |
|
this.masterCredentials = AWS.config.credentials; |
|
while (this.masterCredentials.masterCredentials) { |
|
this.masterCredentials = this.masterCredentials.masterCredentials; |
|
} |
|
} |
|
}); |
|
|
|
},{"../core":23}],28:[function(require,module,exports){ |
|
var AWS = require('../core'); |
|
|
|
|
|
AWS.WebIdentityCredentials = AWS.util.inherit(AWS.Credentials, { |
|
|
|
constructor: function WebIdentityCredentials(params) { |
|
AWS.Credentials.call(this); |
|
this.expired = true; |
|
this.service = new AWS.STS(); |
|
this.params = params; |
|
this.data = null; |
|
this.params.RoleSessionName = this.params.RoleSessionName || 'web-identity'; |
|
}, |
|
|
|
|
|
refresh: function refresh(callback) { |
|
var self = this; |
|
if (!callback) callback = function(err) { if (err) throw err; }; |
|
|
|
self.service.assumeRoleWithWebIdentity(self.params, function (err, data) { |
|
self.data = null; |
|
if (!err) { |
|
self.data = data; |
|
self.service.credentialsFrom(data, self); |
|
} |
|
callback(err); |
|
}); |
|
} |
|
}); |
|
|
|
},{"../core":23}],29:[function(require,module,exports){ |
|
var AWS = require('./core'); |
|
var SequentialExecutor = require('./sequential_executor'); |
|
|
|
|
|
AWS.EventListeners = { |
|
|
|
Core: {} /* doc hack */ |
|
}; |
|
|
|
AWS.EventListeners = { |
|
Core: new SequentialExecutor().addNamedListeners(function(add, addAsync) { |
|
addAsync('VALIDATE_CREDENTIALS', 'validate', |
|
function VALIDATE_CREDENTIALS(req, done) { |
|
req.service.config.getCredentials(function(err) { |
|
if (err) { |
|
req.response.err = AWS.util.error(err, |
|
{code: 'SigningError', message: 'Missing credentials in config'}); |
|
} |
|
done(); |
|
}); |
|
}); |
|
|
|
add('VALIDATE_REGION', 'validate', function VALIDATE_REGION(req) { |
|
if (!req.service.config.region && !req.service.hasGlobalEndpoint()) { |
|
req.response.error = AWS.util.error(new Error(), |
|
{code: 'SigningError', message: 'Missing region in config'}); |
|
} |
|
}); |
|
|
|
add('VALIDATE_PARAMETERS', 'validate', function VALIDATE_PARAMETERS(req) { |
|
var rules = req.service.api.operations[req.operation].input; |
|
new AWS.ParamValidator().validate(rules, req.params); |
|
}); |
|
|
|
add('SET_CONTENT_LENGTH', 'afterBuild', function SET_CONTENT_LENGTH(req) { |
|
if (req.httpRequest.headers['Content-Length'] === undefined) { |
|
var length = AWS.util.string.byteLength(req.httpRequest.body); |
|
req.httpRequest.headers['Content-Length'] = length; |
|
} |
|
}); |
|
|
|
add('SET_HTTP_HOST', 'afterBuild', function SET_HTTP_HOST(req) { |
|
req.httpRequest.headers['Host'] = req.httpRequest.endpoint.host; |
|
}); |
|
|
|
addAsync('SIGN', 'sign', function SIGN(req, done) { |
|
if (!req.service.api.signatureVersion) return done(); // none |
|
|
|
req.service.config.getCredentials(function (err, credentials) { |
|
if (err) { |
|
req.response.error = err; |
|
return done(); |
|
} |
|
|
|
try { |
|
var date = AWS.util.date.getDate(); |
|
var SignerClass = req.service.getSignerClass(req); |
|
var signer = new SignerClass(req.httpRequest, |
|
req.service.api.signingName || req.service.api.endpointPrefix); |
|
|
|
delete req.httpRequest.headers['Authorization']; |
|
delete req.httpRequest.headers['Date']; |
|
delete req.httpRequest.headers['X-Amz-Date']; |
|
|
|
signer.addAuthorization(credentials, date); |
|
req.signedAt = date; |
|
} catch (e) { |
|
req.response.error = e; |
|
} |
|
done(); |
|
}); |
|
}); |
|
|
|
add('VALIDATE_RESPONSE', 'validateResponse', function VALIDATE_RESPONSE(resp) { |
|
if (this.service.successfulResponse(resp, this)) { |
|
resp.data = {}; |
|
resp.error = null; |
|
} else { |
|
resp.data = null; |
|
resp.error = AWS.util.error(new Error(), |
|
{code: 'UnknownError', message: 'An unknown error occurred.'}); |
|
} |
|
}); |
|
|
|
addAsync('SEND', 'send', function SEND(resp, done) { |
|
resp.httpResponse._abortCallback = done; |
|
resp.error = null; |
|
resp.data = null; |
|
|
|
function callback(httpResp) { |
|
resp.httpResponse.stream = httpResp; |
|
|
|
httpResp.on('headers', function onHeaders(statusCode, headers) { |
|
resp.request.emit('httpHeaders', [statusCode, headers, resp]); |
|
|
|
if (!resp.request.httpRequest._streaming) { |
|
if (AWS.HttpClient.streamsApiVersion === 2) { // streams2 API check |
|
httpResp.on('readable', function onReadable() { |
|
var data = httpResp.read(); |
|
if (data !== null) { |
|
resp.request.emit('httpData', [data, resp]); |
|
} |
|
}); |
|
} else { // legacy streams API |
|
httpResp.on('data', function onData(data) { |
|
resp.request.emit('httpData', [data, resp]); |
|
}); |
|
} |
|
} |
|
}); |
|
|
|
httpResp.on('end', function onEnd() { |
|
resp.request.emit('httpDone'); |
|
done(); |
|
}); |
|
} |
|
|
|
function progress(httpResp) { |
|
httpResp.on('sendProgress', function onSendProgress(progress) { |
|
resp.request.emit('httpUploadProgress', [progress, resp]); |
|
}); |
|
|
|
httpResp.on('receiveProgress', function onReceiveProgress(progress) { |
|
resp.request.emit('httpDownloadProgress', [progress, resp]); |
|
}); |
|
} |
|
|
|
function error(err) { |
|
resp.error = AWS.util.error(err, { |
|
code: 'NetworkingError', |
|
region: resp.request.httpRequest.region, |
|
hostname: resp.request.httpRequest.endpoint.hostname, |
|
retryable: true |
|
}); |
|
resp.request.emit('httpError', [resp.error, resp], function() { |
|
done(); |
|
}); |
|
} |
|
|
|
function executeSend() { |
|
var http = AWS.HttpClient.getInstance(); |
|
var httpOptions = resp.request.service.config.httpOptions || {}; |
|
var stream = http.handleRequest(resp.request.httpRequest, httpOptions, |
|
callback, error); |
|
progress(stream); |
|
} |
|
|
|
var timeDiff = (AWS.util.date.getDate() - this.signedAt) / 1000; |
|
if (timeDiff >= 60 * 10) { // if we signed 10min ago, re-sign |
|
this.emit('sign', [this], function(err) { |
|
if (err) done(err); |
|
else executeSend(); |
|
}); |
|
} else { |
|
executeSend(); |
|
} |
|
}); |
|
|
|
add('HTTP_HEADERS', 'httpHeaders', |
|
function HTTP_HEADERS(statusCode, headers, resp) { |
|
resp.httpResponse.statusCode = statusCode; |
|
resp.httpResponse.headers = headers; |
|
resp.httpResponse.body = new AWS.util.Buffer(''); |
|
resp.httpResponse.buffers = []; |
|
resp.httpResponse.numBytes = 0; |
|
}); |
|
|
|
add('HTTP_DATA', 'httpData', function HTTP_DATA(chunk, resp) { |
|
if (chunk) { |
|
if (AWS.util.isNode()) { |
|
resp.httpResponse.numBytes += chunk.length; |
|
|
|
var total = resp.httpResponse.headers['content-length']; |
|
var progress = { loaded: resp.httpResponse.numBytes, total: total }; |
|
resp.request.emit('httpDownloadProgress', [progress, resp]); |
|
} |
|
|
|
resp.httpResponse.buffers.push(new AWS.util.Buffer(chunk)); |
|
} |
|
}); |
|
|
|
add('HTTP_DONE', 'httpDone', function HTTP_DONE(resp) { |
|
if (resp.httpResponse.buffers && resp.httpResponse.buffers.length > 0) { |
|
var body = AWS.util.buffer.concat(resp.httpResponse.buffers); |
|
resp.httpResponse.body = body; |
|
} |
|
delete resp.httpResponse.numBytes; |
|
delete resp.httpResponse.buffers; |
|
}); |
|
|
|
add('FINALIZE_ERROR', 'retry', function FINALIZE_ERROR(resp) { |
|
if (resp.httpResponse.statusCode) { |
|
resp.error.statusCode = resp.httpResponse.statusCode; |
|
if (resp.error.retryable === undefined) { |
|
resp.error.retryable = this.service.retryableError(resp.error, this); |
|
} |
|
} |
|
}); |
|
|
|
add('INVALIDATE_CREDENTIALS', 'retry', function INVALIDATE_CREDENTIALS(resp) { |
|
if (!resp.error) return; |
|
switch (resp.error.code) { |
|
case 'RequestExpired': // EC2 only |
|
case 'ExpiredTokenException': |
|
case 'ExpiredToken': |
|
resp.error.retryable = true; |
|
resp.request.service.config.credentials.expired = true; |
|
} |
|
}); |
|
|
|
add('REDIRECT', 'retry', function REDIRECT(resp) { |
|
if (resp.error && resp.error.statusCode >= 300 && |
|
resp.error.statusCode < 400 && resp.httpResponse.headers['location']) { |
|
this.httpRequest.endpoint = |
|
new AWS.Endpoint(resp.httpResponse.headers['location']); |
|
resp.error.redirect = true; |
|
resp.error.retryable = true; |
|
} |
|
}); |
|
|
|
add('RETRY_CHECK', 'retry', function RETRY_CHECK(resp) { |
|
if (resp.error) { |
|
if (resp.error.redirect && resp.redirectCount < resp.maxRedirects) { |
|
resp.error.retryDelay = 0; |
|
} else if (resp.error.retryable && resp.retryCount < resp.maxRetries) { |
|
var delays = this.service.retryDelays(); |
|
resp.error.retryDelay = delays[resp.retryCount] || 0; |
|
} |
|
} |
|
}); |
|
|
|
addAsync('RESET_RETRY_STATE', 'afterRetry', function RESET_RETRY_STATE(resp, done) { |
|
var delay, willRetry = false; |
|
|
|
if (resp.error) { |
|
delay = resp.error.retryDelay || 0; |
|
if (resp.error.retryable && resp.retryCount < resp.maxRetries) { |
|
resp.retryCount++; |
|
willRetry = true; |
|
} else if (resp.error.redirect && resp.redirectCount < resp.maxRedirects) { |
|
resp.redirectCount++; |
|
willRetry = true; |
|
} |
|
} |
|
|
|
if (willRetry) { |
|
resp.error = null; |
|
setTimeout(done, delay); |
|
} else { |
|
done(); |
|
} |
|
}); |
|
}), |
|
|
|
CorePost: new SequentialExecutor().addNamedListeners(function(add) { |
|
add('EXTRACT_REQUEST_ID', 'extractData', function EXTRACT_REQUEST_ID(resp) { |
|
resp.requestId = resp.httpResponse.headers['x-amz-request-id'] || |
|
resp.httpResponse.headers['x-amzn-requestid']; |
|
|
|
if (!resp.requestId && resp.data && resp.data.ResponseMetadata) { |
|
resp.requestId = resp.data.ResponseMetadata.RequestId; |
|
} |
|
}); |
|
}), |
|
|
|
Logger: new SequentialExecutor().addNamedListeners(function(add) { |
|
add('LOG_REQUEST', 'complete', function LOG_REQUEST(resp) { |
|
var req = resp.request; |
|
var logger = req.service.config.logger; |
|
if (!logger) return; |
|
|
|
function buildMessage() { |
|
var time = AWS.util.date.getDate().getTime(); |
|
var delta = (time - req.startTime.getTime()) / 1000; |
|
var ansi = logger.isTTY ? true : false; |
|
var status = resp.httpResponse.statusCode; |
|
var params = require('util').inspect(req.params, true, true); |
|
|
|
var message = ''; |
|
if (ansi) message += '\x1B[33m'; |
|
message += '[AWS ' + req.service.serviceIdentifier + ' ' + status; |
|
message += ' ' + delta.toString() + 's ' + resp.retryCount + ' retries]'; |
|
if (ansi) message += '\x1B[0;1m'; |
|
message += ' ' + AWS.util.string.lowerFirst(req.operation); |
|
message += '(' + params + ')'; |
|
if (ansi) message += '\x1B[0m'; |
|
return message; |
|
} |
|
|
|
var line = buildMessage(); |
|
if (typeof logger.log === 'function') { |
|
logger.log(line); |
|
} else if (typeof logger.write === 'function') { |
|
logger.write(line + '\n'); |
|
} |
|
}); |
|
}), |
|
|
|
Json: new SequentialExecutor().addNamedListeners(function(add) { |
|
var svc = require('./protocol/json'); |
|
add('BUILD', 'build', svc.buildRequest); |
|
add('EXTRACT_DATA', 'extractData', svc.extractData); |
|
add('EXTRACT_ERROR', 'extractError', svc.extractError); |
|
}), |
|
|
|
Rest: new SequentialExecutor().addNamedListeners(function(add) { |
|
var svc = require('./protocol/rest'); |
|
add('BUILD', 'build', svc.buildRequest); |
|
add('EXTRACT_DATA', 'extractData', svc.extractData); |
|
add('EXTRACT_ERROR', 'extractError', svc.extractError); |
|
}), |
|
|
|
RestJson: new SequentialExecutor().addNamedListeners(function(add) { |
|
var svc = require('./protocol/rest_json'); |
|
add('BUILD', 'build', svc.buildRequest); |
|
add('EXTRACT_DATA', 'extractData', svc.extractData); |
|
add('EXTRACT_ERROR', 'extractError', svc.extractError); |
|
}), |
|
|
|
RestXml: new SequentialExecutor().addNamedListeners(function(add) { |
|
var svc = require('./protocol/rest_xml'); |
|
add('BUILD', 'build', svc.buildRequest); |
|
add('EXTRACT_DATA', 'extractData', svc.extractData); |
|
add('EXTRACT_ERROR', 'extractError', svc.extractError); |
|
}), |
|
|
|
Query: new SequentialExecutor().addNamedListeners(function(add) { |
|
var svc = require('./protocol/query'); |
|
add('BUILD', 'build', svc.buildRequest); |
|
add('EXTRACT_DATA', 'extractData', svc.extractData); |
|
add('EXTRACT_ERROR', 'extractError', svc.extractError); |
|
}) |
|
}; |
|
|
|
},{"./core":23,"./protocol/json":41,"./protocol/query":42,"./protocol/rest":43,"./protocol/rest_json":44,"./protocol/rest_xml":45,"./sequential_executor":50,"util":20}],30:[function(require,module,exports){ |
|
var AWS = require('./core'); |
|
var inherit = AWS.util.inherit; |
|
|
|
|
|
AWS.Endpoint = inherit({ |
|
|
|
|
|
constructor: function Endpoint(endpoint, config) { |
|
AWS.util.hideProperties(this, ['slashes', 'auth', 'hash', 'search', 'query']); |
|
|
|
if (typeof endpoint === 'undefined' || endpoint === null) { |
|
throw new Error('Invalid endpoint: ' + endpoint); |
|
} else if (typeof endpoint !== 'string') { |
|
return AWS.util.copy(endpoint); |
|
} |
|
|
|
if (!endpoint.match(/^http/)) { |
|
var useSSL = config && config.sslEnabled !== undefined ? |
|
config.sslEnabled : AWS.config.sslEnabled; |
|
endpoint = (useSSL ? 'https' : 'http') + '://' + endpoint; |
|
} |
|
|
|
AWS.util.update(this, AWS.util.urlParse(endpoint)); |
|
|
|
if (this.port) { |
|
this.port = parseInt(this.port, 10); |
|
} else { |
|
this.port = this.protocol === 'https:' ? 443 : 80; |
|
} |
|
} |
|
|
|
}); |
|
|
|
|
|
AWS.HttpRequest = inherit({ |
|
|
|
|
|
constructor: function HttpRequest(endpoint, region) { |
|
endpoint = new AWS.Endpoint(endpoint); |
|
this.method = 'POST'; |
|
this.path = endpoint.path || '/'; |
|
this.headers = {}; |
|
this.body = ''; |
|
this.endpoint = endpoint; |
|
this.region = region; |
|
this.setUserAgent(); |
|
}, |
|
|
|
|
|
setUserAgent: function setUserAgent() { |
|
var prefix = AWS.util.isBrowser() ? 'X-Amz-' : ''; |
|
this.headers[prefix + 'User-Agent'] = AWS.util.userAgent(); |
|
}, |
|
|
|
|
|
pathname: function pathname() { |
|
return this.path.split('?', 1)[0]; |
|
}, |
|
|
|
|
|
search: function search() { |
|
return this.path.split('?', 2)[1] || ''; |
|
} |
|
|
|
}); |
|
|
|
|
|
AWS.HttpResponse = inherit({ |
|
|
|
|
|
constructor: function HttpResponse() { |
|
this.statusCode = undefined; |
|
this.headers = {}; |
|
this.body = undefined; |
|
} |
|
}); |
|
|
|
|
|
AWS.HttpClient = inherit({}); |
|
|
|
|
|
AWS.HttpClient.getInstance = function getInstance() { |
|
if (this.singleton === undefined) { |
|
this.singleton = new this(); |
|
} |
|
return this.singleton; |
|
}; |
|
|
|
},{"./core":23}],31:[function(require,module,exports){ |
|
var AWS = require('../core'); |
|
var EventEmitter = require('events').EventEmitter; |
|
require('../http'); |
|
|
|
|
|
AWS.XHRClient = AWS.util.inherit({ |
|
handleRequest: function handleRequest(httpRequest, httpOptions, callback, errCallback) { |
|
var self = this; |
|
var endpoint = httpRequest.endpoint; |
|
var emitter = new EventEmitter(); |
|
var href = endpoint.protocol + '//' + endpoint.hostname; |
|
if (endpoint.port !== 80 && endpoint.port !== 443) { |
|
href += ':' + endpoint.port; |
|
} |
|
href += httpRequest.path; |
|
|
|
var xhr = new XMLHttpRequest(), headersEmitted = false; |
|
httpRequest.stream = xhr; |
|
|
|
if (httpOptions.timeout) { |
|
xhr.timeout = httpOptions.timeout; |
|
} |
|
|
|
xhr.addEventListener('readystatechange', function() { |
|
try { |
|
if (xhr.status === 0) return; // 0 code is invalid |
|
} catch (e) { return; } |
|
|
|
if (this.readyState >= this.HEADERS_RECEIVED && !headersEmitted) { |
|
try { xhr.responseType = 'arraybuffer'; } catch (e) {} |
|
emitter.statusCode = xhr.status; |
|
emitter.headers = self.parseHeaders(xhr.getAllResponseHeaders()); |
|
emitter.emit('headers', emitter.statusCode, emitter.headers); |
|
headersEmitted = true; |
|
} |
|
if (this.readyState === this.DONE) { |
|
self.finishRequest(xhr, emitter); |
|
} |
|
}, false); |
|
xhr.upload.addEventListener('progress', function (evt) { |
|
emitter.emit('sendProgress', evt); |
|
}); |
|
xhr.addEventListener('progress', function (evt) { |
|
emitter.emit('receiveProgress', evt); |
|
}, false); |
|
xhr.addEventListener('timeout', function () { |
|
errCallback(AWS.util.error(new Error('Timeout'), {code: 'TimeoutError'})); |
|
}, false); |
|
xhr.addEventListener('error', function () { |
|
errCallback(AWS.util.error(new Error('Network Failure'), { |
|
code: 'NetworkingError' |
|
})); |
|
}, false); |
|
|
|
callback(emitter); |
|
xhr.open(httpRequest.method, href, httpOptions.xhrAsync !== false); |
|
AWS.util.each(httpRequest.headers, function (key, value) { |
|
if (key !== 'Content-Length' && key !== 'User-Agent' && key !== 'Host') { |
|
xhr.setRequestHeader(key, value); |
|
} |
|
}); |
|
|
|
if (httpRequest.body && typeof httpRequest.body.buffer === 'object') { |
|
xhr.send(httpRequest.body.buffer); // typed arrays sent as ArrayBuffer |
|
} else { |
|
xhr.send(httpRequest.body); |
|
} |
|
|
|
return emitter; |
|
}, |
|
|
|
parseHeaders: function parseHeaders(rawHeaders) { |
|
var headers = {}; |
|
AWS.util.arrayEach(rawHeaders.split(/\r?\n/), function (line) { |
|
var key = line.split(':', 1)[0]; |
|
var value = line.substring(key.length + 2); |
|
if (key.length > 0) headers[key] = value; |
|
}); |
|
return headers; |
|
}, |
|
|
|
finishRequest: function finishRequest(xhr, emitter) { |
|
var buffer; |
|
if (xhr.responseType === 'arraybuffer' && xhr.response) { |
|
var ab = xhr.response; |
|
buffer = new AWS.util.Buffer(ab.byteLength); |
|
var view = new Uint8Array(ab); |
|
for (var i = 0; i < buffer.length; ++i) { |
|
buffer[i] = view[i]; |
|
} |
|
} |
|
|
|
try { |
|
if (!buffer && typeof xhr.responseText === 'string') { |
|
buffer = new AWS.util.Buffer(xhr.responseText); |
|
} |
|
} catch (e) {} |
|
|
|
if (buffer) emitter.emit('data', buffer); |
|
emitter.emit('end'); |
|
} |
|
}); |
|
|
|
|
|
AWS.HttpClient.prototype = AWS.XHRClient.prototype; |
|
|
|
|
|
AWS.HttpClient.streamsApiVersion = 1; |
|
|
|
},{"../core":23,"../http":30,"events":11}],32:[function(require,module,exports){ |
|
var util = require('../util'); |
|
|
|
function JsonBuilder() { } |
|
|
|
JsonBuilder.prototype.build = function(value, shape) { |
|
return JSON.stringify(translate(value, shape)); |
|
}; |
|
|
|
function translate(value, shape) { |
|
if (!shape || value === undefined || value === null) return undefined; |
|
|
|
switch (shape.type) { |
|
case 'structure': return translateStructure(value, shape); |
|
case 'map': return translateMap(value, shape); |
|
case 'list': return translateList(value, shape); |
|
default: return translateScalar(value, shape); |
|
} |
|
} |
|
|
|
function translateStructure(structure, shape) { |
|
var struct = {}; |
|
util.each(structure, function(name, value) { |
|
var memberShape = shape.members[name]; |
|
if (memberShape) { |
|
if (memberShape.location !== 'body') return; |
|
|
|
var result = translate(value, memberShape); |
|
if (result !== undefined) struct[name] = result; |
|
} |
|
}); |
|
return struct; |
|
} |
|
|
|
function translateList(list, shape) { |
|
var out = []; |
|
util.arrayEach(list, function(value) { |
|
var result = translate(value, shape.member); |
|
if (result !== undefined) out.push(result); |
|
}); |
|
return out; |
|
} |
|
|
|
function translateMap(map, shape) { |
|
var out = {}; |
|
util.each(map, function(key, value) { |
|
var result = translate(value, shape.value); |
|
if (result !== undefined) out[key] = result; |
|
}); |
|
return out; |
|
} |
|
|
|
function translateScalar(value, shape) { |
|
return shape.toWireFormat(value); |
|
} |
|
|
|
module.exports = JsonBuilder; |
|
|
|
},{"../util":60}],33:[function(require,module,exports){ |
|
var util = require('../util'); |
|
|
|
function JsonParser() { } |
|
|
|
JsonParser.prototype.parse = function(value, shape) { |
|
return translate(JSON.parse(value), shape); |
|
}; |
|
|
|
function translate(value, shape) { |
|
if (!shape || value === undefined || value === null) return undefined; |
|
|
|
switch (shape.type) { |
|
case 'structure': return translateStructure(value, shape); |
|
case 'map': return translateMap(value, shape); |
|
case 'list': return translateList(value, shape); |
|
default: return translateScalar(value, shape); |
|
} |
|
} |
|
|
|
function translateStructure(structure, shape) { |
|
var struct = {}; |
|
util.each(structure, function(name, value) { |
|
var memberShape = shape.members[name]; |
|
if (memberShape) { |
|
var result = translate(value, memberShape); |
|
if (result !== undefined) struct[name] = result; |
|
} |
|
}); |
|
return struct; |
|
} |
|
|
|
function translateList(list, shape) { |
|
var out = []; |
|
util.arrayEach(list, function(value) { |
|
var result = translate(value, shape.member); |
|
if (result !== undefined) out.push(result); |
|
}); |
|
return out; |
|
} |
|
|
|
function translateMap(map, shape) { |
|
var out = {}; |
|
util.each(map, function(key, value) { |
|
var result = translate(value, shape.value); |
|
if (result !== undefined) out[key] = result; |
|
}); |
|
return out; |
|
} |
|
|
|
function translateScalar(value, shape) { |
|
return shape.toType(value); |
|
} |
|
|
|
module.exports = JsonParser; |
|
|
|
},{"../util":60}],34:[function(require,module,exports){ |
|
var Collection = require('./collection'); |
|
var Operation = require('./operation'); |
|
var Shape = require('./shape'); |
|
var Paginator = require('./paginator'); |
|
var ResourceWaiter = require('./resource_waiter'); |
|
|
|
var util = require('../util'); |
|
var property = util.property; |
|
var memoizedProperty = util.memoizedProperty; |
|
|
|
function Api(api, options) { |
|
api = api || {}; |
|
options = options || {}; |
|
options.api = this; |
|
|
|
api.metadata = api.metadata || {}; |
|
|
|
property(this, 'isApi', true, false); |
|
property(this, 'apiVersion', api.metadata.apiVersion); |
|
property(this, 'endpointPrefix', api.metadata.endpointPrefix); |
|
property(this, 'globalEndpoint', api.metadata.globalEndpoint); |
|
property(this, 'signatureVersion', api.metadata.signatureVersion); |
|
property(this, 'jsonVersion', api.metadata.jsonVersion); |
|
property(this, 'targetPrefix', api.metadata.targetPrefix); |
|
property(this, 'protocol', api.metadata.protocol); |
|
property(this, 'timestampFormat', api.metadata.timestampFormat); |
|
property(this, 'xmlNamespaceUri', api.metadata.xmlNamespace); |
|
property(this, 'abbreviation', api.metadata.serviceAbbreviation); |
|
property(this, 'fullName', api.metadata.serviceFullName); |
|
|
|
memoizedProperty(this, 'className', function() { |
|
var name = api.metadata.serviceAbbreviation || api.metadata.serviceFullName; |
|
if (!name) return null; |
|
|
|
name = name.replace(/^Amazon|AWS\s*|\(.*|\s+|\W+/g, ''); |
|
if (name === 'ElasticLoadBalancing') name = 'ELB'; |
|
return name; |
|
}); |
|
|
|
property(this, 'operations', new Collection(api.operations, options, function(name, operation) { |
|
return new Operation(name, operation, options); |
|
}, util.string.lowerFirst)); |
|
|
|
property(this, 'shapes', new Collection(api.shapes, options, function(name, shape) { |
|
return Shape.create(shape, options); |
|
})); |
|
|
|
property(this, 'paginators', new Collection(api.paginators, options, function(name, paginator) { |
|
return new Paginator(name, paginator, options); |
|
})); |
|
|
|
property(this, 'waiters', new Collection(api.waiters, options, function(name, waiter) { |
|
return new ResourceWaiter(name, waiter, options); |
|
}, util.string.lowerFirst)); |
|
|
|
if (options.documentation) { |
|
property(this, 'documentation', api.documentation); |
|
property(this, 'documentationUrl', api.documentationUrl); |
|
} |
|
} |
|
|
|
module.exports = Api; |
|
|
|
},{"../util":60,"./collection":35,"./operation":36,"./paginator":37,"./resource_waiter":38,"./shape":39}],35:[function(require,module,exports){ |
|
var memoizedProperty = require('../util').memoizedProperty; |
|
|
|
function Collection(iterable, options, fn, nameTr) { |
|
nameTr = nameTr || String; |
|
var self = this; |
|
|
|
for (var id in iterable) { |
|
if (iterable.hasOwnProperty(id)) { |
|
(function(name) { |
|
memoizedProperty(self, nameTr(name), function() { |
|
return fn(name, iterable[name]); |
|
}); |
|
})(id); |
|
} |
|
} |
|
} |
|
|
|
module.exports = Collection; |
|
|
|
},{"../util":60}],36:[function(require,module,exports){ |
|
var Shape = require('./shape'); |
|
|
|
var util = require('../util'); |
|
var property = util.property; |
|
var memoizedProperty = util.memoizedProperty; |
|
|
|
function Operation(name, operation, options) { |
|
options = options || {}; |
|
|
|
property(this, 'name', name); |
|
property(this, 'api', options.api, false); |
|
|
|
operation.http = operation.http || {}; |
|
property(this, 'httpMethod', operation.http.method || 'POST'); |
|
property(this, 'httpPath', operation.http.requestUri || '/'); |
|
|
|
memoizedProperty(this, 'input', function() { |
|
if (!operation.input) { |
|
return new Shape.create({type: 'structure'}, options); |
|
} |
|
return Shape.create(operation.input, options); |
|
}); |
|
|
|
memoizedProperty(this, 'output', function() { |
|
if (!operation.output) { |
|
return new Shape.create({type: 'structure'}, options); |
|
} |
|
return Shape.create(operation.output, options); |
|
}); |
|
|
|
memoizedProperty(this, 'errors', function() { |
|
var list = []; |
|
if (!operation.errors) return null; |
|
|
|
for (var i = 0; i < operation.errors.length; i++) { |
|
list.push(Shape.create(operation.errors[i], options)); |
|
} |
|
|
|
return list; |
|
}); |
|
|
|
memoizedProperty(this, 'paginator', function() { |
|
return options.api.paginators[name]; |
|
}); |
|
|
|
if (options.documentation) { |
|
property(this, 'documentation', operation.documentation); |
|
property(this, 'documentationUrl', operation.documentationUrl); |
|
} |
|
} |
|
|
|
module.exports = Operation; |
|
|
|
},{"../util":60,"./shape":39}],37:[function(require,module,exports){ |
|
var property = require('../util').property; |
|
|
|
function Paginator(name, paginator) { |
|
property(this, 'inputToken', paginator.input_token); |
|
property(this, 'limitKey', paginator.limit_key); |
|
property(this, 'moreResults', paginator.more_results); |
|
property(this, 'outputToken', paginator.output_token); |
|
property(this, 'resultKey', paginator.result_key); |
|
} |
|
|
|
module.exports = Paginator; |
|
|
|
},{"../util":60}],38:[function(require,module,exports){ |
|
var Shape = require('./shape'); |
|
var StructureShape = Shape.shapes.StructureShape; |
|
|
|
var util = require('../util'); |
|
var property = util.property; |
|
var memoizedProperty = util.memoizedProperty; |
|
|
|
function ResourceWaiter(name, waiter, options) { |
|
options = options || {}; |
|
|
|
function InnerResourceWaiter() { |
|
property(this, 'name', name); |
|
property(this, 'api', options.api, false); |
|
|
|
if (waiter.operation) { |
|
property(this, 'operation', util.string.lowerFirst(waiter.operation)); |
|
} |
|
|
|
var self = this, map = { |
|
ignoreErrors: 'ignore_errors', |
|
successType: 'success_type', |
|
successValue: 'success_value', |
|
successPath: 'success_path', |
|
acceptorType: 'acceptor_type', |
|
acceptorValue: 'acceptor_value', |
|
acceptorPath: 'acceptor_path', |
|
failureType: 'failure_type', |
|
failureValue: 'failure_value', |
|
failurePath: 'success_path', |
|
interval: 'interval', |
|
maxAttempts: 'max_attempts' |
|
}; |
|
Object.keys(map).forEach(function(key) { |
|
var value = waiter[map[key]]; |
|
if (value) property(self, key, value); |
|
}); |
|
} |
|
|
|
if (options.api) { |
|
var proto = null; |
|
if (waiter['extends']) { |
|
proto = options.api.waiters[waiter['extends']]; |
|
} else if (name !== '__default__') { |
|
proto = options.api.waiters['__default__']; |
|
} |
|
|
|
if (proto) InnerResourceWaiter.prototype = proto; |
|
} |
|
|
|
return new InnerResourceWaiter(); |
|
} |
|
|
|
module.exports = ResourceWaiter; |
|
|
|
},{"../util":60,"./shape":39}],39:[function(require,module,exports){ |
|
var Collection = require('./collection'); |
|
|
|
var util = require('../util'); |
|
|
|
function property(obj, name, value) { |
|
if (value !== null && value !== undefined) { |
|
util.property.apply(this, arguments); |
|
} |
|
} |
|
|
|
function memoizedProperty(obj, name) { |
|
if (!obj.constructor.prototype[name]) { |
|
util.memoizedProperty.apply(this, arguments); |
|
} |
|
} |
|
|
|
function Shape(shape, options, memberName) { |
|
options = options || {}; |
|
|
|
property(this, 'shape', shape.shape); |
|
property(this, 'api', options.api, false); |
|
property(this, 'type', shape.type); |
|
property(this, 'location', shape.location || 'body'); |
|
property(this, 'queryName', shape.queryName); |
|
property(this, 'queryFlattened', shape.queryFlattened); |
|
property(this, 'name', this.name || shape.xmlName || shape.locationName || |
|
memberName); |
|
property(this, 'isStreaming', shape.streaming || false); |
|
property(this, 'isComposite', shape.isComposite || false); |
|
property(this, 'isShape', true, false); |
|
|
|
if (options.documentation) { |
|
property(this, 'documentation', shape.documentation); |
|
property(this, 'documentationUrl', shape.documentationUrl); |
|
} |
|
|
|
if (shape.xmlAttribute) { |
|
property(this, 'isXmlAttribute', shape.xmlAttribute || false); |
|
} |
|
|
|
property(this, 'defaultValue', null); |
|
this.toWireFormat = function(value) { |
|
if (value === null || value === undefined) return ''; |
|
return value; |
|
}; |
|
this.toType = function(value) { return value; }; |
|
} |
|
|
|
Shape.normalizedTypes = { |
|
character: 'string', |
|
double: 'float', |
|
long: 'integer', |
|
short: 'integer', |
|
biginteger: 'integer', |
|
bigdecimal: 'float', |
|
blob: 'binary' |
|
}; |
|
|
|
Shape.types = { |
|
structure: StructureShape, |
|
list: ListShape, |
|
map: MapShape, |
|
boolean: BooleanShape, |
|
timestamp: TimestampShape, |
|
float: FloatShape, |
|
integer: IntegerShape, |
|
string: StringShape, |
|
base64: Base64Shape, |
|
binary: BinaryShape |
|
}; |
|
|
|
Shape.resolve = function resolve(shape, options) { |
|
if (shape.shape) { |
|
var refShape = options.api.shapes[shape.shape]; |
|
if (!refShape) { |
|
throw new Error('Cannot find shape reference: ' + shape.shape); |
|
} |
|
|
|
return refShape; |
|
} else { |
|
return null; |
|
} |
|
}; |
|
|
|
Shape.create = function create(shape, options, memberName) { |
|
if (shape.isShape) return shape; |
|
|
|
var refShape = Shape.resolve(shape, options); |
|
if (refShape) { |
|
var filteredKeys = Object.keys(shape); |
|
if (!options.documentation) { |
|
filteredKeys = filteredKeys.filter(function(name) { |
|
return !name.match(/documentation/); |
|
}); |
|
} |
|
if (filteredKeys === ['shape']) { // no inline customizations |
|
return refShape; |
|
} |
|
|
|
var InlineShape = function() { |
|
refShape.constructor.call(this, shape, options, memberName); |
|
}; |
|
InlineShape.prototype = refShape; |
|
return new InlineShape(); |
|
} else { |
|
if (!shape.type) { |
|
if (shape.members) shape.type = 'structure'; |
|
else if (shape.member) shape.type = 'list'; |
|
else if (shape.key) shape.type = 'map'; |
|
else shape.type = 'string'; |
|
} |
|
|
|
var origType = shape.type; |
|
if (Shape.normalizedTypes[shape.type]) { |
|
shape.type = Shape.normalizedTypes[shape.type]; |
|
} |
|
|
|
if (Shape.types[shape.type]) { |
|
return new Shape.types[shape.type](shape, options, memberName); |
|
} else { |
|
throw new Error('Unrecognized shape type: ' + origType); |
|
} |
|
} |
|
}; |
|
|
|
function CompositeShape(shape) { |
|
Shape.apply(this, arguments); |
|
property(this, 'isComposite', true); |
|
|
|
if (shape.flattened) { |
|
property(this, 'flattened', shape.flattened || false); |
|
} |
|
} |
|
|
|
function StructureShape(shape, options) { |
|
var requiredMap = null, firstInit = !this.isShape; |
|
|
|
CompositeShape.apply(this, arguments); |
|
|
|
if (firstInit) { |
|
property(this, 'defaultValue', function() { return {}; }); |
|
property(this, 'members', {}); |
|
property(this, 'memberNames', []); |
|
property(this, 'required', []); |
|
property(this, 'isRequired', function(name) { return false; }); |
|
} |
|
|
|
if (shape.members) { |
|
property(this, 'members', new Collection(shape.members, options, function(name, member) { |
|
return Shape.create(member, options, name); |
|
})); |
|
memoizedProperty(this, 'memberNames', function() { |
|
return shape.xmlOrder || Object.keys(shape.members); |
|
}); |
|
} |
|
|
|
if (shape.required) { |
|
property(this, 'required', shape.required); |
|
property(this, 'isRequired', function(name) { |
|
if (!requiredMap) { |
|
requiredMap = {}; |
|
for (var i = 0; i < shape.required.length; i++) { |
|
requiredMap[shape.required[i]] = true; |
|
} |
|
} |
|
|
|
return requiredMap[name]; |
|
}, false, true); |
|
} |
|
|
|
property(this, 'resultWrapper', shape.resultWrapper || null); |
|
|
|
if (shape.payload) { |
|
property(this, 'payload', shape.payload); |
|
} |
|
|
|
if (typeof shape.xmlNamespace === 'string') { |
|
property(this, 'xmlNamespaceUri', shape.xmlNamespace); |
|
} else if (typeof shape.xmlNamespace === 'object') { |
|
property(this, 'xmlNamespacePrefix', shape.xmlNamespace.prefix); |
|
property(this, 'xmlNamespaceUri', shape.xmlNamespace.uri); |
|
} |
|
} |
|
|
|
function ListShape(shape, options) { |
|
var self = this, firstInit = !this.isShape; |
|
CompositeShape.apply(this, arguments); |
|
|
|
if (firstInit) { |
|
property(this, 'defaultValue', function() { return []; }); |
|
} |
|
|
|
if (shape.member) { |
|
memoizedProperty(this, 'member', function() { |
|
return Shape.create(shape.member, options); |
|
}); |
|
} |
|
|
|
if (this.flattened) { |
|
var oldName = this.name; |
|
memoizedProperty(this, 'name', function() { |
|
return self.member.name || oldName; |
|
}); |
|
} |
|
} |
|
|
|
function MapShape(shape, options) { |
|
var firstInit = !this.isShape; |
|
CompositeShape.apply(this, arguments); |
|
|
|
if (firstInit) { |
|
property(this, 'defaultValue', function() { return {}; }); |
|
property(this, 'key', Shape.create({type: 'string'}, options)); |
|
property(this, 'value', Shape.create({type: 'string'}, options)); |
|
} |
|
|
|
if (shape.key) { |
|
memoizedProperty(this, 'key', function() { |
|
return Shape.create(shape.key, options); |
|
}); |
|
} |
|
if (shape.value) { |
|
memoizedProperty(this, 'value', function() { |
|
return Shape.create(shape.value, options); |
|
}); |
|
} |
|
} |
|
|
|
function TimestampShape(shape) { |
|
var self = this; |
|
Shape.apply(this, arguments); |
|
|
|
if (shape.timestampFormat) { |
|
property(this, 'timestampFormat', shape.timestampFormat); |
|
} else if (this.api) { |
|
property(this, 'timestampFormat', this.api.timestampFormat); |
|
} |
|
|
|
this.toType = function(value) { |
|
if (value === null || value === undefined) return null; |
|
if (typeof value.toUTCString === 'function') return value; |
|
return typeof value === 'string' ? util.date.parseTimestamp(value) : null; |
|
}; |
|
|
|
this.toWireFormat = function(value) { |
|
return util.date.format(value, self.timestampFormat); |
|
}; |
|
} |
|
|
|
function StringShape() { |
|
Shape.apply(this, arguments); |
|
} |
|
|
|
function FloatShape() { |
|
Shape.apply(this, arguments); |
|
|
|
this.toType = function(value) { |
|
if (value === null || value === undefined) return null; |
|
return parseFloat(value); |
|
}; |
|
this.toWireFormat = this.toType; |
|
} |
|
|
|
function IntegerShape() { |
|
Shape.apply(this, arguments); |
|
|
|
this.toType = function(value) { |
|
if (value === null || value === undefined) return null; |
|
return parseInt(value, 10); |
|
}; |
|
this.toWireFormat = this.toType; |
|
} |
|
|
|
function BinaryShape() { |
|
Shape.apply(this, arguments); |
|
this.toType = util.base64.decode; |
|
this.toWireFormat = util.base64.encode; |
|
} |
|
|
|
function Base64Shape() { |
|
BinaryShape.apply(this, arguments); |
|
} |
|
|
|
function BooleanShape() { |
|
Shape.apply(this, arguments); |
|
|
|
this.toType = function(value) { |
|
if (value === null || value === undefined) return null; |
|
return value === 'true'; |
|
}; |
|
} |
|
|
|
Shape.shapes = { |
|
StructureShape: StructureShape, |
|
ListShape: ListShape, |
|
MapShape: MapShape, |
|
StringShape: StringShape, |
|
BooleanShape: BooleanShape, |
|
Base64Shape: Base64Shape |
|
}; |
|
|
|
module.exports = Shape; |
|
|
|
},{"../util":60,"./collection":35}],40:[function(require,module,exports){ |
|
var AWS = require('./core'); |
|
|
|
|
|
AWS.ParamValidator = AWS.util.inherit({ |
|
validate: function validate(shape, params, context) { |
|
return this.validateMember(shape, params || {}, context || 'params'); |
|
}, |
|
|
|
validateStructure: function validateStructure(shape, params, context) { |
|
this.validateType(context, params, ['object'], 'structure'); |
|
|
|
for (var i = 0; shape.required && i < shape.required.length; i++) { |
|
var paramName = shape.required[i]; |
|
var value = params[paramName]; |
|
if (value === undefined || value === null) { |
|
this.fail('MissingRequiredParameter', |
|
'Missing required key \'' + paramName + '\' in ' + context); |
|
} |
|
} |
|
|
|
for (paramName in params) { |
|
if (!params.hasOwnProperty(paramName)) continue; |
|
|
|
var paramValue = params[paramName], |
|
memberShape = shape.members[paramName]; |
|
|
|
if (memberShape !== undefined) { |
|
var memberContext = [context, paramName].join('.'); |
|
this.validateMember(memberShape, paramValue, memberContext); |
|
} else { |
|
this.fail('UnexpectedParameter', |
|
'Unexpected key \'' + paramName + '\' found in ' + context); |
|
} |
|
} |
|
|
|
return true; |
|
}, |
|
|
|
validateMember: function validateMember(shape, param, context) { |
|
switch(shape.type) { |
|
case 'structure': |
|
return this.validateStructure(shape, param, context); |
|
case 'list': |
|
return this.validateList(shape, param, context); |
|
case 'map': |
|
return this.validateMap(shape, param, context); |
|
default: |
|
return this.validateScalar(shape, param, context); |
|
} |
|
}, |
|
|
|
validateList: function validateList(shape, params, context) { |
|
this.validateType(context, params, [Array]); |
|
|
|
for (var i = 0; i < params.length; i++) { |
|
this.validateMember(shape.member, params[i], context + '[' + i + ']'); |
|
} |
|
}, |
|
|
|
validateMap: function validateMap(shape, params, context) { |
|
this.validateType(context, params, ['object'], 'map'); |
|
|
|
for (var param in params) { |
|
if (!params.hasOwnProperty(param)) continue; |
|
this.validateMember(shape.value, params[param], |
|
context + '[\'' + param + '\']'); |
|
} |
|
}, |
|
|
|
validateScalar: function validateScalar(shape, value, context) { |
|
switch (shape.type) { |
|
case null: |
|
case undefined: |
|
case 'string': |
|
return this.validateType(context, value, ['string']); |
|
case 'base64': |
|
case 'binary': |
|
return this.validatePayload(context, value); |
|
case 'integer': |
|
case 'float': |
|
return this.validateNumber(context, value); |
|
case 'boolean': |
|
return this.validateType(context, value, ['boolean']); |
|
case 'timestamp': |
|
return this.validateType(context, value, [Date, |
|
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/, 'number'], |
|
'Date object, ISO-8601 string, or a UNIX timestamp'); |
|
default: |
|
return this.fail('UnkownType', 'Unhandled type ' + |
|
shape.type + ' for ' + context); |
|
} |
|
}, |
|
|
|
fail: function fail(code, message) { |
|
throw AWS.util.error(new Error(message), {code: code}); |
|
}, |
|
|
|
validateType: function validateType(context, value, acceptedTypes, type) { |
|
if (value === null || value === undefined) return; |
|
|
|
var foundInvalidType = false; |
|
for (var i = 0; i < acceptedTypes.length; i++) { |
|
if (typeof acceptedTypes[i] === 'string') { |
|
if (typeof value === acceptedTypes[i]) return; |
|
} else if (acceptedTypes[i] instanceof RegExp) { |
|
if ((value || '').toString().match(acceptedTypes[i])) return; |
|
} else { |
|
if (value instanceof acceptedTypes[i]) return; |
|
if (AWS.util.isType(value, acceptedTypes[i])) return; |
|
if (!type && !foundInvalidType) acceptedTypes = acceptedTypes.slice(); |
|
acceptedTypes[i] = AWS.util.typeName(acceptedTypes[i]); |
|
} |
|
foundInvalidType = true; |
|
} |
|
|
|
var acceptedType = type; |
|
if (!acceptedType) { |
|
acceptedType = acceptedTypes.join(', ').replace(/,([^,]+)$/, ', or$1'); |
|
} |
|
|
|
var vowel = acceptedType.match(/^[aeiou]/i) ? 'n' : ''; |
|
this.fail('InvalidParameterType', 'Expected ' + context + ' to be a' + |
|
vowel + ' ' + acceptedType); |
|
}, |
|
|
|
validateNumber: function validateNumber(context, value) { |
|
if (value === null || value === undefined) return; |
|
if (typeof value === 'string') { |
|
var castedValue = parseFloat(value); |
|
if (castedValue.toString() === value) value = castedValue; |
|
} |
|
this.validateType(context, value, ['number']); |
|
}, |
|
|
|
validatePayload: function validatePayload(context, value) { |
|
if (value === null || value === undefined) return; |
|
if (typeof value === 'string') return; |
|
if (value && typeof value.byteLength === 'number') return; // typed arrays |
|
if (AWS.util.isNode()) { // special check for buffer/stream in Node.js |
|
var Stream = AWS.util.nodeRequire('stream').Stream; |
|
if (AWS.util.Buffer.isBuffer(value) || value instanceof Stream) return; |
|
} |
|
|
|
var types = ['Buffer', 'Stream', 'File', 'Blob', 'ArrayBuffer', 'DataView']; |
|
if (value) { |
|
for (var i = 0; i < types.length; i++) { |
|
if (AWS.util.isType(value, types[i])) return; |
|
if (AWS.util.typeName(value.constructor) === types[i]) return; |
|
} |
|
} |
|
|
|
this.fail('InvalidParameterType', 'Expected ' + context + ' to be a ' + |
|
'string, Buffer, Stream, Blob, or typed array object'); |
|
} |
|
}); |
|
|
|
},{"./core":23}],41:[function(require,module,exports){ |
|
var util = require('../util'); |
|
var JsonBuilder = require('../json/builder'); |
|
var JsonParser = require('../json/parser'); |
|
|
|
function buildRequest(req) { |
|
var httpRequest = req.httpRequest; |
|
var api = req.service.api; |
|
var target = api.targetPrefix + '.' + api.operations[req.operation].name; |
|
var version = api.jsonVersion || '1.0'; |
|
var input = api.operations[req.operation].input; |
|
var builder = new JsonBuilder(); |
|
|
|
if (version === 1) version = '1.0'; |
|
httpRequest.body = builder.build(req.params || {}, input); |
|
httpRequest.headers['Content-Type'] = 'application/x-amz-json-' + version; |
|
httpRequest.headers['X-Amz-Target'] = target; |
|
} |
|
|
|
function extractError(resp) { |
|
var error = {}; |
|
var httpResponse = resp.httpResponse; |
|
|
|
if (httpResponse.body.length > 0) { |
|
var e = JSON.parse(httpResponse.body.toString()); |
|
if (e.__type || e.code) { |
|
error.code = (e.__type || e.code).split('#').pop(); |
|
} else { |
|
error.code = 'UnknownError'; |
|
} |
|
if (error.code === 'RequestEntityTooLarge') { |
|
error.message = 'Request body must be less than 1 MB'; |
|
} else { |
|
error.message = (e.message || e.Message || null); |
|
} |
|
} else { |
|
error.code = httpResponse.statusCode; |
|
error.message = null; |
|
} |
|
|
|
resp.error = util.error(new Error(), error); |
|
} |
|
|
|
function extractData(resp) { |
|
var body = resp.httpResponse.body.toString() || '{}'; |
|
if (resp.request.service.config.convertResponseTypes === false) { |
|
resp.data = JSON.parse(body); |
|
} else { |
|
var operation = resp.request.service.api.operations[resp.request.operation]; |
|
var shape = operation.output || {}; |
|
var parser = new JsonParser(); |
|
resp.data = parser.parse(body, shape); |
|
} |
|
} |
|
|
|
module.exports = { |
|
buildRequest: buildRequest, |
|
extractError: extractError, |
|
extractData: extractData |
|
}; |
|
|
|
},{"../json/builder":32,"../json/parser":33,"../util":60}],42:[function(require,module,exports){ |
|
var AWS = require('../core'); |
|
var util = require('../util'); |
|
var QueryParamSerializer = require('../query/query_param_serializer'); |
|
var Shape = require('../model/shape'); |
|
|
|
function buildRequest(req) { |
|
var operation = req.service.api.operations[req.operation]; |
|
var httpRequest = req.httpRequest; |
|
httpRequest.headers['Content-Type'] = |
|
'application/x-www-form-urlencoded; charset=utf-8'; |
|
httpRequest.params = { |
|
Version: req.service.api.apiVersion, |
|
Action: operation.name |
|
}; |
|
|
|
var builder = new QueryParamSerializer(); |
|
builder.serialize(req.params, operation.input, function(name, value) { |
|
httpRequest.params[name] = value; |
|
}); |
|
httpRequest.body = util.queryParamsToString(httpRequest.params); |
|
} |
|
|
|
function extractError(resp) { |
|
var data, body = resp.httpResponse.body.toString(); |
|
if (body.match('<UnknownOperationException')) { |
|
data = { |
|
Code: 'UnknownOperation', |
|
Message: 'Unknown operation ' + resp.request.operation |
|
}; |
|
} else { |
|
data = new AWS.XML.Parser().parse(body); |
|
} |
|
|
|
if (data.Errors) data = data.Errors; |
|
if (data.Error) data = data.Error; |
|
if (data.Code) { |
|
resp.error = util.error(new Error(), { |
|
code: data.Code, |
|
message: data.Message |
|
}); |
|
} else { |
|
resp.error = util.error(new Error(), { |
|
code: resp.httpResponse.statusCode, |
|
message: null |
|
}); |
|
} |
|
} |
|
|
|
function extractData(resp) { |
|
var req = resp.request; |
|
var operation = req.service.api.operations[req.operation]; |
|
var shape = operation.output || {}; |
|
var origRules = shape; |
|
|
|
if (origRules.resultWrapper) { |
|
var tmp = Shape.create({type: 'structure'}); |
|
tmp.members[origRules.resultWrapper] = shape; |
|
tmp.memberNames = [origRules.resultWrapper]; |
|
util.property(shape, 'name', shape.resultWrapper); |
|
shape = tmp; |
|
} |
|
|
|
var parser = new AWS.XML.Parser(); |
|
var data = parser.parse(resp.httpResponse.body.toString(), shape); |
|
|
|
if (origRules.resultWrapper) { |
|
if (data[origRules.resultWrapper]) { |
|
util.update(data, data[origRules.resultWrapper]); |
|
delete data[origRules.resultWrapper]; |
|
} |
|
} |
|
|
|
resp.data = data; |
|
} |
|
|
|
module.exports = { |
|
buildRequest: buildRequest, |
|
extractError: extractError, |
|
extractData: extractData |
|
}; |
|
|
|
},{"../core":23,"../model/shape":39,"../query/query_param_serializer":46,"../util":60}],43:[function(require,module,exports){ |
|
var util = require('../util'); |
|
|
|
function populateMethod(req) { |
|
req.httpRequest.method = req.service.api.operations[req.operation].httpMethod; |
|
} |
|
|
|
function populateURI(req) { |
|
var operation = req.service.api.operations[req.operation]; |
|
var input = operation.input; |
|
var uri = [req.httpRequest.endpoint.path, operation.httpPath].join('/'); |
|
uri = uri.replace(/\/+/g, '/'); |
|
|
|
var escapePathParamFn = req.service.escapePathParam || escapePathParam; |
|
var escapeQuerystringParamFn = req.service.escapeQuerystringParam || |
|
escapeQuerystringParam; |
|
|
|
var queryString = {}, queryStringSet = false; |
|
util.each(input.members, function (name, member) { |
|
var paramValue = req.params[name]; |
|
if (paramValue === null || paramValue === undefined) return; |
|
if (member.location === 'uri') { |
|
uri = uri.replace('{' + member.name + '}', escapePathParamFn(paramValue)); |
|
} else if (member.location === 'querystring') { |
|
queryStringSet = true; |
|
queryString[member.name] = escapeQuerystringParamFn(paramValue); |
|
} |
|
}); |
|
|
|
if (queryStringSet) { |
|
uri += (uri.indexOf('?') >= 0 ? '&' : '?'); |
|
var parts = []; |
|
util.arrayEach(Object.keys(queryString).sort(), function(key) { |
|
parts.push(escapeQuerystringParam(key) + '=' + queryString[key]); |
|
}); |
|
uri += parts.join('&'); |
|
} |
|
|
|
req.httpRequest.path = uri; |
|
} |
|
|
|
function escapePathParam(value) { |
|
return util.uriEscape(String(value)); |
|
} |
|
|
|
function escapeQuerystringParam(value) { |
|
return util.uriEscape(String(value)); |
|
} |
|
|
|
function populateHeaders(req) { |
|
var operation = req.service.api.operations[req.operation]; |
|
util.each(operation.input.members, function (name, member) { |
|
var value = req.params[name]; |
|
if (value === null || value === undefined) return; |
|
|
|
if (member.location === 'headers' && member.type === 'map') { |
|
util.each(value, function(key, value) { |
|
req.httpRequest.headers[member.name + key] = value; |
|
}); |
|
} else if (member.location === 'header') { |
|
value = member.toWireFormat(value).toString(); |
|
req.httpRequest.headers[member.name] = value; |
|
} |
|
}); |
|
} |
|
|
|
function buildRequest(req) { |
|
populateMethod(req); |
|
populateURI(req); |
|
populateHeaders(req); |
|
} |
|
|
|
function extractError() { |
|
} |
|
|
|
function extractData(resp) { |
|
var req = resp.request; |
|
var data = {}; |
|
var r = resp.httpResponse; |
|
var operation = req.service.api.operations[req.operation]; |
|
var output = operation.output; |
|
|
|
var headers = {}; |
|
util.each(r.headers, function (k, v) { |
|
headers[k.toLowerCase()] = v; |
|
}); |
|
|
|
util.each(output.members, function(name, member) { |
|
var header = (member.name || name).toLowerCase(); |
|
if (member.location === 'headers' && member.type === 'map') { |
|
data[name] = {}; |
|
util.each(r.headers, function (k, v) { |
|
var result = k.match(new RegExp('^' + member.name + '(.+)', 'i')); |
|
if (result !== null) { |
|
data[name][result[1]] = v; |
|
} |
|
}); |
|
} else if (member.location === 'header') { |
|
if (headers[header] !== undefined) { |
|
data[name] = headers[header]; |
|
} |
|
} else if (member.location === 'status') { |
|
data[name] = parseInt(r.statusCode, 10); |
|
} |
|
}); |
|
|
|
resp.data = data; |
|
} |
|
|
|
module.exports = { |
|
buildRequest: buildRequest, |
|
extractError: extractError, |
|
extractData: extractData |
|
}; |
|
|
|
},{"../util":60}],44:[function(require,module,exports){ |
|
var util = require('../util'); |
|
var Rest = require('./rest'); |
|
var Json = require('./json'); |
|
var JsonBuilder = require('../json/builder'); |
|
|
|
function populateBody(req) { |
|
var builder = new JsonBuilder(); |
|
var input = req.service.api.operations[req.operation].input; |
|
|
|
if (input.payload) { |
|
var params = {}; |
|
var payloadShape = input.members[input.payload]; |
|
params = req.params[input.payload]; |
|
if (params === undefined) return; |
|
|
|
if (payloadShape.type === 'structure') { |
|
req.httpRequest.body = builder.build(params, payloadShape); |
|
} else { // non-JSON payload |
|
req.httpRequest.body = params; |
|
} |
|
} else { |
|
req.httpRequest.body = builder.build(req.params, input); |
|
} |
|
} |
|
|
|
function buildRequest(req) { |
|
Rest.buildRequest(req); |
|
populateBody(req); |
|
} |
|
|
|
function extractError(resp) { |
|
Json.extractError(resp); |
|
} |
|
|
|
function extractData(resp) { |
|
Rest.extractData(resp); |
|
|
|
var req = resp.request; |
|
var rules = req.service.api.operations[req.operation].output || {}; |
|
if (rules.payload) { |
|
var payloadMember = rules.members[rules.payload]; |
|
if (payloadMember.isStreaming) { |
|
resp.data[rules.payload] = resp.httpResponse.body; |
|
} else if (payloadMember.type === 'structure') { |
|
Json.extractData(resp); |
|
} else { |
|
resp.data[rules.payload] = resp.httpResponse.body.toString(); |
|
} |
|
} else { |
|
var data = resp.data; |
|
Json.extractData(resp); |
|
resp.data = util.merge(data, resp.data); |
|
} |
|
} |
|
|
|
module.exports = { |
|
buildRequest: buildRequest, |
|
extractError: extractError, |
|
extractData: extractData |
|
}; |
|
|
|
},{"../json/builder":32,"../util":60,"./json":41,"./rest":43}],45:[function(require,module,exports){ |
|
var AWS = require('../core'); |
|
var util = require('../util'); |
|
var Rest = require('./rest'); |
|
|
|
function populateBody(req) { |
|
var input = req.service.api.operations[req.operation].input; |
|
var builder = new AWS.XML.Builder(); |
|
var params = req.params; |
|
|
|
var payload = input.payload; |
|
if (payload) { |
|
var payloadMember = input.members[payload]; |
|
params = params[payload]; |
|
if (params === undefined) return; |
|
|
|
if (payloadMember.type === 'structure') { |
|
req.httpRequest.body = builder.toXML(params, payloadMember, payload); |
|
} else { // non-xml payload |
|
req.httpRequest.body = params; |
|
} |
|
} else { |
|
req.httpRequest.body = builder.toXML(params, input, input.shape || |
|
util.string.upperFirst(req.operation) + 'Request'); |
|
} |
|
} |
|
|
|
function buildRequest(req) { |
|
Rest.buildRequest(req); |
|
populateBody(req); |
|
} |
|
|
|
function extractError(resp) { |
|
Rest.extractError(resp); |
|
|
|
var data = new AWS.XML.Parser().parse(resp.httpResponse.body.toString()); |
|
if (data.Errors) data = data.Errors; |
|
if (data.Error) data = data.Error; |
|
if (data.Code) { |
|
resp.error = util.error(new Error(), { |
|
code: data.Code, |
|
message: data.Message |
|
}); |
|
} else { |
|
resp.error = util.error(new Error(), { |
|
code: resp.httpResponse.statusCode, |
|
message: null |
|
}); |
|
} |
|
} |
|
|
|
function extractData(resp) { |
|
Rest.extractData(resp); |
|
|
|
var parser; |
|
var req = resp.request; |
|
var body = resp.httpResponse.body; |
|
var operation = req.service.api.operations[req.operation]; |
|
var output = operation.output; |
|
|
|
var payload = output.payload; |
|
if (payload) { |
|
var payloadMember = output.members[payload]; |
|
if (payloadMember.isStreaming) { |
|
resp.data[payload] = body; |
|
} else if (payloadMember.type === 'structure') { |
|
parser = new AWS.XML.Parser(); |
|
resp.data = parser.parse(body.toString(), payloadMember); |
|
} else { |
|
resp.data[payload] = body.toString(); |
|
} |
|
} else if (body.length > 0) { |
|
parser = new AWS.XML.Parser(); |
|
var data = parser.parse(body.toString(), output); |
|
util.update(resp.data, data); |
|
} |
|
} |
|
|
|
module.exports = { |
|
buildRequest: buildRequest, |
|
extractError: extractError, |
|
extractData: extractData |
|
}; |
|
|
|
},{"../core":23,"../util":60,"./rest":43}],46:[function(require,module,exports){ |
|
var util = require('../util'); |
|
|
|
function QueryParamSerializer() { } |
|
|
|
QueryParamSerializer.prototype.serialize = function(params, shape, fn) { |
|
serializeStructure('', params, shape, fn); |
|
}; |
|
|
|
function serializeStructure(prefix, struct, rules, fn) { |
|
util.each(rules.members, function(name, member) { |
|
var value = struct[name]; |
|
if (value === null || value === undefined) return; |
|
|
|
var memberName = prefix ? prefix + '.' + member.name : member.name; |
|
serializeMember(memberName, value, member, fn); |
|
}); |
|
} |
|
|
|
function serializeMap(name, map, rules, fn) { |
|
var i = 1; |
|
util.each(map, function (key, value) { |
|
var prefix = rules.flattened || rules.queryFlattened ? '.' : '.entry.'; |
|
var position = prefix + (i++) + '.'; |
|
var keyName = position + (rules.key.name || 'key'); |
|
var valueName = position + (rules.value.name || 'value'); |
|
serializeMember(name + keyName, key, rules.key, fn); |
|
serializeMember(name + valueName, value, rules.value, fn); |
|
}); |
|
} |
|
|
|
function serializeList(name, list, rules, fn) { |
|
var memberRules = rules.member || {}; |
|
|
|
if (list.length === 0) { |
|
fn.call(this, name, null); |
|
return; |
|
} |
|
|
|
util.arrayEach(list, function (v, n) { |
|
var suffix = '.' + (n + 1); |
|
if (rules.flattened || rules.queryFlattened) { |
|
if (memberRules.name) { |
|
var parts = name.split('.'); |
|
parts.pop(); |
|
parts.push(memberRules.name); |
|
name = parts.join('.'); |
|
} |
|
} else { |
|
suffix = '.member' + suffix; |
|
} |
|
serializeMember(name + suffix, v, memberRules, fn); |
|
}); |
|
} |
|
|
|
function serializeMember(name, value, rules, fn) { |
|
if (value === null || value === undefined) return; |
|
if (rules.type === 'structure') { |
|
serializeStructure(name, value, rules, fn); |
|
} else if (rules.type === 'list') { |
|
serializeList(name, value, rules, fn); |
|
} else if (rules.type === 'map') { |
|
serializeMap(name, value, rules, fn); |
|
} else { |
|
fn(name, rules.toWireFormat(value).toString()); |
|
} |
|
} |
|
|
|
module.exports = QueryParamSeria |