New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sanity/client

Package Overview
Dependencies
Maintainers
6
Versions
1027
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/client - npm Package Compare versions

Comparing version 0.101.20-next to 0.101.21-newgradient

lib/util/omit.js

14

lib/assets/assetsClient.js

@@ -10,2 +10,10 @@ 'use strict';

function toPromise(observable) {
return observable.filter(function (event) {
return event.type === 'response';
}).map(function (event) {
return event.body;
}).toPromise();
}
assign(AssetsClient.prototype, {

@@ -20,3 +28,3 @@ upload: function upload(assetType, body) {

return this.client.requestObservable({
var observable = this.client._requestObservable({
method: 'POST',

@@ -29,2 +37,4 @@ timeout: options.timeout || 0,

});
return this.client.isPromiseAPI() ? toPromise(observable) : observable;
},

@@ -37,3 +47,3 @@ delete: function _delete(type, id) {

if (type._type) {
assetType = type._type.replace(/^(sanity\.|Asset$)/g, '');
assetType = type._type.replace(/(^sanity\.|Asset$)/g, '');
docId = type._id;

@@ -40,0 +50,0 @@ }

11

lib/config.js

@@ -14,3 +14,4 @@ 'use strict';

var newConfig = assign({}, defaultConfig, prevConfig, config);
var projectBased = newConfig.useProjectHostname;
var gradientMode = newConfig.gradientMode;
var projectBased = !gradientMode && newConfig.useProjectHostname;

@@ -22,2 +23,6 @@ if (typeof Promise === 'undefined') {

if (gradientMode && !newConfig.namespace) {
throw new Error('Configuration must contain `namespace` when running in gradient mode');
}
if (projectBased && !newConfig.projectId) {

@@ -31,4 +36,4 @@ throw new Error('Configuration must contain `projectId`');

if (newConfig.dataset) {
validate.dataset(newConfig.dataset);
if (!gradientMode && newConfig.dataset) {
validate.dataset(newConfig.dataset, newConfig.gradientMode);
}

@@ -35,0 +40,0 @@

@@ -28,2 +28,13 @@ 'use strict';

var isResponse = function isResponse(event) {
return event.type === 'response';
};
var getBody = function getBody(event) {
return event.body;
};
var toPromise = function toPromise(observable) {
return observable.toPromise();
};
var getQuerySizeLimit = 1948;

@@ -34,18 +45,22 @@

getDataUrl: function getDataUrl(endpoint, uri) {
var projectId = this.clientConfig.projectId;
return (this.clientConfig.gradientMode ? '/' + endpoint + '/' + projectId + '/' + uri : '/data/' + endpoint + '/' + uri).replace(/\/($|\?)/, '$1');
getDataUrl: function getDataUrl(operation, path) {
var config = this.clientConfig;
var catalog = config.gradientMode ? config.namespace : validators.hasDataset(config);
var baseUri = '/' + operation + '/' + catalog;
var uri = path ? baseUri + '/' + path : baseUri;
return (this.clientConfig.gradientMode ? uri : '/data' + uri).replace(/\/($|\?)/, '$1');
},
fetch: function fetch(query, params) {
return this.dataRequest('query', { query: query, params: params }).then(function (res) {
var observable = this._dataRequest('query', { query: query, params: params }).map(function (res) {
return res.result || [];
});
return this.isPromiseAPI() ? toPromise(observable) : observable;
},
getDocument: function getDocument(id) {
return this.request({
uri: this.getDataUrl('doc', id),
json: true
}).then(function (res) {
return res.documents && res.documents[0];
var options = { uri: this.getDataUrl('doc', id), json: true };
var observable = this._requestObservable(options).filter(isResponse).map(function (event) {
return event.body.documents && event.body.documents[0];
});
return this.isPromiseAPI() ? toPromise(observable) : observable;
},

@@ -56,5 +71,7 @@ create: function create(doc, options) {

createIfNotExists: function createIfNotExists(doc, options) {
validators.requireDocumentId('createIfNotExists', doc);
return this._create(doc, 'createIfNotExists', options);
},
createOrReplace: function createOrReplace(doc, options) {
validators.requireDocumentId('createOrReplace', doc);
return this._create(doc, 'createOrReplace', options);

@@ -66,5 +83,3 @@ },

delete: function _delete(selection, options) {
return this.dataRequest('mutate', {
mutations: [{ delete: getSelection(selection) }]
}, options);
return this.dataRequest('mutate', { mutations: [{ delete: getSelection(selection) }] }, options);
},

@@ -81,4 +96,9 @@ mutate: function mutate(mutations, options) {

dataRequest: function dataRequest(endpoint, body) {
var _this = this;
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var request = this._dataRequest(endpoint, body, options);
return this.isPromiseAPI() ? toPromise(request) : request;
},
_dataRequest: function _dataRequest(endpoint, body) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -95,11 +115,13 @@

return validators.promise.hasDataset(this.clientConfig).then(function (dataset) {
return _this.request({
method: useGet ? 'GET' : 'POST',
uri: _this.getDataUrl(endpoint, '' + dataset + stringQuery),
json: true,
body: useGet ? undefined : body,
query: isMutation && getMutationQuery(options)
});
}).then(function (res) {
var uri = this.getDataUrl(endpoint, stringQuery);
var reqOptions = {
method: useGet ? 'GET' : 'POST',
uri: uri,
json: true,
body: useGet ? undefined : body,
query: isMutation && getMutationQuery(options)
};
return this._requestObservable(reqOptions).filter(isResponse).map(getBody).map(function (res) {
if (!isMutation) {

@@ -131,4 +153,3 @@ return res;

var dataset = validators.hasDataset(this.clientConfig);
var mutation = _defineProperty({}, op, assign({}, doc, { _id: doc._id || dataset + '.' }));
var mutation = _defineProperty({}, op, doc);
var opts = assign({ returnFirst: true, returnDocuments: true }, options);

@@ -135,0 +156,0 @@ return this.dataRequest('mutate', { mutations: [mutation] }, opts);

@@ -6,3 +6,2 @@ 'use strict';

var encodeQueryString = require('./encodeQueryString');
var validators = require('../validators');
var pick = require('../util/pick');

@@ -34,4 +33,3 @@ var defaults = require('../util/defaults');

var qs = encodeQueryString({ query: query, params: params, options: listenOpts });
var dataset = validators.hasDataset(this.clientConfig);
var uri = '' + this.clientConfig.url + this.getDataUrl('listen', '' + dataset + qs);
var uri = '' + this.clientConfig.url + this.getDataUrl('listen', qs);
var token = this.clientConfig.token;

@@ -38,0 +36,0 @@ var listenFor = options.events ? options.events : ['mutation'];

@@ -24,9 +24,16 @@ 'use strict';

create: function create(doc) {
return this._create(doc, 'create');
validators.validateObject('create', doc);
return this._add({ create: doc });
},
createIfNotExists: function createIfNotExists(doc) {
return this._create(doc, 'createIfNotExists');
var op = 'createIfNotExists';
validators.validateObject(op, doc);
validators.requireDocumentId(op, doc);
return this._add(_defineProperty({}, op, doc));
},
createOrReplace: function createOrReplace(doc) {
return this._create(doc, 'createOrReplace');
var op = 'createOrReplace';
validators.validateObject(op, doc);
validators.requireDocumentId(op, doc);
return this._add(_defineProperty({}, op, doc));
},

@@ -75,12 +82,2 @@ delete: function _delete(documentId) {

},
_create: function _create(doc, op) {
if (!doc._id && !this.client) {
throw new Error('Document needs an _id property when transaction is create outside a client scope. ' + 'Pass `{_id: "<datasetName>:"}` to have Sanity generate an ID for you.');
}
validators.validateObject(op, doc);
var dataset = validators.hasDataset(this.client.clientConfig);
var mutation = _defineProperty({}, op, assign({}, doc, { _id: doc._id || dataset + '.' }));
return this._add(mutation);
},
_add: function _add(mut) {

@@ -87,0 +84,0 @@ this.operations.push(mut);

@@ -11,3 +11,3 @@ 'use strict';

var jsonResponse = require('get-it/lib/middleware/jsonResponse');
var sanityObservable = require('@sanity/observable/minimal');
var SanityObservable = require('@sanity/observable/minimal');
var progress = require('get-it/lib/middleware/progress');

@@ -30,3 +30,3 @@

function retry5xx(err) {
function retry5xx(err, attempt, options) {
// Retry low-level network errors

@@ -37,3 +37,7 @@ if (retry.shouldRetry(err)) {

return err.response && err.response.statusCode >= 500;
if (options.method === 'HEAD' || options.method === 'GET') {
return err.response && err.response.statusCode >= 500;
}
return false;
}

@@ -75,3 +79,3 @@

var middleware = [jsonRequest(), jsonResponse(), progress(), httpError, observable({ implementation: sanityObservable }), retry({ maxRetries: 5, shouldRetry: retry5xx })];
var middleware = [jsonRequest(), jsonResponse(), progress(), httpError, observable({ implementation: SanityObservable }), retry({ maxRetries: 5, shouldRetry: retry5xx })];

@@ -89,13 +93,3 @@ // Don't include debug middleware in browsers

var obs = requester(assign({ maxRedirects: 0 }, options));
obs.toPromise = function () {
return new Promise(function (resolve, reject) {
obs.filter(function (ev) {
return ev.type === 'response';
}).subscribe(function (res) {
return resolve(res.body);
}, reject);
});
};
return obs;
return requester(assign({ maxRedirects: 0 }, options));
}

@@ -102,0 +96,0 @@

@@ -14,2 +14,3 @@ 'use strict';

var getRequestOptions = require('./http/requestOptions');
var omit = require('./util/omit');

@@ -20,2 +21,6 @@ var _require = require('./config'),

var toPromise = function toPromise(observable) {
return observable.toPromise();
};
function SanityClient() {

@@ -31,2 +36,6 @@ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultConfig;

this.auth = new AuthClient(this);
if (config.isPromiseAPI) {
this.observable = new SanityClient(omit(config, ['isPromiseAPI']));
}
}

@@ -44,2 +53,6 @@

if (this.observable) {
this.observable.config(omit(newConfig, ['isPromiseAPI']));
}
this.clientConfig = initConfig(newConfig, this.clientConfig || {});

@@ -51,7 +64,16 @@ return this;

},
request: function request(options) {
return this.requestObservable(options).toPromise();
isPromiseAPI: function isPromiseAPI() {
return this.clientConfig.isPromiseAPI;
},
requestObservable: function requestObservable(options) {
_requestObservable: function _requestObservable(options) {
return httpRequest(mergeOptions(getRequestOptions(this.clientConfig), options, { url: this.getUrl(options.url || options.uri) }), this.clientConfig.requester);
},
request: function request(options) {
var observable = this._requestObservable(options).filter(function (event) {
return event.type === 'response';
}).map(function (event) {
return event.body;
});
return this.isPromiseAPI() ? toPromise(observable) : observable;
}

@@ -76,3 +98,3 @@ });

function createClient(config) {
return new SanityClient(config);
return new SanityClient(assign({}, config, { isPromiseAPI: true }));
}

@@ -79,0 +101,0 @@

@@ -12,5 +12,5 @@ 'use strict';

var selectionOpts = ['* Dataset-prefixed document ID (<dataset.docId>)', '* Array of dataset-prefixed document IDs', '* Object containing `query`'].join('\n');
var selectionOpts = ['* Document ID (<docId>)', '* Array of document IDs', '* Object containing `query`'].join('\n');
throw new Error('Unknown selection - must be one of:\n\n' + selectionOpts);
};

@@ -32,5 +32,13 @@ 'use strict';

exports.requireDocumentId = function (op, doc) {
if (!doc._id) {
throw new Error(op + '() requires that the document contains an ID ("_id" property)');
}
exports.validateDocumentId(op, doc._id);
};
exports.validateDocumentId = function (op, id) {
if (typeof id !== 'string' || !/^[-_a-z0-9]{1,128}\.[-_a-z0-9.]+$/i.test(id)) {
throw new Error(op + '() takes a document ID in format dataset.docId');
if (typeof id !== 'string' || !/^[a-z0-9_.-]+$/i.test(id)) {
throw new Error(op + '(): "' + id + '" is not a valid document ID');
}

@@ -63,10 +71,2 @@ };

return config.dataset || '';
};
exports.promise = {
hasDataset: function hasDataset(config) {
return new Promise(function (resolve) {
return resolve(exports.hasDataset(config));
});
}
};
{
"name": "@sanity/client",
"version": "0.101.20-next",
"version": "0.101.21-newgradient",
"description": "Client for retrieving data from Sanity",

@@ -11,3 +11,3 @@ "main": "lib/sanityClient.js",

"size": "node -r babel-register src/scripts/print-bundle-size",
"clean": "rimraf coverage .nyc_output umd/*.js",
"clean": "rimraf lib coverage .nyc_output umd/*.js",
"coverage": "DEBUG=sanity NODE_ENV=test nyc --reporter=html --reporter=lcov --reporter=text npm test",

@@ -25,17 +25,19 @@ "minify": "uglifyjs -c -m -- umd/sanityClient.js > umd/sanityClient.min.js",

"deep-assign": "^2.0.0",
"get-it": "^1.0.2",
"get-it": "^1.0.3",
"in-publish": "^2.0.0",
"object-assign": "^4.1.0"
"object-assign": "^4.1.1"
},
"devDependencies": {
"boxen": "^0.8.1",
"boxen": "^1.0.0",
"browserify": "^13.1.1",
"chalk": "^1.1.3",
"envify": "^4.0.0",
"eslint": "^3.16.1",
"eslint-config-sanity": "^2.0.2",
"gzip-size": "^3.0.0",
"hard-rejection": "^0.1.0",
"hard-rejection": "^1.0.0",
"nock": "git://github.com/rexxars/nock.git#fix-socket-event-scope",
"nyc": "^10.0.0",
"nyc": "^10.1.2",
"pretty-bytes": "^4.0.2",
"rimraf": "^2.5.4",
"rimraf": "^2.6.0",
"tape": "^4.6.2",

@@ -42,0 +44,0 @@ "uglify-js": "^2.7.3",

@@ -51,2 +51,10 @@ /* eslint-disable strict */

test('calling config() reconfigures observable API too', t => {
const client = sanityClient({projectId: 'abc123'})
client.config({projectId: 'def456'})
t.equal(client.observable.config().projectId, 'def456', 'Observable API gets reconfigured')
t.end()
})
test('can clone client', t => {

@@ -99,5 +107,5 @@ const client = sanityClient({projectId: 'abc123'})

test('validation', t => {
t.doesNotThrow(() => validators.validateDocumentId('op', 'foo.bar'), /document ID in format/, 'does not throw on valid ID')
t.doesNotThrow(() => validators.validateDocumentId('op', 'foo.bar.baz'), /document ID in format/, 'does not throw on valid ID')
t.throws(() => validators.validateDocumentId('op', 'blahblah'), /document ID in format/, 'throws on invalid ID')
t.doesNotThrow(() => validators.validateDocumentId('op', 'barfoo'), /document ID in format/, 'does not throw on valid ID')
t.doesNotThrow(() => validators.validateDocumentId('op', 'bar.foo.baz'), /document ID in format/, 'does not throw on valid ID')
t.throws(() => validators.validateDocumentId('op', 'blah#blah'), /not a valid document ID/, 'throws on invalid ID')
t.end()

@@ -121,12 +129,21 @@ })

test('can request list of projects', t => {
nock(`https://${apiHost}`)
.get('/v1/projects')
.reply(200, [{projectId: 'foo'}, {projectId: 'bar'}])
test('can request project by id', t => {
const doc = {
_id: 'projects.n1f7y',
projectId: 'n1f7y',
displayName: 'Movies Unlimited',
studioHostname: 'movies',
members: [{
id: 'someuserid',
role: 'administrator'
}]
}
nock(`https://${apiHost}`).get('/v1/projects/n1f7y').reply(200, doc)
const client = sanityClient({useProjectHostname: false, apiHost: `https://${apiHost}`})
client.projects.list().then(projects => {
t.equal(projects.length, 2, 'should have two projects')
t.equal(projects[0].projectId, 'foo', 'should have project id')
}).catch(t.ifError).then(t.end)
client.projects.getById('n1f7y')
.then(project => t.deepEqual(project, doc))
.catch(t.ifError)
.then(t.end)
})

@@ -175,3 +192,3 @@

q: query,
result: [{_id: 'beerfiesta.beer:njgNkngskjg', rating: 5}]
result: [{_id: 'njgNkngskjg', rating: 5}]
})

@@ -237,8 +254,8 @@

test('can query for single document', t => {
nock(projectHost()).get('/v1/data/doc/foo.123').reply(200, {
nock(projectHost()).get('/v1/data/doc/foo/abc123').reply(200, {
ms: 123,
documents: [{_id: 'foo.123', mood: 'lax'}]
documents: [{_id: 'abc123', mood: 'lax'}]
})
getClient().getDocument('foo.123').then(res => {
getClient().getDocument('abc123').then(res => {
t.equal(res.mood, 'lax', 'data should match')

@@ -249,5 +266,5 @@ }).catch(t.ifError).then(t.end)

test('gives http statuscode as error if no body is present on errors', t => {
nock(projectHost()).get('/v1/data/doc/foo.123').reply(400)
nock(projectHost()).get('/v1/data/doc/foo/abc123').reply(400)
getClient().getDocument('foo.123')
getClient().getDocument('abc123')
.then(res => {

@@ -265,5 +282,5 @@ t.fail('Resolve handler should not be called on failure')

test('populates response body on errors', t => {
nock(projectHost()).get('/v1/data/doc/foo.123').times(5).reply(400, 'Some Weird Error')
nock(projectHost()).get('/v1/data/doc/foo/abc123').times(5).reply(400, 'Some Weird Error')
getClient().getDocument('foo.123')
getClient().getDocument('abc123')
.then(res => {

@@ -281,17 +298,9 @@ t.fail('Resolve handler should not be called on failure')

test('rejects if trying to perform data request without dataset', t => {
sanityClient({projectId: 'foo'}).fetch('blah')
.then(res => {
t.fail('Resolve handler should not be called on failure')
t.end()
})
.catch(err => {
t.ok(err instanceof Error, 'should be error')
t.ok(/dataset.*?must be provided/.test(err.message))
t.end()
})
test('throws if trying to perform data request without dataset', t => {
t.throws(() => sanityClient({projectId: 'foo'}).fetch('blah'), Error, /dataset.*?must be provided/)
t.end()
})
test('can create documents', t => {
const doc = {_id: 'foo.123', name: 'Raptor'}
const doc = {_id: 'abc123', name: 'Raptor'}

@@ -302,3 +311,3 @@ nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true&visibility=sync', {mutations: [{create: doc}]})

results: [{
document: {_id: 'foo.123', _createdAt: '2016-10-24T08:09:32.997Z', name: 'Raptor'},
document: {_id: 'abc123', _createdAt: '2016-10-24T08:09:32.997Z', name: 'Raptor'},
operation: 'create'

@@ -319,3 +328,3 @@ }]

const doc = {name: 'Raptor'}
const expectedBody = {mutations: [{create: Object.assign({}, doc, {_id: 'foo.'})}]}
const expectedBody = {mutations: [{create: Object.assign({}, doc)}]}
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true&visibility=sync', expectedBody)

@@ -325,4 +334,4 @@ .reply(200, {

results: [{
id: 'foo.456',
document: {_id: 'foo.456', name: 'Raptor'}
id: 'abc456',
document: {_id: 'abc456', name: 'Raptor'}
}]

@@ -333,3 +342,3 @@ })

.then(res => {
t.equal(res._id, 'foo.456', 'document id returned')
t.equal(res._id, 'abc456', 'document id returned')
})

@@ -341,5 +350,5 @@ .catch(t.ifError)

test('can tell create() not to return documents', t => {
const doc = {_id: 'foo.123', name: 'Raptor'}
const doc = {_id: 'abc123', name: 'Raptor'}
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&visibility=sync', {mutations: [{create: doc}]})
.reply(200, {transactionId: 'abc123', results: [{id: 'foo.123', operation: 'create'}]})
.reply(200, {transactionId: 'abc123', results: [{id: 'abc123', operation: 'create'}]})

@@ -349,3 +358,3 @@ getClient().create(doc, {returnDocuments: false})

t.equal(res.transactionId, 'abc123', 'returns transaction ID')
t.equal(res.documentId, 'foo.123', 'returns document id')
t.equal(res.documentId, 'abc123', 'returns document id')
})

@@ -357,9 +366,9 @@ .catch(t.ifError)

test('can tell create() to use non-default visibility mode', t => {
const doc = {_id: 'foo.123', name: 'Raptor'}
const doc = {_id: 'abc123', name: 'Raptor'}
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true&visibility=async', {mutations: [{create: doc}]})
.reply(200, {transactionId: 'abc123', results: [{id: 'foo.123', document: doc, operation: 'create'}]})
.reply(200, {transactionId: 'abc123', results: [{id: 'abc123', document: doc, operation: 'create'}]})
getClient().create(doc, {visibility: 'async'})
.then(res => {
t.equal(res._id, 'foo.123', 'document id returned')
t.equal(res._id, 'abc123', 'document id returned')
})

@@ -371,6 +380,6 @@ .catch(t.ifError)

test('createIfNotExists() sends correct mutation', t => {
const doc = {_id: 'foo.123', name: 'Raptor'}
const doc = {_id: 'abc123', name: 'Raptor'}
const expectedBody = {mutations: [{createIfNotExists: doc}]}
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true&visibility=sync', expectedBody)
.reply(200, {transactionId: '123abc', results: [{id: 'foo.123', document: doc, operation: 'create'}]})
.reply(200, {transactionId: '123abc', results: [{id: 'abc123', document: doc, operation: 'create'}]})

@@ -381,6 +390,6 @@ getClient().createIfNotExists(doc).catch(t.ifError).then(() => t.end())

test('can tell createIfNotExists() not to return documents', t => {
const doc = {_id: 'foo.123', name: 'Raptor'}
const doc = {_id: 'abc123', name: 'Raptor'}
const expectedBody = {mutations: [{createIfNotExists: doc}]}
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&visibility=sync', expectedBody)
.reply(200, {transactionId: 'abc123', results: [{id: 'foo.123', operation: 'create'}]})
.reply(200, {transactionId: 'abc123', results: [{id: 'abc123', operation: 'create'}]})

@@ -390,3 +399,3 @@ getClient().createIfNotExists(doc, {returnDocuments: false})

t.equal(res.transactionId, 'abc123', 'returns transaction ID')
t.equal(res.documentId, 'foo.123', 'returns document id')
t.equal(res.documentId, 'abc123', 'returns document id')
})

@@ -398,6 +407,6 @@ .catch(t.ifError)

test('createOrReplace() sends correct mutation', t => {
const doc = {_id: 'foo.123', name: 'Raptor'}
const doc = {_id: 'abc123', name: 'Raptor'}
const expectedBody = {mutations: [{createOrReplace: doc}]}
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true&visibility=sync', expectedBody)
.reply(200, {transactionId: '123abc', results: [{id: 'foo.123', operation: 'create'}]})
.reply(200, {transactionId: '123abc', results: [{id: 'abc123', operation: 'create'}]})

@@ -408,6 +417,6 @@ getClient().createOrReplace(doc).catch(t.ifError).then(t.end)

test('can tell createOrReplace() not to return documents', t => {
const doc = {_id: 'foo.123', name: 'Raptor'}
const doc = {_id: 'abc123', name: 'Raptor'}
const expectedBody = {mutations: [{createOrReplace: doc}]}
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&visibility=sync', expectedBody)
.reply(200, {transactionId: 'abc123', results: [{id: 'foo.123', operation: 'create'}]})
.reply(200, {transactionId: 'abc123', results: [{id: 'abc123', operation: 'create'}]})

@@ -417,3 +426,3 @@ getClient().createOrReplace(doc, {returnDocuments: false})

t.equal(res.transactionId, 'abc123', 'returns transaction ID')
t.equal(res.documentId, 'foo.123', 'returns document id')
t.equal(res.documentId, 'abc123', 'returns document id')
})

@@ -425,8 +434,8 @@ .catch(t.ifError)

test('delete() sends correct mutation', t => {
const expectedBody = {mutations: [{delete: {id: 'foo.123'}}]}
const expectedBody = {mutations: [{delete: {id: 'abc123'}}]}
nock(projectHost())
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true&visibility=sync', expectedBody)
.reply(200, {transactionId: 'abc123', results: [{id: 'foo.123', operation: 'delete'}]})
.reply(200, {transactionId: 'abc123', results: [{id: 'abc123', operation: 'delete'}]})
getClient().delete('foo.123').catch(t.ifError).then(() => t.end())
getClient().delete('abc123').catch(t.ifError).then(() => t.end())
})

@@ -444,8 +453,8 @@

test('delete() can be told not to return documents', t => {
const expectedBody = {mutations: [{delete: {id: 'foo.123'}}]}
const expectedBody = {mutations: [{delete: {id: 'abc123'}}]}
nock(projectHost())
.post('/v1/data/mutate/foo?returnIds=true&visibility=sync', expectedBody)
.reply(200, {transactionId: 'abc123', results: [{id: 'foo.123', operation: 'delete'}]})
.reply(200, {transactionId: 'abc123', results: [{id: 'abc123', operation: 'delete'}]})
getClient().delete('foo.123', {returnDocuments: false}).catch(t.ifError).then(() => t.end())
getClient().delete('abc123', {returnDocuments: false}).catch(t.ifError).then(() => t.end())
})

@@ -455,7 +464,7 @@

const docs = [{
_id: 'movie/raiders-of-the-lost-ark',
_id: 'movies.raiders-of-the-lost-ark',
title: 'Raiders of the Lost Ark',
year: 1981
}, {
_id: 'movie/the-phantom-menace',
_id: 'movies.the-phantom-menace',
title: 'Star Wars: Episode I - The Phantom Menace',

@@ -467,3 +476,3 @@ year: 1999

{create: docs[0]},
{delete: {id: 'movie/the-phantom-menace'}}
{delete: {id: 'movies.the-phantom-menace'}}
]

@@ -474,4 +483,4 @@

.reply(200, {transactionId: 'foo', results: [
{id: 'movie/raiders-of-the-lost-ark', operation: 'create', document: docs[0]},
{id: 'movie/the-phantom-menace', operation: 'delete', document: docs[1]}
{id: 'movies.raiders-of-the-lost-ark', operation: 'create', document: docs[0]},
{id: 'movies.the-phantom-menace', operation: 'delete', document: docs[1]}
]})

@@ -487,3 +496,3 @@

for (let i = 1866; i <= 2016; i++) {
clause.push(`.title == $beerName${i}`)
clause.push(`title == $beerName${i}`)
params[`beerName${i}`] = `some beer ${i}`

@@ -493,3 +502,3 @@ }

// Again, just... don't do this.
const query = `beerfiesta.beer[${clause.join(' || ')}]`
const query = `*[is "beer" && (${clause.join(' || ')})]`

@@ -502,3 +511,3 @@ nock(projectHost())

q: query,
result: [{_id: 'beerfiesta.beer:njgNkngskjg', rating: 5}]
result: [{_id: 'njgNkngskjg', rating: 5}]
})

@@ -516,3 +525,3 @@

test('can build and serialize a patch of operations', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.inc({count: 1})

@@ -522,3 +531,3 @@ .set({brownEyes: true})

t.deepEqual(patch, {id: 'foo.123', inc: {count: 1}, set: {brownEyes: true}})
t.deepEqual(patch, {id: 'abc123', inc: {count: 1}, set: {brownEyes: true}})
t.end()

@@ -528,4 +537,4 @@ })

test('patch() can take an array of IDs', t => {
const patch = getClient().patch(['foo.123', 'foo.456']).inc({count: 1}).serialize()
t.deepEqual(patch, {id: ['foo.123', 'foo.456'], inc: {count: 1}})
const patch = getClient().patch(['abc123', 'foo.456']).inc({count: 1}).serialize()
t.deepEqual(patch, {id: ['abc123', 'foo.456'], inc: {count: 1}})
t.end()

@@ -541,3 +550,3 @@ })

test('merge() patch can be applied multiple times', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.merge({count: 1, foo: 'bar'})

@@ -547,3 +556,3 @@ .merge({count: 2, bar: 'foo'})

t.deepEqual(patch, {id: 'foo.123', merge: {count: 2, foo: 'bar', bar: 'foo'}})
t.deepEqual(patch, {id: 'abc123', merge: {count: 2, foo: 'bar', bar: 'foo'}})
t.end()

@@ -553,3 +562,3 @@ })

test('setIfMissing() patch can be applied multiple times', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.setIfMissing({count: 1, foo: 'bar'})

@@ -559,3 +568,3 @@ .setIfMissing({count: 2, bar: 'foo'})

t.deepEqual(patch, {id: 'foo.123', setIfMissing: {count: 2, foo: 'bar', bar: 'foo'}})
t.deepEqual(patch, {id: 'abc123', setIfMissing: {count: 2, foo: 'bar', bar: 'foo'}})
t.end()

@@ -565,3 +574,3 @@ })

test('only last replace() patch call gets applied', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.replace({count: 1, foo: 'bar'})

@@ -571,3 +580,3 @@ .replace({count: 2, bar: 'foo'})

t.deepEqual(patch, {id: 'foo.123', set: {$: {count: 2, bar: 'foo'}}})
t.deepEqual(patch, {id: 'abc123', set: {$: {count: 2, bar: 'foo'}}})
t.end()

@@ -577,3 +586,3 @@ })

test('can apply inc() and dec()', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.inc({count: 1}) // One step forward

@@ -583,3 +592,3 @@ .dec({count: 2}) // Two steps back

t.deepEqual(patch, {id: 'foo.123', inc: {count: 1}, dec: {count: 2}})
t.deepEqual(patch, {id: 'abc123', inc: {count: 1}, dec: {count: 2}})
t.end()

@@ -589,3 +598,3 @@ })

test('can apply unset()', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.inc({count: 1})

@@ -595,3 +604,3 @@ .unset(['bitter', 'enchilada'])

t.deepEqual(patch, {id: 'foo.123', inc: {count: 1}, unset: ['bitter', 'enchilada']})
t.deepEqual(patch, {id: 'abc123', inc: {count: 1}, unset: ['bitter', 'enchilada']})
t.end()

@@ -602,3 +611,3 @@ })

t.throws(() =>
getClient().patch('foo.123').unset('bitter').serialize(),
getClient().patch('abc123').unset('bitter').serialize(),
/non-array given/

@@ -610,3 +619,3 @@ )

test('can apply insert()', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.inc({count: 1})

@@ -617,3 +626,3 @@ .insert('after', 'tags[-1]', ['hotsauce'])

t.deepEqual(patch, {
id: 'foo.123',
id: 'abc123',
inc: {count: 1},

@@ -627,3 +636,3 @@ insert: {after: 'tags[-1]', items: ['hotsauce']}

t.throws(() =>
getClient().patch('foo.123').insert('bitter', 'sel', ['raf']),
getClient().patch('abc123').insert('bitter', 'sel', ['raf']),
/one of: "before", "after", "replace"/

@@ -633,3 +642,3 @@ )

t.throws(() =>
getClient().patch('foo.123').insert('before', 123, ['raf']),
getClient().patch('abc123').insert('before', 123, ['raf']),
/must be a string/

@@ -639,3 +648,3 @@ )

t.throws(() =>
getClient().patch('foo.123').insert('before', 'prop', 'blah'),
getClient().patch('abc123').insert('before', 'prop', 'blah'),
/must be an array/

@@ -647,3 +656,3 @@ )

test('can apply append()', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.inc({count: 1})

@@ -654,3 +663,3 @@ .append('tags', ['sriracha'])

t.deepEqual(patch, {
id: 'foo.123',
id: 'abc123',
inc: {count: 1},

@@ -663,3 +672,3 @@ insert: {after: 'tags[-1]', items: ['sriracha']}

test('can apply prepend()', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.inc({count: 1})

@@ -670,3 +679,3 @@ .prepend('tags', ['sriracha', 'hotsauce'])

t.deepEqual(patch, {
id: 'foo.123',
id: 'abc123',
inc: {count: 1},

@@ -679,3 +688,3 @@ insert: {before: 'tags[0]', items: ['sriracha', 'hotsauce']}

test('can apply splice()', t => {
const patch = () => getClient().patch('foo.123')
const patch = () => getClient().patch('abc123')
const replaceFirst = patch().splice('tags', 0, 1, ['foo']).serialize()

@@ -703,3 +712,3 @@ const insertInMiddle = patch().splice('tags', 5, 0, ['foo']).serialize()

test('can apply diffMatchPatch()', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
.inc({count: 1})

@@ -710,3 +719,3 @@ .diffMatchPatch({description: '@@ -1,13 +1,12 @@\n The \n-rabid\n+nice\n dog\n'})

t.deepEqual(patch, {
id: 'foo.123',
id: 'abc123',
inc: {count: 1},

@@ -719,3 +728,3 @@ diffMatchPatch: {description: '@@ -1,13 +1,12 @@\n The \n-rabid\n+nice\n dog\n'}

test('all patch methods throw on non-objects being passed as argument', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
t.throws(() => patch.merge([]), /merge\(\) takes an object of properties/, 'merge throws')

@@ -732,3 +741,3 @@ t.throws(() => patch.set(null), /set\(\) takes an object of properties/, 'set throws')

test('executes patch when commit() is called', t => {
const expectedPatch = {patch: {id: 'foo.123', inc: {count: 1}, set: {visited: true}}}
const expectedPatch = {patch: {id: 'abc123', inc: {count: 1}, set: {visited: true}}}
nock(projectHost())

@@ -738,3 +747,3 @@ .post('/v1/data/mutate/foo?returnIds=true&visibility=sync', {mutations: [expectedPatch]})

getClient().patch('foo.123')
getClient().patch('abc123')
.inc({count: 1})

@@ -751,3 +760,3 @@ .set({visited: true})

test('returns patched document by default', t => {
const expectedPatch = {patch: {id: 'foo.123', inc: {count: 1}, set: {visited: true}}}
const expectedPatch = {patch: {id: 'abc123', inc: {count: 1}, set: {visited: true}}}
const expectedBody = {mutations: [expectedPatch]}

@@ -757,6 +766,6 @@ nock(projectHost())

.reply(200, {transactionId: 'blatti', results: [{
id: 'foo.123',
id: 'abc123',
operation: 'update',
document: {
_id: 'foo.123',
_id: 'abc123',
_createdAt: '2016-10-24T08:09:32.997Z',

@@ -768,3 +777,3 @@ count: 2,

getClient().patch('foo.123')
getClient().patch('abc123')
.inc({count: 1})

@@ -774,3 +783,3 @@ .set({visited: true})

.then(res => {
t.equal(res._id, 'foo.123', 'returns patched document')
t.equal(res._id, 'abc123', 'returns patched document')
})

@@ -782,3 +791,3 @@ .catch(t.ifError)

test('commit() returns promise', t => {
const expectedPatch = {patch: {id: 'foo.123', inc: {count: 1}, set: {visited: true}}}
const expectedPatch = {patch: {id: 'abc123', inc: {count: 1}, set: {visited: true}}}
const expectedBody = {mutations: [expectedPatch]}

@@ -789,3 +798,3 @@ nock(projectHost())

getClient().patch('foo.123')
getClient().patch('abc123')
.inc({count: 1})

@@ -801,3 +810,3 @@ .set({visited: true})

test('each patch operation returns same patch', t => {
const patch = getClient().patch('foo.123')
const patch = getClient().patch('abc123')
const inc = patch.inc({count: 1})

@@ -813,3 +822,3 @@ const dec = patch.dec({count: 1})

combined.serialize(),
{id: 'foo.123', inc: {count: 1}, dec: {count: 1}},
{id: 'abc123', inc: {count: 1}, dec: {count: 1}},
'combined patch should have both inc and dec ops'

@@ -822,7 +831,7 @@ )

test('can reset patches to no operations, keeping document ID', t => {
const patch = getClient().patch('foo.123').inc({count: 1}).dec({visits: 1})
const patch = getClient().patch('abc123').inc({count: 1}).dec({visits: 1})
const reset = patch.reset()
t.deepEqual(patch.serialize(), {id: 'foo.123'}, 'correct patch')
t.deepEqual(reset.serialize(), {id: 'foo.123'}, 'reset patch should be empty')
t.deepEqual(patch.serialize(), {id: 'abc123'}, 'correct patch')
t.deepEqual(reset.serialize(), {id: 'abc123'}, 'reset patch should be empty')
t.equal(patch, reset, 'reset mutates, does not clone')

@@ -833,6 +842,6 @@ t.end()

test('patch has toJSON() which serializes patch', t => {
const patch = getClient().patch('foo.123').inc({count: 1})
const patch = getClient().patch('abc123').inc({count: 1})
t.deepEqual(
JSON.parse(JSON.stringify(patch)),
JSON.parse(JSON.stringify({id: 'foo.123', inc: {count: 1}}))
JSON.parse(JSON.stringify({id: 'abc123', inc: {count: 1}}))
)

@@ -859,3 +868,3 @@ t.end()

test('can manually call clone on patch', t => {
const patch1 = getClient().patch('foo.123').inc({count: 1})
const patch1 = getClient().patch('abc123').inc({count: 1})
const patch2 = patch1.clone()

@@ -873,9 +882,9 @@

const trans = getClient().transaction()
.create({_id: 'foo.moo', name: 'foobar'})
.delete('foo.nznjkAJnjgnk')
.create({_id: 'moofoo', name: 'foobar'})
.delete('nznjkAJnjgnk')
.serialize()
t.deepEqual(trans, [
{create: {_id: 'foo.moo', name: 'foobar'}},
{delete: {id: 'foo.nznjkAJnjgnk'}}
{create: {_id: 'moofoo', name: 'foobar'}},
{delete: {id: 'nznjkAJnjgnk'}}
])

@@ -888,3 +897,3 @@ t.end()

const create = trans.create({count: 1})
const combined = create.delete('foo.bar')
const combined = create.delete('foobar')

@@ -896,3 +905,3 @@ t.equal(trans, create, 'should be mutated')

combined.serialize(),
[{create: {_id: 'foo.', count: 1}}, {delete: {id: 'foo.bar'}}],
[{create: {count: 1}}, {delete: {id: 'foobar'}}],
'combined transaction should have both create and delete ops'

@@ -904,13 +913,12 @@ )

test('methods are chainable', t => {
test('transaction methods are chainable', t => {
const trans = getClient().transaction()
.create({moo: 'tools'})
.createIfNotExists({j: 'query'})
.createOrReplace({do: 'jo'})
.delete('proto.type')
.patch('foo.bar', {})
.createIfNotExists({_id: 'someId', j: 'query'})
.createOrReplace({_id: 'someOtherId', do: 'jo'})
.delete('prototype')
.patch('foobar', {inc: {sales: 1}})
t.deepEqual(trans.serialize(), [{
create: {
_id: 'foo.',
moo: 'tools'

@@ -920,3 +928,3 @@ }

createIfNotExists: {
_id: 'foo.',
_id: 'someId',
j: 'query'

@@ -926,3 +934,3 @@ }

createOrReplace: {
_id: 'foo.',
_id: 'someOtherId',
do: 'jo'

@@ -932,7 +940,8 @@ }

delete: {
id: 'proto.type'
id: 'prototype'
}
}, {
patch: {
id: 'foo.bar'
id: 'foobar',
inc: {sales: 1}
}

@@ -947,3 +956,3 @@ }])

const trans = getClient().transaction()
.patch('foo.moo', p => p.inc({sales: 1}).dec({stock: 1}))
.patch('moofoo', p => p.inc({sales: 1}).dec({stock: 1}))
.serialize()

@@ -953,3 +962,3 @@

patch: {
id: 'foo.moo',
id: 'moofoo',
inc: {sales: 1},

@@ -964,3 +973,3 @@ dec: {stock: 1}

t.throws(
() => getClient().transaction().patch('foo.moo', noop),
() => getClient().transaction().patch('moofoo', noop),
/must return the patch/

@@ -973,3 +982,3 @@ )

const client = getClient()
const incPatch = client.patch('foo.bar').inc({sales: 1})
const incPatch = client.patch('bar').inc({sales: 1})
const trans = getClient().transaction().patch(incPatch).serialize()

@@ -979,3 +988,3 @@

patch: {
id: 'foo.bar',
id: 'bar',
inc: {sales: 1}

@@ -988,3 +997,3 @@ }

test('executes transaction when commit() is called', t => {
const mutations = [{create: {_id: 'foo.', bar: true}}, {delete: {id: 'foo.bar'}}]
const mutations = [{create: {bar: true}}, {delete: {id: 'barfoo'}}]
nock(projectHost())

@@ -996,3 +1005,3 @@ .post('/v1/data/mutate/foo?returnIds=true&visibility=sync', {mutations})

.create({bar: true})
.delete('foo.bar')
.delete('barfoo')
.commit()

@@ -1011,6 +1020,13 @@ .then(res => {

t.throws(() => trans.createOrReplace('foo'), /object of prop/, 'throws on createOrReplace()')
t.throws(() => trans.delete({id: 'foo.bar'}), /document ID in format/, 'throws on delete()')
t.throws(() => trans.delete({id: 'moofoo'}), /not a valid document ID/, 'throws on delete()')
t.end()
})
test('throws when not including document ID in createOrReplace/createIfNotExists in transaction', t => {
const trans = getClient().transaction()
t.throws(() => trans.createIfNotExists({_type: 'movie', a: 1}), /contains an ID/, 'throws on createIfNotExists()')
t.throws(() => trans.createOrReplace({_type: 'movie', a: 1}), /contains an ID/, 'throws on createOrReplace()')
t.end()
})
test('can manually call clone on transaction', t => {

@@ -1029,3 +1045,3 @@ const trans1 = getClient().transaction().delete('foo.bar')

JSON.parse(JSON.stringify(trans)),
JSON.parse(JSON.stringify([{create: {_id: 'foo.', count: 1}}]))
JSON.parse(JSON.stringify([{create: {count: 1}}]))
)

@@ -1038,4 +1054,4 @@ t.end()

t.deepEqual(
trans.delete('foo.bar').serialize(),
[{delete: {id: 'foo.bar'}}],
trans.delete('barfoo').serialize(),
[{delete: {id: 'barfoo'}}],
'transaction should work without context'

@@ -1046,8 +1062,2 @@ )

test('transaction create() throws if called without a client and document lacks id', t => {
const trans = new sanityClient.Transaction()
t.throws(() => trans.create({foo: 'bar'}), /document needs an _id/i)
t.end()
})
test('transaction commit() throws if called without a client', t => {

@@ -1063,3 +1073,3 @@ const trans = new sanityClient.Transaction()

test('listeners connect to listen endpoint, emits events', t => {
const doc = {_id: 'foo.blah', _type: 'foo.bar', prop: 'value'}
const doc = {_id: 'mooblah', _type: 'foo.bar', prop: 'value'}
const response = [

@@ -1100,31 +1110,29 @@ ':',

/*****************
* HTTP REQUESTS *
* ASSETS *
*****************/
test('uploads images', t => {
const fixturePath = fixture('horsehead-nebula.jpg')
const isImage = body => new Buffer(body, 'hex').compare(fs.readFileSync(fixturePath)) === 0
test('includes token if set', t => {
const qs = '?query=foo.bar'
const token = 'abcdefghijklmnopqrstuvwxyz'
const reqheaders = {'Sanity-Token': token}
nock(projectHost(), {reqheaders}).get(`/v1/data/query/foo${qs}`).reply(200, {})
nock(projectHost())
.post('/v1/assets/images/foo', isImage)
.reply(201, {url: 'https://some.asset.url'})
getClient({token}).fetch('foo.bar')
.then(docs => {
t.equal(docs.length, 0)
})
.catch(t.ifError)
.then(t.end)
getClient().assets.upload('image', fs.createReadStream(fixturePath))
.then(body => {
t.equal(body.url, 'https://some.asset.url')
t.end()
}, ifError(t))
})
test('uploads images', t => {
test('uploads images with given content type', t => {
const fixturePath = fixture('horsehead-nebula.jpg')
const isImage = body => new Buffer(body, 'hex').compare(fs.readFileSync(fixturePath)) === 0
nock(projectHost())
nock(projectHost(), {reqheaders: {'Content-Type': 'image/jpeg'}})
.post('/v1/assets/images/foo', isImage)
.reply(201, {url: 'https://some.asset.url'})
getClient().assets.upload('image', fs.createReadStream(fixturePath))
.filter(event => event.type === 'response')
.map(event => event.body)
.subscribe(body => {
getClient().assets.upload('image', fs.createReadStream(fixturePath), {contentType: 'image/jpeg'})
.then(body => {
t.equal(body.url, 'https://some.asset.url')

@@ -1144,3 +1152,3 @@ t.end()

// @todo write a test that asserts upload events (slowness)
getClient().assets.upload('image', fs.createReadStream(fixturePath))
getClient().observable.assets.upload('image', fs.createReadStream(fixturePath))
.filter(event => event.type === 'progress')

@@ -1163,5 +1171,3 @@ .subscribe(

getClient().assets.upload('image', fs.createReadStream(fixturePath), {label: label})
.filter(event => event.type === 'response') // todo: test progress events too
.map(event => event.body)
.subscribe(body => {
.then(body => {
t.equal(body.label, label)

@@ -1181,5 +1187,3 @@ t.end()

getClient().assets.upload('file', fs.createReadStream(fixturePath))
.filter(event => event.type === 'response')
.map(evt => evt.body)
.subscribe(body => {
.then(body => {
t.equal(body.url, 'https://some.asset.url')

@@ -1199,3 +1203,2 @@ t.end()

getClient().assets.upload('image', fs.createReadStream(fixturePath))
.toPromise()
.then(body => {

@@ -1216,2 +1219,81 @@ t.equal(body.url, 'https://some.asset.url')

test('delete assets given whole asset document', t => {
nock(projectHost()).delete('/v1/assets/images/moo987').reply(200, {some: 'prop'})
const doc = {_id: 'moo987', _type: 'sanity.imageAsset'}
getClient().assets.delete(doc).then(body => {
t.equal(body.some, 'prop')
t.end()
}, ifError(t))
})
/*****************
* AUTH *
*****************/
test('can retrieve auth providers', t => {
const response = {
providers: [{
name: 'providerid',
title: 'providertitle',
url: 'https://some/login/url'
}]
}
nock(projectHost())
.get('/v1/auth/providers')
.reply(200, response)
getClient().auth.getLoginProviders().then(body => {
t.deepEqual(body, response)
t.end()
}, ifError(t))
})
test('can logout', t => {
nock(projectHost())
.get('/v1/auth/logout')
.reply(200)
getClient().auth.logout().then(() => t.end(), ifError(t))
})
/*****************
* USERS *
*****************/
test('can retrieve user by id', t => {
const response = {
role: null,
id: 'Z29vZA2MTc2MDY5MDI1MDA3MzA5MTAwOjozMjM',
name: 'Mannen i Gata',
email: 'some@email.com'
}
nock(projectHost())
.get('/v1/users/me')
.reply(200, response)
getClient().users.getById('me').then(body => {
t.deepEqual(body, response)
t.end()
}, ifError(t))
})
/*****************
* HTTP REQUESTS *
*****************/
test('includes token if set', t => {
const qs = '?query=foo.bar'
const token = 'abcdefghijklmnopqrstuvwxyz'
const reqheaders = {'Sanity-Token': token}
nock(projectHost(), {reqheaders}).get(`/v1/data/query/foo${qs}`).reply(200, {})
getClient({token}).fetch('foo.bar')
.then(docs => {
t.equal(docs.length, 0)
})
.catch(t.ifError)
.then(t.end)
})
// Don't rely on this unless you're working at Sanity Inc ;)

@@ -1243,3 +1325,3 @@ test('can use alternative http requester', t => {

test('handles HTTP errors gracefully', t => {
const doc = {_id: 'foo.bar', visits: 5}
const doc = {_id: 'barfoo', visits: 5}
const expectedBody = {mutations: [{create: doc}]}

@@ -1265,3 +1347,3 @@ nock(projectHost())

test.skip('handles connection timeouts gracefully', t => {
const doc = {_id: 'foo.bar', visits: 5}
const doc = {_id: 'barfoo', visits: 5}
const expectedBody = {mutations: [{create: doc}]}

@@ -1288,3 +1370,3 @@ nock(projectHost())

test.skip('handles socket timeouts gracefully', t => {
const doc = {_id: 'foo.bar', visits: 5}
const doc = {_id: 'barfoo', visits: 5}
const expectedBody = {mutations: [{create: doc}]}

@@ -1291,0 +1373,0 @@ nock(projectHost())

@@ -12,3 +12,3 @@ /* eslint-disable strict */

const apiHost = 'https://api.sanity.url'
const clientConfig = {apiHost: apiHost, projectId: 'bf1942', dataset: 'foo', gradientMode: true}
const clientConfig = {apiHost: apiHost, namespace: 'beerns', gradientMode: true}
const getClient = conf => sanityClient(assign({}, clientConfig, conf || {}))

@@ -19,11 +19,16 @@

*****************/
test('[gradient] throws when creating client without specifying namespace', t => {
t.throws(() => sanityClient({gradientMode: true}), /must contain `namespace`/, 'throws on create()')
t.end()
})
test('[gradient] can query for documents', t => {
const query = 'beerfiesta.beer[.title == $beerName]'
const query = '*[is "beerfiesta.beer" && title == $beerName]'
const params = {beerName: 'Headroom Double IPA'}
const qs = 'beerfiesta.beer%5B.title%20%3D%3D%20%24beerName%5D&%24beerName=%22Headroom%20Double%20IPA%22'
const qs = '*%5Bis%20%22beerfiesta.beer%22%20%26%26%20title%20%3D%3D%20%24beerName%5D&%24beerName=%22Headroom%20Double%20IPA%22'
nock(apiHost).get(`/query/bf1942/foo?query=${qs}`).reply(200, {
nock(apiHost).get(`/query/beerns?query=${qs}`).reply(200, {
ms: 123,
q: query,
result: [{_id: 'beerfiesta.beer:njgNkngskjg', rating: 5}]
result: [{_id: 'njgNkngskjg', _type: 'beerfiesta.beer', rating: 5}]
})

@@ -38,9 +43,9 @@

test('[gradient] can query for single document', t => {
nock(apiHost).get('/doc/bf1942/foo.123').reply(200, {
nock(apiHost).get('/doc/beerns/njgNkngskjg').reply(200, {
ms: 123,
documents: [{_id: 'foo.123', mood: 'lax'}]
documents: [{_id: 'njgNkngskjg', title: 'Headroom Double IPA'}]
})
getClient().getDocument('foo.123').then(res => {
t.equal(res.mood, 'lax', 'data should match')
getClient().getDocument('njgNkngskjg').then(res => {
t.equal(res.title, 'Headroom Double IPA', 'data should match')
}).catch(t.ifError).then(t.end)

@@ -51,10 +56,10 @@ })

const reqheaders = {Authorization: 'Bearer MyToken'}
nock(apiHost, {reqheaders}).get('/doc/bf1942/foo.123').reply(200, {
nock(apiHost, {reqheaders}).get('/doc/beerns/barfoo').reply(200, {
ms: 123,
documents: [{_id: 'foo.123', mood: 'lax'}]
documents: [{_id: 'barfoo', mood: 'lax'}]
})
getClient({token: 'MyToken'}).getDocument('foo.123').then(res => {
getClient({token: 'MyToken'}).getDocument('barfoo').then(res => {
t.equal(res.mood, 'lax', 'data should match')
}).catch(t.ifError).then(t.end)
})

@@ -1,2 +0,2 @@

!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.SanityClient=t()}}(function(){return function t(e,r,n){function o(s,u){if(!r[s]){if(!e[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[s]={exports:{}};e[s][0].call(l.exports,function(t){var r=e[s][1][t];return o(r?r:t)},l,l.exports,t,e,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(t,e,r){"use strict";function n(t){this.client=t}var o=t("object-assign"),i=t("../validators");o(n.prototype,{upload:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};i.validateAssetType(t);var n=i.hasDataset(this.client.clientConfig),o="image"===t?"images":"files";return this.client.requestObservable({method:"POST",timeout:r.timeout||0,query:r.label?{label:r.label}:{},url:"/assets/"+o+"/"+n,headers:r.contentType?{"Content-Type":r.contentType}:{},body:e})},delete:function(t,e){var r=t,n=e;t._type&&(r=t._type.replace(/^(sanity\.|Asset$)/g,""),n=t._id),i.validateAssetType(r),i.validateDocumentId("delete",n);var o="image"===r?"images":"files";return this.client.request({method:"DELETE",url:"/assets/"+o+"/"+n})}}),e.exports=n},{"../validators":18,"object-assign":41}],2:[function(t,e,r){"use strict";function n(t){this.client=t}var o=t("object-assign");o(n.prototype,{getLoginProviders:function(){return this.client.request({uri:"/auth/providers"})},logout:function(){return this.client.request({uri:"/auth/logout"})}}),e.exports=n},{"object-assign":41}],3:[function(t,e,r){"use strict";var n=t("object-assign"),o=t("./validators"),i=r.defaultConfig={apiHost:"https://api.sanity.io",useProjectHostname:!0,gradientMode:!1};r.initConfig=function(t,e){var r=n({},i,e,t),s=r.useProjectHostname;if("undefined"==typeof Promise)throw new Error("No native `Promise`-implementation found, polyfill needed");if(s&&!r.projectId)throw new Error("Configuration must contain `projectId`");if(s&&o.projectId(r.projectId),r.dataset&&o.dataset(r.dataset),r.gradientMode)r.url=r.apiHost;else{var u=r.apiHost.split("://",2),a=u[0],c=u[1];r.useProjectHostname?r.url=a+"://"+r.projectId+"."+c+"/v1":r.url=r.apiHost+"/v1"}return r}},{"./validators":18,"object-assign":41}],4:[function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var o=t("object-assign"),i=t("../validators"),s=t("../util/getSelection"),u=t("./encodeQueryString"),a=t("./transaction"),c=t("./patch"),l=t("./listen"),f=function(t,e){var r="undefined"==typeof t?e:t;return t===!1?void 0:r},p=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{returnIds:!0,returnDocuments:f(t.returnDocuments,!0),visibility:t.visibility||"sync"}},h=1948;e.exports={listen:l,getDataUrl:function(t,e){var r=this.clientConfig.projectId;return(this.clientConfig.gradientMode?"/"+t+"/"+r+"/"+e:"/data/"+t+"/"+e).replace(/\/($|\?)/,"$1")},fetch:function(t,e){return this.dataRequest("query",{query:t,params:e}).then(function(t){return t.result||[]})},getDocument:function(t){return this.request({uri:this.getDataUrl("doc",t),json:!0}).then(function(t){return t.documents&&t.documents[0]})},create:function(t,e){return this._create(t,"create",e)},createIfNotExists:function(t,e){return this._create(t,"createIfNotExists",e)},createOrReplace:function(t,e){return this._create(t,"createOrReplace",e)},patch:function(t,e){return new c(t,e,this)},delete:function(t,e){return this.dataRequest("mutate",{mutations:[{delete:s(t)}]},e)},mutate:function(t,e){var r=t instanceof c?t.serialize():t,n=Array.isArray(r)?r:[r];return this.dataRequest("mutate",{mutations:n},e)},transaction:function(t){return new a(t,this)},dataRequest:function(t,e){var r=this,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s="mutate"===t,a=!s&&u(e),c=!s&&a.length<h,l=c?a:"",f=o.returnFirst;return i.promise.hasDataset(this.clientConfig).then(function(n){return r.request({method:c?"GET":"POST",uri:r.getDataUrl(t,""+n+l),json:!0,body:c?void 0:e,query:s&&p(o)})}).then(function(t){if(!s)return t;var e=t.results||[];if(o.returnDocuments)return f?e[0]&&e[0].document:e.map(function(t){return t.document});var r=f?"documentId":"documentIds",i=f?e[0]&&e[0].id:e.map(function(t){return t.id});return n({transactionId:t.transactionId,results:e},r,i)})},_create:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=i.hasDataset(this.clientConfig),u=n({},e,o({},t,{_id:t._id||s+"."})),a=o({returnFirst:!0,returnDocuments:!0},r);return this.dataRequest("mutate",{mutations:[u]},a)}}},{"../util/getSelection":16,"../validators":18,"./encodeQueryString":5,"./listen":6,"./patch":7,"./transaction":8,"object-assign":41}],5:[function(t,e,r){"use strict";var n=encodeURIComponent;e.exports=function(t){var e=t.query,r=t.params,o=void 0===r?{}:r,i=t.options,s=void 0===i?{}:i,u=Object.keys(o).reduce(function(t,e){return t+"&"+n("$"+e)+"="+n(JSON.stringify(o[e]))},"?query="+n(e));return Object.keys(s).reduce(function(t,e){return s[e]?t+"&"+n(e)+"="+n(s[e]):t},u)}},{}],6:[function(t,e,r){"use strict";function n(t){try{var e=t.data&&JSON.parse(t.data)||{};return s({type:t.type},e)}catch(t){return t}}function o(t){if(t instanceof Error)return t;var e=n(t);return e instanceof Error?e:new Error(i(e))}function i(t){return t.error?t.error.description?t.error.description:"string"==typeof t.error?t.error:JSON.stringify(t.error,null,2):t.message||"Unknown listener error"}var s=t("object-assign"),u=t("@sanity/observable/minimal"),a=t("./encodeQueryString"),c=t("../validators"),l=t("../util/pick"),f=t("../util/defaults"),p="undefined"!=typeof window&&window.EventSource?window.EventSource:t("@sanity/eventsource"),h=function(t,e,r){t.removeEventListener?t.removeEventListener(e,r,!1):t.removeListener(e,r)},d=["includePreviousRevision","includeResult"],b={includeResult:!0};e.exports=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=f(r,b),y=l(i,d),v=a({query:t,params:e,options:y}),m=c.hasDataset(this.clientConfig),g=""+this.clientConfig.url+this.getDataUrl("listen",""+m+v),w=this.clientConfig.token,_=i.events?i.events:["mutation"],j=_.indexOf("reconnect")!==-1,O=new p(g,s({withCredentials:!0},w?{headers:{"Sanity-Token":w}}:{}));return new u(function(t){function e(){O.readyState===p.CLOSED?t.complete():O.readyState===p.CONNECTING&&a()}function r(e){t.error(o(e))}function i(e){var r=n(e);return r instanceof Error?t.error(r):t.next(r)}function s(e){t.complete(),u()}function u(){_.forEach(function(t){return h(O,t,i)}),h(O,"error",e),h(O,"channelError",r),h(O,"disconnect",s),O.close()}function a(){j&&t.next({type:"reconnect"})}return O.addEventListener("error",e,!1),O.addEventListener("channelError",r,!1),O.addEventListener("disconnect",s,!1),_.forEach(function(t){return O.addEventListener(t,i,!1)}),u})}},{"../util/defaults":15,"../util/pick":17,"../validators":18,"./encodeQueryString":5,"@sanity/eventsource":50,"@sanity/observable/minimal":53,"object-assign":41}],7:[function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.selection=t,this.operations=s({},e),this.client=r}var i=t("deep-assign"),s=t("object-assign"),u=t("../util/getSelection"),a=t("../validators"),c=a.validateObject,l=a.validateInsert;s(o.prototype,{clone:function(){return new o(this.selection,s({},this.operations),this.client)},merge:function(t){return c("merge",t),this._assign("merge",i(this.operations.merge||{},t))},set:function(t){return this._assign("set",t)},diffMatchPatch:function(t){return c("diffMatchPatch",t),this._assign("diffMatchPatch",t)},unset:function(t){if(!Array.isArray(t))throw new Error("unset(attrs) takes an array of attributes to unset, non-array given");return this.operations=s({},this.operations,{unset:t}),this},setIfMissing:function(t){return this._assign("setIfMissing",t)},replace:function(t){return c("replace",t),this._set("set",{$:t})},inc:function(t){return this._assign("inc",t)},dec:function(t){return this._assign("dec",t)},insert:function(t,e,r){var o;return l(t,e,r),this._assign("insert",(o={},n(o,t,e),n(o,"items",r),o))},append:function(t,e){return this.insert("after",t+"[-1]",e)},prepend:function(t,e){return this.insert("before",t+"[0]",e)},splice:function(t,e,r,n){var o="undefined"==typeof r||r===-1,i=e<0?e-1:e,s=o?-1:Math.max(0,e+r),u=i<0&&s>=0?"":s,a=t+"["+i+":"+u+"]";return this.insert("replace",a,n||[])},serialize:function(){return s(u(this.selection),this.operations)},toJSON:function(){return this.serialize()},commit:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.client)throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");var e="string"==typeof this.selection,r=s({returnFirst:e,returnDocuments:!0},t);return this.client.mutate({patch:this.serialize()},r)},reset:function(){return this.operations={},this},_set:function(t,e){return this._assign(t,e,!1)},_assign:function(t,e){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return c(t,e),this.operations=s({},this.operations,n({},t,s({},r&&this.operations[t]||{},e))),this}}),e.exports=o},{"../util/getSelection":16,"../validators":18,"deep-assign":21,"object-assign":41}],8:[function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments[1];this.operations=t,this.client=e}var i=t("object-assign"),s=t("../validators"),u=t("./patch"),a={returnDocuments:!1};i(o.prototype,{clone:function(){return new o(this.operations.slice(0),this.client)},create:function(t){return this._create(t,"create")},createIfNotExists:function(t){return this._create(t,"createIfNotExists")},createOrReplace:function(t){return this._create(t,"createOrReplace")},delete:function(t){return s.validateDocumentId("delete",t),this._add({delete:{id:t}})},patch:function t(e,r){var n="function"==typeof r,o=e instanceof u;if(o)return this._add({patch:e.serialize()});if(n){var t=r(new u(e,{},this.client));if(!(t instanceof u))throw new Error("function passed to `patch()` must return the patch");return this._add({patch:t.serialize()})}return this._add({patch:i({id:e},r)})},serialize:function(){return this.operations.slice()},toJSON:function(){return this.serialize()},commit:function(t){if(!this.client)throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");return this.client.mutate(this.serialize(),t||a)},reset:function(){return this.operations=[],this},_create:function(t,e){if(!t._id&&!this.client)throw new Error('Document needs an _id property when transaction is create outside a client scope. Pass `{_id: "<datasetName>:"}` to have Sanity generate an ID for you.');s.validateObject(e,t);var r=s.hasDataset(this.client.clientConfig),o=n({},e,i({},t,{_id:t._id||r+"."}));return this._add(o)},_add:function(t){return this.operations.push(t),this}}),e.exports=o},{"../validators":18,"./patch":7,"object-assign":41}],9:[function(t,e,r){"use strict";function n(t){this.request=t.request.bind(t)}var o=t("object-assign"),i=t("../validators");o(n.prototype,{create:function(t){return this._modify("PUT",t)},delete:function(t){return this._modify("DELETE",t)},list:function(){return this.request({uri:"/datasets"})},_modify:function(t,e){return i.dataset(e),this.request({method:t,uri:"/datasets/"+e})}}),e.exports=n},{"../validators":18,"object-assign":41}],10:[function(t,e,r){"use strict";function n(t){return!!p.shouldRetry(t)||t.response&&t.response.statusCode>=500}function o(t){var e=t.body;return this.response=t,this.statusCode=t.statusCode,this.responseBody=s(e,t),e.error&&e.message?void(this.message=e.error+" - "+e.message):e.error&&e.error.description?(this.message=e.error.description,void(this.details=e.error)):void(this.message=e.error||e.message||i(t))}function i(t){var e=t.statusMessage?" "+t.statusMessage:"";return t.method+"-request to "+t.url+" resulted in HTTP "+t.statusCode+e}function s(t,e){var r=(e.headers["content-type"]||"").toLowerCase(),n=r.indexOf("application/json")!==-1;return n?JSON.stringify(t,null,2):t}function u(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:_,r=e(c({maxRedirects:0},t));return r.toPromise=function(){return new Promise(function(t,e){r.filter(function(t){return"response"===t.type}).subscribe(function(e){return t(e.body)},e)})},r}var a=t("get-it"),c=t("object-assign"),l=t("create-error-class"),f=t("get-it/lib/middleware/observable"),p=t("get-it/lib/middleware/retry"),h=t("get-it/lib/middleware/jsonRequest"),d=t("get-it/lib/middleware/jsonResponse"),b=t("@sanity/observable/minimal"),y=t("get-it/lib/middleware/progress"),v=l("ClientError",o),m=l("ServerError",o),g={onResponse:function(t){if(t.statusCode>=500)throw new m(t);if(t.statusCode>=400)throw new v(t);return t}},w=[h(),d(),y(),g,f({implementation:b}),p({maxRetries:5,shouldRetry:n})],_=a(w);u.defaultRequester=_,e.exports=u},{"@sanity/observable/minimal":53,"create-error-class":20,"get-it":23,"get-it/lib/middleware/jsonRequest":25,"get-it/lib/middleware/jsonResponse":26,"get-it/lib/middleware/observable":27,"get-it/lib/middleware/progress":29,"get-it/lib/middleware/retry":30,"object-assign":41}],11:[function(t,e,r){"use strict";var n="Sanity-Token",o="Sanity-Project-ID";e.exports=function(t){var e={};return t.token&&t.gradientMode?e.Authorization="Bearer "+t.token:t.token&&(e[n]=t.token),!t.useProjectHostname&&t.projectId&&(e[o]=t.projectId),{headers:e,timeout:"timeout"in t?t.timeout:3e4,withCredentials:!0,json:!0}}},{}],12:[function(t,e,r){"use strict";function n(t){this.client=t}var o=t("object-assign");o(n.prototype,{list:function(){return this.client.request({uri:"/projects"})},getById:function(t){return this.client.request({uri:"/projects/"+t})}}),e.exports=n},{"object-assign":41}],13:[function(t,e,r){"use strict";function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:m;this.config(t),this.assets=new p(this),this.datasets=new l(this),this.projects=new f(this),this.users=new h(this),this.auth=new d(this)}function o(){for(var t=arguments.length,e=Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=e.reduce(function(t,e){return t||e.headers?s(t||{},e.headers||{}):null},null);return s.apply(void 0,e.concat([n?{headers:n}:{}]))}function i(t){return new n(t)}var s=t("object-assign"),u=t("./data/patch"),a=t("./data/transaction"),c=t("./data/dataMethods"),l=t("./datasets/datasetsClient"),f=t("./projects/projectsClient"),p=t("./assets/assetsClient"),h=t("./users/usersClient"),d=t("./auth/authClient"),b=t("./http/request"),y=t("./http/requestOptions"),v=t("./config"),m=v.defaultConfig,g=v.initConfig;s(n.prototype,c),s(n.prototype,{clone:function(){return new n(this.config())},config:function(t){return"undefined"==typeof t?s({},this.clientConfig):(this.clientConfig=g(t,this.clientConfig||{}),this)},getUrl:function(t){return this.clientConfig.url+"/"+t.replace(/^\//,"")},request:function(t){return this.requestObservable(t).toPromise()},requestObservable:function(t){return b(o(y(this.clientConfig),t,{url:this.getUrl(t.url||t.uri)}),this.clientConfig.requester)}}),i.Patch=u,i.Transaction=a,i.requester=b.defaultRequester,e.exports=i},{"./assets/assetsClient":1,"./auth/authClient":2,"./config":3,"./data/dataMethods":4,"./data/patch":7,"./data/transaction":8,"./datasets/datasetsClient":9,"./http/request":10,"./http/requestOptions":11,"./projects/projectsClient":12,"./users/usersClient":14,"object-assign":41}],14:[function(t,e,r){"use strict";function n(t){this.client=t}var o=t("object-assign");o(n.prototype,{getById:function(t){return this.client.request({uri:"/users/"+t})}}),e.exports=n},{"object-assign":41}],15:[function(t,e,r){"use strict";e.exports=function(t,e){return Object.keys(e).concat(Object.keys(t)).reduce(function(r,n){return r[n]="undefined"==typeof t[n]?e[n]:t[n],r},{})}},{}],16:[function(t,e,r){"use strict";e.exports=function(t){if("string"==typeof t||Array.isArray(t))return{id:t};if(t&&t.query)return{query:t.query};var e=["* Dataset-prefixed document ID (<dataset.docId>)","* Array of dataset-prefixed document IDs","* Object containing `query`"].join("\n");throw new Error("Unknown selection - must be one of:\n\n"+e)}},{}],17:[function(t,e,r){"use strict";e.exports=function(t,e){return e.reduce(function(e,r){return"undefined"==typeof t[r]?e:(e[r]=t[r],e)},{})}},{}],18:[function(t,e,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=["image","file"],i=["before","after","replace"];r.dataset=function(t){if(!/^[-\w]{1,128}$/.test(t))throw new Error("Datasets can only contain lowercase characters, numbers, underscores and dashes")},r.projectId=function(t){if(!/^[-a-z0-9]+$/i.test(t))throw new Error("`projectId` can only contain only a-z, 0-9 and dashes")},r.validateAssetType=function(t){if(o.indexOf(t)===-1)throw new Error("Invalid asset type: "+t+". Must be one of "+o.join(", "))},r.validateObject=function(t,e){if(null===e||"object"!==("undefined"==typeof e?"undefined":n(e))||Array.isArray(e))throw new Error(t+"() takes an object of properties")},r.validateDocumentId=function(t,e){if("string"!=typeof e||!/^[-_a-z0-9]{1,128}\.[-_a-z0-9.]+$/i.test(e))throw new Error(t+"() takes a document ID in format dataset.docId")},r.validateInsert=function(t,e,r){var n="insert(at, selector, items)";if(i.indexOf(t)===-1){var o=i.map(function(t){return'"'+t+'"'}).join(", ");throw new Error(n+' takes an "at"-argument which is one of: '+o)}if("string"!=typeof e)throw new Error(n+' takes a "selector"-argument which must be a string');if(!Array.isArray(r))throw new Error(n+' takes an "items"-argument which must be an array')},r.hasDataset=function(t){if(!t.gradientMode&&!t.dataset)throw new Error("`dataset` must be provided to perform queries");return t.dataset||""},r.promise={hasDataset:function(t){return new Promise(function(e){return e(r.hasDataset(t))})}}},{}],19:[function(t,e,r){"use strict";e.exports=Error.captureStackTrace||function(t){var e=new Error;Object.defineProperty(t,"stack",{configurable:!0,get:function(){var t=e.stack;return Object.defineProperty(this,"stack",{value:t}),t}})}},{}],20:[function(t,e,r){"use strict";function n(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}var o=t("capture-stack-trace");e.exports=function(t,e){if("string"!=typeof t)throw new TypeError("Expected className to be a string");if(/[^0-9a-zA-Z_$]/.test(t))throw new Error("className contains invalid characters");e=e||function(t){this.message=t};var r=function(){Object.defineProperty(this,"name",{configurable:!0,value:t,writable:!0}),o(this,this.constructor),e.apply(this,arguments)};return n(r,Error),r}},{"capture-stack-trace":19}],21:[function(t,e,r){"use strict";function n(t){if(null===t||void 0===t)throw new TypeError("Sources cannot be null or undefined");return Object(t)}function o(t,e,r){var n=e[r];if(void 0!==n&&null!==n){if(u.call(t,r)&&(void 0===t[r]||null===t[r]))throw new TypeError("Cannot convert undefined or null to object ("+r+")");u.call(t,r)&&s(n)?t[r]=i(Object(t[r]),e[r]):t[r]=n}}function i(t,e){if(t===e)return t;e=Object(e);for(var r in e)u.call(e,r)&&o(t,e,r);if(Object.getOwnPropertySymbols)for(var n=Object.getOwnPropertySymbols(e),i=0;i<n.length;i++)a.call(e,n[i])&&o(t,e,n[i]);return t}var s=t("is-obj"),u=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;e.exports=function(t){t=n(t);for(var e=1;e<arguments.length;e++)i(t,arguments[e]);return t}},{"is-obj":37}],22:[function(t,e,r){function n(t,e,r){if(!u(e))throw new TypeError("iterator must be a function");arguments.length<3&&(r=this),"[object Array]"===a.call(t)?o(t,e,r):"string"==typeof t?i(t,e,r):s(t,e,r)}function o(t,e,r){for(var n=0,o=t.length;n<o;n++)c.call(t,n)&&e.call(r,t[n],n,t)}function i(t,e,r){for(var n=0,o=t.length;n<o;n++)e.call(r,t.charAt(n),n,t)}function s(t,e,r){for(var n in t)c.call(t,n)&&e.call(r,t[n],n,t)}var u=t("is-function");e.exports=n;var a=Object.prototype.toString,c=Object.prototype.hasOwnProperty},{"is-function":36}],23:[function(t,e,r){"use strict";var n=t("nano-pubsub"),o=t("./util/middlewareReducer"),i=t("./middleware/defaultOptionsProcessor"),s=t("./request"),u=["request","response","progress","error","abort"],a=["processOptions","onRequest","onResponse","onError","onReturn","onHeaders"];e.exports=function t(){function e(t){function e(t,e,n){var o=t,s=e;if(!o)try{s=i("onResponse",e,n)}catch(t){s=null,o=t}o=o&&i("onError",o,n),o?r.error.publish(o):s&&r.response.publish(s)}var r=u.reduce(function(t,e){return t[e]=n(),t},{}),i=o(l),a=i("processOptions",t),c={options:a,channels:r,applyMiddleware:i},f=null,p=r.request.subscribe(function(t){f=s(t,function(r,n){return e(r,n,t)})});r.abort.subscribe(function(){p(),f&&f.abort()});var h=i("onReturn",r,c);return h===r&&r.request.publish(c),h}var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],c=[],l=a.reduce(function(t,e){return t[e]=t[e]||[],t},{processOptions:[i]});return e.use=function(t){if(!t)throw new Error("Tried to add middleware that resolved to falsey value");if("function"==typeof t)throw new Error("Tried to add middleware that was a function. It probably expects you to pass options to it.");if(t.onReturn&&l.onReturn.length>0)throw new Error("Tried to add new middleware with `onReturn` handler, but another handler has already been registered for this event");a.forEach(function(e){t[e]&&l[e].push(t[e])}),c.push(t)},e.clone=function(){return t(c)},r.forEach(e.use),e}},{"./middleware/defaultOptionsProcessor":24,"./request":32,"./util/middlewareReducer":35,"nano-pubsub":40}],24:[function(t,e,r){"use strict";function n(t){if(t===!1||0===t)return!1;if(t.connect||t.socket)return t;var e=Number(t);return isNaN(e)?n(u.timeout):{connect:e,socket:e}}function o(t){var e={};for(var r in t)void 0!==t[r]&&(e[r]=t[r]);return e}var i=t("object-assign"),s=t("url-parse"),u={timeout:12e4};e.exports=function(t){var e="string"==typeof t?i({url:t},u):i({},u,t),r=s(e.url,{},!0);return e.timeout=n(e.timeout),e.query&&(r.query=i({},r.query,o(e.query))),e.method=e.body&&!e.method?"POST":(e.method||"GET").toUpperCase(),e.url=r.toString(),e}},{"object-assign":41,"url-parse":48}],25:[function(t,e,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=t("object-assign"),i=t("is-plain-object"),s=["boolean","string","number"],u=function(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)};e.exports=function(){return{processOptions:function(t){var e=t.body,r=e&&!u(e)&&(s.indexOf("undefined"==typeof e?"undefined":n(e))!==-1||Array.isArray(e)||i(e)||e&&"function"==typeof e.toJSON);return r?o({},t,{body:JSON.stringify(t.body),headers:o({},t.headers,{"Content-Type":"application/json"})}):t}}}},{"is-plain-object":38,"object-assign":41}],26:[function(t,e,r){"use strict";function n(t){try{return JSON.parse(t)}catch(t){throw t.message="Failed to parsed response body as JSON: "+t.message,t}}var o=t("object-assign");e.exports=function(){return{onResponse:function(t){var e=t.headers["content-type"];return t.body&&e&&e.indexOf("application/json")!==-1?o({},t,{body:n(t.body)}):t},processOptions:function(t){return o({},t,{headers:o({Accept:"application/json"},t.headers)})}}}},{"object-assign":41}],27:[function(t,e,r){"use strict";var n=t("../util/global"),o=t("object-assign");e.exports=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.implementation||n.Observable;if(!e)throw new Error("`Observable` is not available in global scope, and no implementation was passed");return{onReturn:function(t,r){return new e(function(e){return t.error.subscribe(function(t){return e.error(t)}),t.progress.subscribe(function(t){return e.next(o({type:"progress"},t))}),t.response.subscribe(function(t){e.next(o({type:"response"},t)),e.complete()}),t.request.publish(r),function(){return t.abort.publish()}})}}}},{"../util/global":34,"object-assign":41}],28:[function(t,e,r){"use strict";e.exports=function(){return{onRequest:function(t){function e(t){return function(e){var r=e.lengthComputable?e.loaded/e.total*100:-1;n.channels.progress.publish({stage:t,percent:r,total:e.total,loaded:e.loaded,lengthComputable:e.lengthComputable})}}if("xhr"===t.adapter){var r=t.request,n=t.context;"upload"in r&&"onprogress"in r.upload&&(r.upload.onprogress=e("upload")),"onprogress"in r&&(r.onprogress=e("download"))}}}}},{}],29:[function(t,e,r){"use strict";e.exports=t("./node-progress")},{"./node-progress":28}],30:[function(t,e,r){"use strict";function n(t){return 100*Math.pow(2,t)+100*Math.random()}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=t("object-assign"),s=t("../util/node-shouldRetry"),u=function(t){return null!==t&&"object"===("undefined"==typeof t?"undefined":o(t))&&"function"==typeof t.pipe},a=e.exports=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.maxRetries||5,r=t.retryDelay||n,o=t.shouldRetry||s;return{onError:function(t,n){var s=n.options,a=s.maxRetries||e,c=s.shouldRetry||o,l=s.attemptNumber||0;if(u(s.body))return t;if(!c(t,l)||l>=a)return t;var f=i({},n,{options:i({},s,{attemptNumber:l+1})});return setTimeout(function(){return n.channels.request.publish(f)},r(l)),null}}};a.shouldRetry=s},{"../util/node-shouldRetry":33,"object-assign":41}],31:[function(t,e,r){"use strict";var n=t("same-origin"),o=t("parse-headers"),i=function(){},s=window,u=s.XMLHttpRequest||i,a="withCredentials"in new u,c=a?u:s.XDomainRequest,l="xhr";e.exports=function(t,e){function r(){_=!0,m.abort()}function i(e){O=!0,m.abort();var r=new Error("ESOCKETTIMEDOUT"===e?"Socket timed out on request to "+b.url:"Connection timed out on request to "+b.url);r.code=e,t.channels.error.publish(r)}function a(){E&&(f(),v.socket=setTimeout(function(){return i("ESOCKETTIMEDOUT")},E.socket))}function f(){(_||m.readyState>=2&&v.connect)&&clearTimeout(v.connect),v.socket&&clearTimeout(v.socket)}function p(){if(!j){f(),j=!0,m=null;var t=new Error("Network error while attempting to reach "+b.url);t.isNetworkError=!0,t.request=b,e(t)}}function h(){var t=m.status,e=m.statusText;if(g&&void 0===t)t=200;else{if(t>12e3&&t<12156)return p();t=1223===m.status?204:m.status,e=1223===m.status?"No Content":e}return{body:m.response||m.responseText,url:b.url,method:b.method,headers:g?{}:o(m.getAllResponseHeaders()),statusCode:t,statusMessage:e}}function d(){if(!(_||j||O)){if(0===m.status)return void p(new Error("Unknown XHR error"));f(),j=!0,e(null,h())}}var b=t.options,y=!n(s.location.href,b.url),v={},m=y?new c:new u,g=s.XDomainRequest&&m instanceof s.XDomainRequest,w=b.headers,_=!1,j=!1,O=!1;m.onerror=p,m.ontimeout=p,m.onabort=function(){_=!0},m.onprogress=function(){};var x=g?"onload":"onreadystatechange";if(m[x]=function(){a(),_||4!==m.readyState&&!g||0!==m.status&&d()},m.open(b.method,b.url,!0),m.withCredentials=!!b.withCredentials,w&&m.setRequestHeader)for(var S in w)w.hasOwnProperty(S)&&m.setRequestHeader(S,w[S]);else if(w&&g)throw new Error("Headers cannot be set on an XDomainRequest object");b.rawBody&&(m.responseType="arraybuffer"),t.applyMiddleware("onRequest",{options:b,adapter:l,request:m,context:t}),m.send(b.body||null);var E=b.timeout;return E&&(v.connect=setTimeout(function(){return i("ETIMEDOUT")},E.connect)),{abort:r}}},{"parse-headers":42,"same-origin":45}],32:[function(t,e,r){"use strict";e.exports=t("./node-request")},{"./node-request":31}],33:[function(t,e,r){"use strict";e.exports=function(t){return t.isNetworkError||!1}},{}],34:[function(t,e,r){(function(t){"use strict";"undefined"!=typeof window?e.exports=window:"undefined"!=typeof t?e.exports=t:"undefined"!=typeof self?e.exports=self:e.exports={}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],35:[function(t,e,r){"use strict";e.exports=function(t){var e=function(e,r){for(var n=arguments.length,o=Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];return t[e].reduce(function(t,e){return e.apply(void 0,[t].concat(o))},r)};return e}},{}],36:[function(t,e,r){function n(t){var e=o.call(t);return"[object Function]"===e||"function"==typeof t&&"[object RegExp]"!==e||"undefined"!=typeof window&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)}e.exports=n;var o=Object.prototype.toString},{}],37:[function(t,e,r){"use strict";e.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}},{}],38:[function(t,e,r){"use strict";function n(t){return o(t)===!0&&"[object Object]"===Object.prototype.toString.call(t)}var o=t("isobject");e.exports=function(t){var e,r;return n(t)!==!1&&(e=t.constructor,"function"==typeof e&&(r=e.prototype,n(r)!==!1&&r.hasOwnProperty("isPrototypeOf")!==!1))}},{isobject:39}],39:[function(t,e,r){"use strict";e.exports=function(t){return null!=t&&"object"==typeof t&&!Array.isArray(t)}},{}],40:[function(t,e,r){e.exports=function(){function t(t){return r.push(t),function(){var e=r.indexOf(t);e>-1&&r.splice(e,1)}}function e(){for(var t=0;t<r.length;t++)r[t].apply(null,arguments)}var r=[];return{subscribe:t,publish:e}}},{}],41:[function(t,e,r){"use strict";function n(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function o(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;var n=Object.getOwnPropertyNames(e).map(function(t){return e[t]});if("0123456789"!==n.join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach(function(t){o[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(t){return!1}}var i=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,u=Object.prototype.propertyIsEnumerable;e.exports=o()?Object.assign:function(t,e){for(var r,o,a=n(t),c=1;c<arguments.length;c++){r=Object(arguments[c]);for(var l in r)s.call(r,l)&&(a[l]=r[l]);if(i){o=i(r);for(var f=0;f<o.length;f++)u.call(r,o[f])&&(a[o[f]]=r[o[f]])}}return a}},{}],42:[function(t,e,r){var n=t("trim"),o=t("for-each"),i=function(t){return"[object Array]"===Object.prototype.toString.call(t)};e.exports=function(t){if(!t)return{};var e={};return o(n(t).split("\n"),function(t){var r=t.indexOf(":"),o=n(t.slice(0,r)).toLowerCase(),s=n(t.slice(r+1));"undefined"==typeof e[o]?e[o]=s:i(e[o])?e[o].push(s):e[o]=[e[o],s]}),e}},{"for-each":22,trim:47}],43:[function(t,e,r){"use strict";function n(t){for(var e,r=/([^=?&]+)=?([^&]*)/g,n={};e=r.exec(t);n[decodeURIComponent(e[1])]=decodeURIComponent(e[2]));return n}function o(t,e){e=e||"";var r=[];"string"!=typeof e&&(e="?");for(var n in t)i.call(t,n)&&r.push(encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return r.length?e+r.join("&"):""}var i=Object.prototype.hasOwnProperty;r.stringify=o,r.parse=n},{}],44:[function(t,e,r){
"use strict";e.exports=function(t,e){if(e=e.split(":")[0],t=+t,!t)return!1;switch(e){case"http":case"ws":return 80!==t;case"https":case"wss":return 443!==t;case"ftp":return 21!==t;case"gopher":return 70!==t;case"file":return!1}return 0!==t}},{}],45:[function(t,e,r){"use strict";var n=t("url");e.exports=function(t,e,r){if(t===e)return!0;var o=n.parse(t,!1,!0),i=n.parse(e,!1,!0),s=0|o.port||("https"===o.protocol?443:80),u=0|i.port||("https"===i.protocol?443:80),a={proto:o.protocol===i.protocol,hostname:o.hostname===i.hostname,port:s===u};return a.proto&&a.hostname&&(a.port||r)}},{url:46}],46:[function(t,e,r){"use strict";var n=/^(?:(?:(?:([^:\/#\?]+:)?(?:(?:\/\/)((?:((?:[^:@\/#\?]+)(?:\:(?:[^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((?:\/?(?:[^\/\?#]+\/+)*)(?:[^\?#]*)))?(\?[^#]+)?)(#.*)?/;e.exports={regex:n,parse:function(t){var e=n.exec(t);return e?{protocol:(e[1]||"").toLowerCase()||void 0,hostname:(e[5]||"").toLowerCase()||void 0,port:e[6]||void 0}:{}}}},{}],47:[function(t,e,r){function n(t){return t.replace(/^\s*|\s*$/g,"")}r=e.exports=n,r.left=function(t){return t.replace(/^\s*/,"")},r.right=function(t){return t.replace(/\s*$/,"")}},{}],48:[function(t,e,r){"use strict";function n(t){var e=c.exec(t);return{protocol:e[1]?e[1].toLowerCase():"",slashes:!!e[2],rest:e[3]}}function o(t,e){for(var r=(e||"/").split("/").slice(0,-1).concat(t.split("/")),n=r.length,o=r[n-1],i=!1,s=0;n--;)"."===r[n]?r.splice(n,1):".."===r[n]?(r.splice(n,1),s++):s&&(0===n&&(i=!0),r.splice(n,1),s--);return i&&r.unshift(""),"."!==o&&".."!==o||r.push(""),r.join("/")}function i(t,e,r){if(!(this instanceof i))return new i(t,e,r);var c,f,p,h,d,b,y=l.slice(),v=typeof e,m=this,g=0;for("object"!==v&&"string"!==v&&(r=e,e=null),r&&"function"!=typeof r&&(r=a.parse),e=u(e),f=n(t||""),c=!f.protocol&&!f.slashes,m.slashes=f.slashes||c&&e.slashes,m.protocol=f.protocol||e.protocol||"",t=f.rest,f.slashes||(y[2]=[/(.*)/,"pathname"]);g<y.length;g++)h=y[g],p=h[0],b=h[1],p!==p?m[b]=t:"string"==typeof p?~(d=t.indexOf(p))&&("number"==typeof h[2]?(m[b]=t.slice(0,d),t=t.slice(d+h[2])):(m[b]=t.slice(d),t=t.slice(0,d))):(d=p.exec(t))&&(m[b]=d[1],t=t.slice(0,d.index)),m[b]=m[b]||(c&&h[3]?e[b]||"":""),h[4]&&(m[b]=m[b].toLowerCase());r&&(m.query=r(m.query)),c&&e.slashes&&"/"!==m.pathname.charAt(0)&&(""!==m.pathname||""!==e.pathname)&&(m.pathname=o(m.pathname,e.pathname)),s(m.port,m.protocol)||(m.host=m.hostname,m.port=""),m.username=m.password="",m.auth&&(h=m.auth.split(":"),m.username=h[0]||"",m.password=h[1]||""),m.origin=m.protocol&&m.host&&"file:"!==m.protocol?m.protocol+"//"+m.host:"null",m.href=m.toString()}var s=t("requires-port"),u=t("./lolcation"),a=t("querystringify"),c=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,l=[["#","hash"],["?","query"],["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]];i.prototype.set=function(t,e,r){var n=this;switch(t){case"query":"string"==typeof e&&e.length&&(e=(r||a.parse)(e)),n[t]=e;break;case"port":n[t]=e,s(e,n.protocol)?e&&(n.host=n.hostname+":"+e):(n.host=n.hostname,n[t]="");break;case"hostname":n[t]=e,n.port&&(e+=":"+n.port),n.host=e;break;case"host":n[t]=e,/:\d+$/.test(e)?(e=e.split(":"),n.port=e.pop(),n.hostname=e.join(":")):(n.hostname=e,n.port="");break;case"protocol":n.protocol=e.toLowerCase(),n.slashes=!r;break;case"pathname":n.pathname=e.length&&"/"!==e.charAt(0)?"/"+e:e;break;default:n[t]=e}for(var o=0;o<l.length;o++){var i=l[o];i[4]&&(n[i[1]]=n[i[1]].toLowerCase())}return n.origin=n.protocol&&n.host&&"file:"!==n.protocol?n.protocol+"//"+n.host:"null",n.href=n.toString(),n},i.prototype.toString=function(t){t&&"function"==typeof t||(t=a.stringify);var e,r=this,n=r.protocol;n&&":"!==n.charAt(n.length-1)&&(n+=":");var o=n+(r.slashes?"//":"");return r.username&&(o+=r.username,r.password&&(o+=":"+r.password),o+="@"),o+=r.host+r.pathname,e="object"==typeof r.query?t(r.query):r.query,e&&(o+="?"!==e.charAt(0)?"?"+e:e),r.hash&&(o+=r.hash),o},i.extractProtocol=n,i.location=u,i.qs=a,e.exports=i},{"./lolcation":49,querystringify:43,"requires-port":44}],49:[function(t,e,r){(function(r){"use strict";var n,o=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,i={hash:1,query:1};e.exports=function(e){e=e||r.location||{},n=n||t("./");var s,u={},a=typeof e;if("blob:"===e.protocol)u=new n(unescape(e.pathname),{});else if("string"===a){u=new n(e,{});for(s in i)delete u[s]}else if("object"===a){for(s in e)s in i||(u[s]=e[s]);void 0===u.slashes&&(u.slashes=o.test(e.href))}return u}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./":48}],50:[function(t,e,r){var n=t("eventsource-polyfill/dist/eventsource");e.exports=window.EventSource||n.EventSource},{"eventsource-polyfill/dist/eventsource":51}],51:[function(t,e,r){!function(t){function e(t,e,r,n){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.data=e||null,this.origin=r||"",this.lastEventId=n||"",this.type=t||"message"}function r(){return!(!window.XDomainRequest||!window.XMLHttpRequest||void 0!==(new XMLHttpRequest).responseType)}if(!t.EventSource||t._eventSourceImportPrefix){var n=(t._eventSourceImportPrefix||"")+"EventSource",o=function(t,e){if(!t||"string"!=typeof t)throw new SyntaxError("Not enough arguments");this.URL=t,this.setOptions(e);var r=this;setTimeout(function(){r.poll()},0)};if(o.prototype={CONNECTING:0,OPEN:1,CLOSED:2,defaultOptions:{loggingEnabled:!1,loggingPrefix:"eventsource",interval:500,bufferSizeLimit:262144,silentTimeout:3e5,getArgs:{evs_buffer_size_limit:262144},xhrHeaders:{Accept:"text/event-stream","Cache-Control":"no-cache","X-Requested-With":"XMLHttpRequest"}},setOptions:function(t){var e,r=this.defaultOptions;for(e in r)r.hasOwnProperty(e)&&(this[e]=r[e]);for(e in t)e in r&&t.hasOwnProperty(e)&&(this[e]=t[e]);this.getArgs&&this.bufferSizeLimit&&(this.getArgs.evs_buffer_size_limit=this.bufferSizeLimit),"undefined"!=typeof console&&"undefined"!=typeof console.log||(this.loggingEnabled=!1)},log:function(t){this.loggingEnabled&&console.log("["+this.loggingPrefix+"]:"+t)},poll:function(){try{if(this.readyState==this.CLOSED)return;this.cleanup(),this.readyState=this.CONNECTING,this.cursor=0,this.cache="",this._xhr=new this.XHR(this),this.resetNoActivityTimer()}catch(t){this.log("There were errors inside the pool try-catch"),this.dispatchEvent("error",{type:"error",data:t.message})}},pollAgain:function(t){var e=this;e.readyState=e.CONNECTING,e.dispatchEvent("error",{type:"error",data:"Reconnecting "}),this._pollTimer=setTimeout(function(){e.poll()},t||0)},cleanup:function(){this.log("evs cleaning up"),this._pollTimer&&(clearInterval(this._pollTimer),this._pollTimer=null),this._noActivityTimer&&(clearInterval(this._noActivityTimer),this._noActivityTimer=null),this._xhr&&(this._xhr.abort(),this._xhr=null)},resetNoActivityTimer:function(){if(this.silentTimeout){this._noActivityTimer&&clearInterval(this._noActivityTimer);var t=this;this._noActivityTimer=setTimeout(function(){t.log("Timeout! silentTImeout:"+t.silentTimeout),t.pollAgain()},this.silentTimeout)}},close:function(){this.readyState=this.CLOSED,this.log("Closing connection. readyState: "+this.readyState),this.cleanup()},ondata:function(){var t=this._xhr;if(t.isReady()&&!t.hasError()){this.resetNoActivityTimer(),this.readyState==this.CONNECTING&&(this.readyState=this.OPEN,this.dispatchEvent("open",{type:"open"}));var e=t.getBuffer();e.length>this.bufferSizeLimit&&(this.log("buffer.length > this.bufferSizeLimit"),this.pollAgain()),0==this.cursor&&e.length>0&&"\ufeff"==e.substring(0,1)&&(this.cursor=1);var r=this.lastMessageIndex(e);if(r[0]>=this.cursor){var n=r[1],o=e.substring(this.cursor,n);this.parseStream(o),this.cursor=n}t.isDone()&&(this.log("request.isDone(). reopening the connection"),this.pollAgain(this.interval))}else this.readyState!==this.CLOSED&&(this.log("this.readyState !== this.CLOSED"),this.pollAgain(this.interval))},parseStream:function(t){t=this.cache+this.normalizeToLF(t);var r,n,o,i,s,u,a=t.split("\n\n");for(r=0;r<a.length-1;r++){for(o="message",i=[],parts=a[r].split("\n"),n=0;n<parts.length;n++)s=this.trimWhiteSpace(parts[n]),0==s.indexOf("event")?o=s.replace(/event:?\s*/,""):0==s.indexOf("retry")?(u=parseInt(s.replace(/retry:?\s*/,"")),isNaN(u)||(this.interval=u)):0==s.indexOf("data")?i.push(s.replace(/data:?\s*/,"")):0==s.indexOf("id:")?this.lastEventId=s.replace(/id:?\s*/,""):0==s.indexOf("id")&&(this.lastEventId=null);if(i.length){var c=new e(o,i.join("\n"),window.location.origin,this.lastEventId);this.dispatchEvent(o,c)}}this.cache=a[a.length-1]},dispatchEvent:function(t,e){var r=this["_"+t+"Handlers"];if(r)for(var n=0;n<r.length;n++)r[n].call(this,e);this["on"+t]&&this["on"+t].call(this,e)},addEventListener:function(t,e){this["_"+t+"Handlers"]||(this["_"+t+"Handlers"]=[]),this["_"+t+"Handlers"].push(e)},removeEventListener:function(t,e){var r=this["_"+t+"Handlers"];if(r)for(var n=r.length-1;n>=0;--n)if(r[n]===e){r.splice(n,1);break}},_pollTimer:null,_noactivityTimer:null,_xhr:null,lastEventId:null,cache:"",cursor:0,onerror:null,onmessage:null,onopen:null,readyState:0,urlWithParams:function(t,e){var r=[];if(e){var n,o,i=encodeURIComponent;for(n in e)e.hasOwnProperty(n)&&(o=i(n)+"="+i(e[n]),r.push(o))}return r.length>0?t.indexOf("?")==-1?t+"?"+r.join("&"):t+"&"+r.join("&"):t},lastMessageIndex:function(t){var e=t.lastIndexOf("\n\n"),r=t.lastIndexOf("\r\r"),n=t.lastIndexOf("\r\n\r\n");return n>Math.max(e,r)?[n,n+4]:[Math.max(e,r),Math.max(e,r)+2]},trimWhiteSpace:function(t){var e=/^(\s|\u00A0)+|(\s|\u00A0)+$/g;return t.replace(e,"")},normalizeToLF:function(t){return t.replace(/\r\n|\r/g,"\n")}},r()){o.isPolyfill="IE_8-9";var i=o.prototype.defaultOptions;i.xhrHeaders=null,i.getArgs.evs_preamble=2056,o.prototype.XHR=function(t){request=new XDomainRequest,this._request=request,request.onprogress=function(){request._ready=!0,t.ondata()},request.onload=function(){this._loaded=!0,t.ondata()},request.onerror=function(){this._failed=!0,t.readyState=t.CLOSED,t.dispatchEvent("error",{type:"error",data:"XDomainRequest error"})},request.ontimeout=function(){this._failed=!0,t.readyState=t.CLOSED,t.dispatchEvent("error",{type:"error",data:"XDomainRequest timed out"})};var e={};if(t.getArgs){var r=t.getArgs;for(var n in r)r.hasOwnProperty(n)&&(e[n]=r[n]);t.lastEventId&&(e.evs_last_event_id=t.lastEventId)}request.open("GET",t.urlWithParams(t.URL,e)),request.send()},o.prototype.XHR.prototype={useXDomainRequest:!0,_request:null,_ready:!1,_loaded:!1,_failed:!1,isReady:function(){return this._request._ready},isDone:function(){return this._request._loaded},hasError:function(){return this._request._failed},getBuffer:function(){var t="";try{t=this._request.responseText||""}catch(t){}return t},abort:function(){this._request&&this._request.abort()}}}else o.isPolyfill="XHR",o.prototype.XHR=function(t){request=new XMLHttpRequest,this._request=request,t._xhr=this,request.onreadystatechange=function(){request.readyState>1&&t.readyState!=t.CLOSED&&(200==request.status||request.status>=300&&request.status<400?t.ondata():(request._failed=!0,t.readyState=t.CLOSED,t.dispatchEvent("error",{type:"error",data:"The server responded with "+request.status}),t.close()))},request.onprogress=function(){},request.open("GET",t.urlWithParams(t.URL,t.getArgs),!0);var e=t.xhrHeaders;for(var r in e)e.hasOwnProperty(r)&&request.setRequestHeader(r,e[r]);t.lastEventId&&request.setRequestHeader("Last-Event-Id",t.lastEventId),request.send()},o.prototype.XHR.prototype={useXDomainRequest:!1,_request:null,_failed:!1,isReady:function(){return this._request.readyState>=2},isDone:function(){return 4==this._request.readyState},hasError:function(){return this._failed||this._request.status>=400},getBuffer:function(){var t="";try{t=this._request.responseText||""}catch(t){}return t},abort:function(){this._request&&this._request.abort()}};t[n]=o}}(this)},{}],52:[function(t,e,r){"use strict";function n(){i.apply(this,arguments)}var o=t("rxjs/Observable"),i=o.Observable,s=t("rxjs/operator/map"),u=s.map,a=t("rxjs/operator/filter"),c=a.filter,l=t("rxjs/operator/reduce"),f=l.reduce,p=t("rxjs/operator/toPromise"),h=p.toPromise,d=t("object-assign");n.prototype=Object.create(d(Object.create(null),i.prototype)),Object.defineProperty(n.prototype,"constructor",{value:n,enumerable:!1,writable:!0,configurable:!0}),n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.map=u,n.prototype.filter=c,n.prototype.reduce=f,n.prototype.toPromise=h,e.exports=n},{"object-assign":54,"rxjs/Observable":55,"rxjs/operator/filter":59,"rxjs/operator/map":60,"rxjs/operator/reduce":61,"rxjs/operator/toPromise":62}],53:[function(t,e,r){e.exports=t("./lib/SanityObservableMinimal")},{"./lib/SanityObservableMinimal":52}],54:[function(t,e,r){"use strict";function n(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function o(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;var n=Object.getOwnPropertyNames(e).map(function(t){return e[t]});if("0123456789"!==n.join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach(function(t){o[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(t){return!1}}var i=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,u=Object.prototype.propertyIsEnumerable;e.exports=o()?Object.assign:function(t,e){for(var r,o,a=n(t),c=1;c<arguments.length;c++){r=Object(arguments[c]);for(var l in r)s.call(r,l)&&(a[l]=r[l]);if(i){o=i(r);for(var f=0;f<o.length;f++)u.call(r,o[f])&&(a[o[f]]=r[o[f]])}}return a}},{}],55:[function(t,e,r){"use strict";var n=t("./util/root"),o=t("./util/toSubscriber"),i=t("./symbol/observable"),s=function(){function t(t){this._isScalar=!1,t&&(this._subscribe=t)}return t.prototype.lift=function(e){var r=new t;return r.source=this,r.operator=e,r},t.prototype.subscribe=function(t,e,r){var n=this.operator,i=o.toSubscriber(t,e,r);if(n?n.call(i,this.source):i.add(this._trySubscribe(i)),i.syncErrorThrowable&&(i.syncErrorThrowable=!1,i.syncErrorThrown))throw i.syncErrorValue;return i},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.syncErrorThrown=!0,t.syncErrorValue=e,t.error(e)}},t.prototype.forEach=function(t,e){var r=this;if(e||(n.root.Rx&&n.root.Rx.config&&n.root.Rx.config.Promise?e=n.root.Rx.config.Promise:n.root.Promise&&(e=n.root.Promise)),!e)throw new Error("no Promise impl found");return new e(function(e,n){var o=r.subscribe(function(e){if(o)try{t(e)}catch(t){n(t),o.unsubscribe()}else t(e)},n,e)})},t.prototype._subscribe=function(t){return this.source.subscribe(t)},t.prototype[i.$$observable]=function(){return this},t.create=function(e){return new t(e)},t}();r.Observable=s},{"./symbol/observable":63,"./util/root":70,"./util/toSubscriber":71}],56:[function(t,e,r){"use strict";r.empty={closed:!0,next:function(t){},error:function(t){throw t},complete:function(){}}},{}],57:[function(t,e,r){"use strict";var n=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},o=t("./util/isFunction"),i=t("./Subscription"),s=t("./Observer"),u=t("./symbol/rxSubscriber"),a=function(t){function e(r,n,o){switch(t.call(this),this.syncErrorValue=null,this.syncErrorThrown=!1,this.syncErrorThrowable=!1,this.isStopped=!1,arguments.length){case 0:this.destination=s.empty;break;case 1:if(!r){this.destination=s.empty;break}if("object"==typeof r){r instanceof e?(this.destination=r,this.destination.add(this)):(this.syncErrorThrowable=!0,this.destination=new c(this,r));break}default:this.syncErrorThrowable=!0,this.destination=new c(this,r,n,o)}}return n(e,t),e.prototype[u.$$rxSubscriber]=function(){return this},e.create=function(t,r,n){var o=new e(t,r,n);return o.syncErrorThrowable=!1,o},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this))},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){this.destination.error(t),this.unsubscribe()},e.prototype._complete=function(){this.destination.complete(),this.unsubscribe()},e.prototype._unsubscribeAndRecycle=function(){var t=this,e=t._parent,r=t._parents;return this._parent=null,this._parents=null,this.unsubscribe(),this.closed=!1,this.isStopped=!1,this._parent=e,this._parents=r,this},e}(i.Subscription);r.Subscriber=a;var c=function(t){function e(e,r,n,i){t.call(this),this._parentSubscriber=e;var s,u=this;o.isFunction(r)?s=r:r&&(u=r,s=r.next,n=r.error,i=r.complete,o.isFunction(u.unsubscribe)&&this.add(u.unsubscribe.bind(u)),u.unsubscribe=this.unsubscribe.bind(this)),this._context=u,this._next=s,this._error=n,this._complete=i}return n(e,t),e.prototype.next=function(t){if(!this.isStopped&&this._next){var e=this._parentSubscriber;e.syncErrorThrowable?this.__tryOrSetError(e,this._next,t)&&this.unsubscribe():this.__tryOrUnsub(this._next,t)}},e.prototype.error=function(t){if(!this.isStopped){var e=this._parentSubscriber;if(this._error)e.syncErrorThrowable?(this.__tryOrSetError(e,this._error,t),this.unsubscribe()):(this.__tryOrUnsub(this._error,t),this.unsubscribe());else{if(!e.syncErrorThrowable)throw this.unsubscribe(),t;e.syncErrorValue=t,e.syncErrorThrown=!0,this.unsubscribe()}}},e.prototype.complete=function(){if(!this.isStopped){var t=this._parentSubscriber;this._complete?t.syncErrorThrowable?(this.__tryOrSetError(t,this._complete),this.unsubscribe()):(this.__tryOrUnsub(this._complete),this.unsubscribe()):this.unsubscribe()}},e.prototype.__tryOrUnsub=function(t,e){try{t.call(this._context,e)}catch(t){throw this.unsubscribe(),t}},e.prototype.__tryOrSetError=function(t,e,r){try{e.call(this._context,r)}catch(e){return t.syncErrorValue=e,t.syncErrorThrown=!0,!0}return!1},e.prototype._unsubscribe=function(){var t=this._parentSubscriber;this._context=null,this._parentSubscriber=null,t.unsubscribe()},e}(a)},{"./Observer":56,"./Subscription":58,"./symbol/rxSubscriber":64,"./util/isFunction":68}],58:[function(t,e,r){"use strict";function n(t){return t.reduce(function(t,e){return t.concat(e instanceof c.UnsubscriptionError?e.errors:e)},[])}var o=t("./util/isArray"),i=t("./util/isObject"),s=t("./util/isFunction"),u=t("./util/tryCatch"),a=t("./util/errorObject"),c=t("./util/UnsubscriptionError"),l=function(){function t(t){this.closed=!1,this._parent=null,this._parents=null,this._subscriptions=null,t&&(this._unsubscribe=t)}return t.prototype.unsubscribe=function(){var t,e=!1;if(!this.closed){var r=this,l=r._parent,f=r._parents,p=r._unsubscribe,h=r._subscriptions;this.closed=!0,this._parent=null,this._parents=null,this._subscriptions=null;for(var d=-1,b=f?f.length:0;l;)l.remove(this),l=++d<b&&f[d]||null;if(s.isFunction(p)){var y=u.tryCatch(p).call(this);y===a.errorObject&&(e=!0,t=t||(a.errorObject.e instanceof c.UnsubscriptionError?n(a.errorObject.e.errors):[a.errorObject.e]))}if(o.isArray(h))for(d=-1,b=h.length;++d<b;){var v=h[d];if(i.isObject(v)){var y=u.tryCatch(v.unsubscribe).call(v);if(y===a.errorObject){e=!0,t=t||[];var m=a.errorObject.e;m instanceof c.UnsubscriptionError?t=t.concat(n(m.errors)):t.push(m)}}}if(e)throw new c.UnsubscriptionError(t)}},t.prototype.add=function(e){if(!e||e===t.EMPTY)return t.EMPTY;if(e===this)return this;var r=e;switch(typeof e){case"function":r=new t(e);case"object":if(r.closed||"function"!=typeof r.unsubscribe)return r;if(this.closed)return r.unsubscribe(),r;if("function"!=typeof r._addParent){var n=r;r=new t,r._subscriptions=[n]}break;default:throw new Error("unrecognized teardown "+e+" added to Subscription.")}var o=this._subscriptions||(this._subscriptions=[]);return o.push(r),r._addParent(this),r},t.prototype.remove=function(t){var e=this._subscriptions;if(e){var r=e.indexOf(t);r!==-1&&e.splice(r,1)}},t.prototype._addParent=function(t){var e=this,r=e._parent,n=e._parents;r&&r!==t?n?n.indexOf(t)===-1&&n.push(t):this._parents=[t]:this._parent=t},t.EMPTY=function(t){return t.closed=!0,t}(new t),t}();r.Subscription=l},{"./util/UnsubscriptionError":65,"./util/errorObject":66,"./util/isArray":67,"./util/isFunction":68,"./util/isObject":69,"./util/tryCatch":72}],59:[function(t,e,r){"use strict";function n(t,e){return this.lift(new s(t,e))}var o=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},i=t("../Subscriber");r.filter=n;var s=function(){function t(t,e){this.predicate=t,this.thisArg=e}return t.prototype.call=function(t,e){return e.subscribe(new u(t,this.predicate,this.thisArg))},t}(),u=function(t){function e(e,r,n){t.call(this,e),this.predicate=r,this.thisArg=n,this.count=0,this.predicate=r}return o(e,t),e.prototype._next=function(t){var e;try{e=this.predicate.call(this.thisArg,t,this.count++)}catch(t){return void this.destination.error(t)}e&&this.destination.next(t)},e}(i.Subscriber)},{"../Subscriber":57}],60:[function(t,e,r){"use strict";function n(t,e){if("function"!=typeof t)throw new TypeError("argument is not a function. Are you looking for `mapTo()`?");return this.lift(new s(t,e))}var o=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},i=t("../Subscriber");r.map=n;var s=function(){function t(t,e){this.project=t,this.thisArg=e}return t.prototype.call=function(t,e){return e.subscribe(new u(t,this.project,this.thisArg))},t}();r.MapOperator=s;var u=function(t){function e(e,r,n){t.call(this,e),this.project=r,this.count=0,this.thisArg=n||this}return o(e,t),e.prototype._next=function(t){var e;try{e=this.project.call(this.thisArg,t,this.count++)}catch(t){return void this.destination.error(t)}this.destination.next(e)},e}(i.Subscriber)},{"../Subscriber":57}],61:[function(t,e,r){"use strict";function n(t,e){var r=!1;return arguments.length>=2&&(r=!0),this.lift(new s(t,e,r))}var o=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},i=t("../Subscriber");r.reduce=n;var s=function(){function t(t,e,r){void 0===r&&(r=!1),this.accumulator=t,this.seed=e,this.hasSeed=r}return t.prototype.call=function(t,e){return e.subscribe(new u(t,this.accumulator,this.seed,this.hasSeed))},t}();r.ReduceOperator=s;var u=function(t){function e(e,r,n,o){t.call(this,e),this.accumulator=r,this.hasSeed=o,this.index=0,this.hasValue=!1,this.acc=n,this.hasSeed||this.index++}return o(e,t),e.prototype._next=function(t){this.hasValue||(this.hasValue=this.hasSeed)?this._tryReduce(t):(this.acc=t,this.hasValue=!0)},e.prototype._tryReduce=function(t){var e;try{e=this.accumulator(this.acc,t,this.index++)}catch(t){return void this.destination.error(t)}this.acc=e},e.prototype._complete=function(){(this.hasValue||this.hasSeed)&&this.destination.next(this.acc),this.destination.complete()},e}(i.Subscriber);r.ReduceSubscriber=u},{"../Subscriber":57}],62:[function(t,e,r){"use strict";function n(t){var e=this;if(t||(o.root.Rx&&o.root.Rx.config&&o.root.Rx.config.Promise?t=o.root.Rx.config.Promise:o.root.Promise&&(t=o.root.Promise)),!t)throw new Error("no Promise impl found");return new t(function(t,r){var n;e.subscribe(function(t){return n=t},function(t){return r(t)},function(){return t(n)})})}var o=t("../util/root");r.toPromise=n},{"../util/root":70}],63:[function(t,e,r){"use strict";function n(t){var e,r=t.Symbol;return"function"==typeof r?r.observable?e=r.observable:(e=r("observable"),r.observable=e):e="@@observable",e}var o=t("../util/root");r.getSymbolObservable=n,r.$$observable=n(o.root)},{"../util/root":70}],64:[function(t,e,r){"use strict";var n=t("../util/root"),o=n.root.Symbol;r.$$rxSubscriber="function"==typeof o&&"function"==typeof o.for?o.for("rxSubscriber"):"@@rxSubscriber"},{"../util/root":70}],65:[function(t,e,r){"use strict";var n=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},o=function(t){function e(e){t.call(this),this.errors=e;var r=Error.call(this,e?e.length+" errors occurred during unsubscription:\n "+e.map(function(t,e){return e+1+") "+t.toString()}).join("\n "):"");this.name=r.name="UnsubscriptionError",this.stack=r.stack,this.message=r.message}return n(e,t),e}(Error);r.UnsubscriptionError=o},{}],66:[function(t,e,r){"use strict";r.errorObject={e:{}}},{}],67:[function(t,e,r){"use strict";r.isArray=Array.isArray||function(t){return t&&"number"==typeof t.length}},{}],68:[function(t,e,r){"use strict";function n(t){return"function"==typeof t}r.isFunction=n},{}],69:[function(t,e,r){"use strict";function n(t){return null!=t&&"object"==typeof t}r.isObject=n},{}],70:[function(t,e,r){(function(t){"use strict";if(r.root="object"==typeof window&&window.window===window&&window||"object"==typeof self&&self.self===self&&self||"object"==typeof t&&t.global===t&&t,!r.root)throw new Error("RxJS could not find any global context (window, self, global)")}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],71:[function(t,e,r){"use strict";function n(t,e,r){if(t){if(t instanceof o.Subscriber)return t;if(t[i.$$rxSubscriber])return t[i.$$rxSubscriber]()}return t||e||r?new o.Subscriber(t,e,r):new o.Subscriber(s.empty)}var o=t("../Subscriber"),i=t("../symbol/rxSubscriber"),s=t("../Observer");r.toSubscriber=n},{"../Observer":56,"../Subscriber":57,"../symbol/rxSubscriber":64}],72:[function(t,e,r){"use strict";function n(){try{return i.apply(this,arguments)}catch(t){return s.errorObject.e=t,s.errorObject}}function o(t){return i=t,n}var i,s=t("./errorObject");r.tryCatch=o},{"./errorObject":66}]},{},[13])(13)});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.SanityClient=t()}}(function(){return function t(e,r,n){function o(s,u){if(!r[s]){if(!e[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[s]={exports:{}};e[s][0].call(l.exports,function(t){var r=e[s][1][t];return o(r?r:t)},l,l.exports,t,e,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(t,e,r){"use strict";function n(t){this.client=t}function o(t){return t.filter(function(t){return"response"===t.type}).map(function(t){return t.body}).toPromise()}var i=t("object-assign"),s=t("../validators");i(n.prototype,{upload:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};s.validateAssetType(t);var n=s.hasDataset(this.client.clientConfig),i="image"===t?"images":"files",u=this.client._requestObservable({method:"POST",timeout:r.timeout||0,query:r.label?{label:r.label}:{},url:"/assets/"+i+"/"+n,headers:r.contentType?{"Content-Type":r.contentType}:{},body:e});return this.client.isPromiseAPI()?o(u):u},delete:function(t,e){var r=t,n=e;t._type&&(r=t._type.replace(/(^sanity\.|Asset$)/g,""),n=t._id),s.validateAssetType(r),s.validateDocumentId("delete",n);var o="image"===r?"images":"files";return this.client.request({method:"DELETE",url:"/assets/"+o+"/"+n})}}),e.exports=n},{"../validators":19,"object-assign":42}],2:[function(t,e,r){"use strict";function n(t){this.client=t}var o=t("object-assign");o(n.prototype,{getLoginProviders:function(){return this.client.request({uri:"/auth/providers"})},logout:function(){return this.client.request({uri:"/auth/logout"})}}),e.exports=n},{"object-assign":42}],3:[function(t,e,r){"use strict";var n=t("object-assign"),o=t("./validators"),i=r.defaultConfig={apiHost:"https://api.sanity.io",useProjectHostname:!0,gradientMode:!1};r.initConfig=function(t,e){var r=n({},i,e,t),s=r.gradientMode,u=!s&&r.useProjectHostname;if("undefined"==typeof Promise)throw new Error("No native `Promise`-implementation found, polyfill needed");if(s&&!r.namespace)throw new Error("Configuration must contain `namespace` when running in gradient mode");if(u&&!r.projectId)throw new Error("Configuration must contain `projectId`");if(u&&o.projectId(r.projectId),!s&&r.dataset&&o.dataset(r.dataset,r.gradientMode),r.gradientMode)r.url=r.apiHost;else{var a=r.apiHost.split("://",2),c=a[0],l=a[1];r.useProjectHostname?r.url=c+"://"+r.projectId+"."+l+"/v1":r.url=r.apiHost+"/v1"}return r}},{"./validators":19,"object-assign":42}],4:[function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var o=t("object-assign"),i=t("../validators"),s=t("../util/getSelection"),u=t("./encodeQueryString"),a=t("./transaction"),c=t("./patch"),l=t("./listen"),f=function(t,e){var r="undefined"==typeof t?e:t;return t===!1?void 0:r},p=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{returnIds:!0,returnDocuments:f(t.returnDocuments,!0),visibility:t.visibility||"sync"}},h=function(t){return"response"===t.type},d=function(t){return t.body},b=function(t){return t.toPromise()},y=1948;e.exports={listen:l,getDataUrl:function(t,e){var r=this.clientConfig,n=r.gradientMode?r.namespace:i.hasDataset(r),o="/"+t+"/"+n,s=e?o+"/"+e:o;return(this.clientConfig.gradientMode?s:"/data"+s).replace(/\/($|\?)/,"$1")},fetch:function(t,e){var r=this._dataRequest("query",{query:t,params:e}).map(function(t){return t.result||[]});return this.isPromiseAPI()?b(r):r},getDocument:function(t){var e={uri:this.getDataUrl("doc",t),json:!0},r=this._requestObservable(e).filter(h).map(function(t){return t.body.documents&&t.body.documents[0]});return this.isPromiseAPI()?b(r):r},create:function(t,e){return this._create(t,"create",e)},createIfNotExists:function(t,e){return i.requireDocumentId("createIfNotExists",t),this._create(t,"createIfNotExists",e)},createOrReplace:function(t,e){return i.requireDocumentId("createOrReplace",t),this._create(t,"createOrReplace",e)},patch:function(t,e){return new c(t,e,this)},delete:function(t,e){return this.dataRequest("mutate",{mutations:[{delete:s(t)}]},e)},mutate:function(t,e){var r=t instanceof c?t.serialize():t,n=Array.isArray(r)?r:[r];return this.dataRequest("mutate",{mutations:n},e)},transaction:function(t){return new a(t,this)},dataRequest:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=this._dataRequest(t,e,r);return this.isPromiseAPI()?b(n):n},_dataRequest:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o="mutate"===t,i=!o&&u(e),s=!o&&i.length<y,a=s?i:"",c=r.returnFirst,l=this.getDataUrl(t,a),f={method:s?"GET":"POST",uri:l,json:!0,body:s?void 0:e,query:o&&p(r)};return this._requestObservable(f).filter(h).map(d).map(function(t){if(!o)return t;var e=t.results||[];if(r.returnDocuments)return c?e[0]&&e[0].document:e.map(function(t){return t.document});var i=c?"documentId":"documentIds",s=c?e[0]&&e[0].id:e.map(function(t){return t.id});return n({transactionId:t.transactionId,results:e},i,s)})},_create:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=n({},e,t),s=o({returnFirst:!0,returnDocuments:!0},r);return this.dataRequest("mutate",{mutations:[i]},s)}}},{"../util/getSelection":16,"../validators":19,"./encodeQueryString":5,"./listen":6,"./patch":7,"./transaction":8,"object-assign":42}],5:[function(t,e,r){"use strict";var n=encodeURIComponent;e.exports=function(t){var e=t.query,r=t.params,o=void 0===r?{}:r,i=t.options,s=void 0===i?{}:i,u=Object.keys(o).reduce(function(t,e){return t+"&"+n("$"+e)+"="+n(JSON.stringify(o[e]))},"?query="+n(e));return Object.keys(s).reduce(function(t,e){return s[e]?t+"&"+n(e)+"="+n(s[e]):t},u)}},{}],6:[function(t,e,r){"use strict";function n(t){try{var e=t.data&&JSON.parse(t.data)||{};return s({type:t.type},e)}catch(t){return t}}function o(t){if(t instanceof Error)return t;var e=n(t);return e instanceof Error?e:new Error(i(e))}function i(t){return t.error?t.error.description?t.error.description:"string"==typeof t.error?t.error:JSON.stringify(t.error,null,2):t.message||"Unknown listener error"}var s=t("object-assign"),u=t("@sanity/observable/minimal"),a=t("./encodeQueryString"),c=t("../util/pick"),l=t("../util/defaults"),f="undefined"!=typeof window&&window.EventSource?window.EventSource:t("@sanity/eventsource"),p=function(t,e,r){t.removeEventListener?t.removeEventListener(e,r,!1):t.removeListener(e,r)},h=["includePreviousRevision","includeResult"],d={includeResult:!0};e.exports=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=l(r,d),b=c(i,h),y=a({query:t,params:e,options:b}),v=""+this.clientConfig.url+this.getDataUrl("listen",y),m=this.clientConfig.token,g=i.events?i.events:["mutation"],w=g.indexOf("reconnect")!==-1,O=new f(v,s({withCredentials:!0},m?{headers:{"Sanity-Token":m}}:{}));return new u(function(t){function e(){O.readyState===f.CLOSED?t.complete():O.readyState===f.CONNECTING&&a()}function r(e){t.error(o(e))}function i(e){var r=n(e);return r instanceof Error?t.error(r):t.next(r)}function s(e){t.complete(),u()}function u(){g.forEach(function(t){return p(O,t,i)}),p(O,"error",e),p(O,"channelError",r),p(O,"disconnect",s),O.close()}function a(){w&&t.next({type:"reconnect"})}return O.addEventListener("error",e,!1),O.addEventListener("channelError",r,!1),O.addEventListener("disconnect",s,!1),g.forEach(function(t){return O.addEventListener(t,i,!1)}),u})}},{"../util/defaults":15,"../util/pick":18,"./encodeQueryString":5,"@sanity/eventsource":51,"@sanity/observable/minimal":54,"object-assign":42}],7:[function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.selection=t,this.operations=s({},e),this.client=r}var i=t("deep-assign"),s=t("object-assign"),u=t("../util/getSelection"),a=t("../validators"),c=a.validateObject,l=a.validateInsert;s(o.prototype,{clone:function(){return new o(this.selection,s({},this.operations),this.client)},merge:function(t){return c("merge",t),this._assign("merge",i(this.operations.merge||{},t))},set:function(t){return this._assign("set",t)},diffMatchPatch:function(t){return c("diffMatchPatch",t),this._assign("diffMatchPatch",t)},unset:function(t){if(!Array.isArray(t))throw new Error("unset(attrs) takes an array of attributes to unset, non-array given");return this.operations=s({},this.operations,{unset:t}),this},setIfMissing:function(t){return this._assign("setIfMissing",t)},replace:function(t){return c("replace",t),this._set("set",{$:t})},inc:function(t){return this._assign("inc",t)},dec:function(t){return this._assign("dec",t)},insert:function(t,e,r){var o;return l(t,e,r),this._assign("insert",(o={},n(o,t,e),n(o,"items",r),o))},append:function(t,e){return this.insert("after",t+"[-1]",e)},prepend:function(t,e){return this.insert("before",t+"[0]",e)},splice:function(t,e,r,n){var o="undefined"==typeof r||r===-1,i=e<0?e-1:e,s=o?-1:Math.max(0,e+r),u=i<0&&s>=0?"":s,a=t+"["+i+":"+u+"]";return this.insert("replace",a,n||[])},serialize:function(){return s(u(this.selection),this.operations)},toJSON:function(){return this.serialize()},commit:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.client)throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");var e="string"==typeof this.selection,r=s({returnFirst:e,returnDocuments:!0},t);return this.client.mutate({patch:this.serialize()},r)},reset:function(){return this.operations={},this},_set:function(t,e){return this._assign(t,e,!1)},_assign:function(t,e){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return c(t,e),this.operations=s({},this.operations,n({},t,s({},r&&this.operations[t]||{},e))),this}}),e.exports=o},{"../util/getSelection":16,"../validators":19,"deep-assign":22,"object-assign":42}],8:[function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments[1];this.operations=t,this.client=e}var i=t("object-assign"),s=t("../validators"),u=t("./patch"),a={returnDocuments:!1};i(o.prototype,{clone:function(){return new o(this.operations.slice(0),this.client)},create:function(t){return s.validateObject("create",t),this._add({create:t})},createIfNotExists:function(t){var e="createIfNotExists";return s.validateObject(e,t),s.requireDocumentId(e,t),this._add(n({},e,t))},createOrReplace:function(t){var e="createOrReplace";return s.validateObject(e,t),s.requireDocumentId(e,t),this._add(n({},e,t))},delete:function(t){return s.validateDocumentId("delete",t),this._add({delete:{id:t}})},patch:function t(e,r){var n="function"==typeof r,o=e instanceof u;if(o)return this._add({patch:e.serialize()});if(n){var t=r(new u(e,{},this.client));if(!(t instanceof u))throw new Error("function passed to `patch()` must return the patch");return this._add({patch:t.serialize()})}return this._add({patch:i({id:e},r)})},serialize:function(){return this.operations.slice()},toJSON:function(){return this.serialize()},commit:function(t){if(!this.client)throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");return this.client.mutate(this.serialize(),t||a)},reset:function(){return this.operations=[],this},_add:function(t){return this.operations.push(t),this}}),e.exports=o},{"../validators":19,"./patch":7,"object-assign":42}],9:[function(t,e,r){"use strict";function n(t){this.request=t.request.bind(t)}var o=t("object-assign"),i=t("../validators");o(n.prototype,{create:function(t){return this._modify("PUT",t)},delete:function(t){return this._modify("DELETE",t)},list:function(){return this.request({uri:"/datasets"})},_modify:function(t,e){return i.dataset(e),this.request({method:t,uri:"/datasets/"+e})}}),e.exports=n},{"../validators":19,"object-assign":42}],10:[function(t,e,r){"use strict";function n(t,e,r){return!!p.shouldRetry(t)||("HEAD"===r.method||"GET"===r.method)&&t.response&&t.response.statusCode>=500}function o(t){var e=t.body;return this.response=t,this.statusCode=t.statusCode,this.responseBody=s(e,t),e.error&&e.message?void(this.message=e.error+" - "+e.message):e.error&&e.error.description?(this.message=e.error.description,void(this.details=e.error)):void(this.message=e.error||e.message||i(t))}function i(t){var e=t.statusMessage?" "+t.statusMessage:"";return t.method+"-request to "+t.url+" resulted in HTTP "+t.statusCode+e}function s(t,e){var r=(e.headers["content-type"]||"").toLowerCase(),n=r.indexOf("application/json")!==-1;return n?JSON.stringify(t,null,2):t}function u(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:O;return e(c({maxRedirects:0},t))}var a=t("get-it"),c=t("object-assign"),l=t("create-error-class"),f=t("get-it/lib/middleware/observable"),p=t("get-it/lib/middleware/retry"),h=t("get-it/lib/middleware/jsonRequest"),d=t("get-it/lib/middleware/jsonResponse"),b=t("@sanity/observable/minimal"),y=t("get-it/lib/middleware/progress"),v=l("ClientError",o),m=l("ServerError",o),g={onResponse:function(t){if(t.statusCode>=500)throw new m(t);if(t.statusCode>=400)throw new v(t);return t}},w=[h(),d(),y(),g,f({implementation:b}),p({maxRetries:5,shouldRetry:n})],O=a(w);u.defaultRequester=O,e.exports=u},{"@sanity/observable/minimal":54,"create-error-class":21,"get-it":24,"get-it/lib/middleware/jsonRequest":26,"get-it/lib/middleware/jsonResponse":27,"get-it/lib/middleware/observable":28,"get-it/lib/middleware/progress":30,"get-it/lib/middleware/retry":31,"object-assign":42}],11:[function(t,e,r){"use strict";var n="Sanity-Token",o="Sanity-Project-ID";e.exports=function(t){var e={};return t.token&&t.gradientMode?e.Authorization="Bearer "+t.token:t.token&&(e[n]=t.token),!t.useProjectHostname&&t.projectId&&(e[o]=t.projectId),{headers:e,timeout:"timeout"in t?t.timeout:3e4,withCredentials:!0,json:!0}}},{}],12:[function(t,e,r){"use strict";function n(t){this.client=t}var o=t("object-assign");o(n.prototype,{list:function(){return this.client.request({uri:"/projects"})},getById:function(t){return this.client.request({uri:"/projects/"+t})}}),e.exports=n},{"object-assign":42}],13:[function(t,e,r){"use strict";function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:g;this.config(t),this.assets=new p(this),this.datasets=new l(this),this.projects=new f(this),this.users=new h(this),this.auth=new d(this),t.isPromiseAPI&&(this.observable=new n(v(t,["isPromiseAPI"])))}function o(){for(var t=arguments.length,e=Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=e.reduce(function(t,e){return t||e.headers?s(t||{},e.headers||{}):null},null);return s.apply(void 0,e.concat([n?{headers:n}:{}]))}function i(t){return new n(s({},t,{isPromiseAPI:!0}))}var s=t("object-assign"),u=t("./data/patch"),a=t("./data/transaction"),c=t("./data/dataMethods"),l=t("./datasets/datasetsClient"),f=t("./projects/projectsClient"),p=t("./assets/assetsClient"),h=t("./users/usersClient"),d=t("./auth/authClient"),b=t("./http/request"),y=t("./http/requestOptions"),v=t("./util/omit"),m=t("./config"),g=m.defaultConfig,w=m.initConfig,O=function(t){return t.toPromise()};s(n.prototype,c),s(n.prototype,{clone:function(){return new n(this.config())},config:function(t){return"undefined"==typeof t?s({},this.clientConfig):(this.observable&&this.observable.config(v(t,["isPromiseAPI"])),this.clientConfig=w(t,this.clientConfig||{}),this)},getUrl:function(t){return this.clientConfig.url+"/"+t.replace(/^\//,"")},isPromiseAPI:function(){return this.clientConfig.isPromiseAPI},_requestObservable:function(t){return b(o(y(this.clientConfig),t,{url:this.getUrl(t.url||t.uri)}),this.clientConfig.requester)},request:function(t){var e=this._requestObservable(t).filter(function(t){return"response"===t.type}).map(function(t){return t.body});return this.isPromiseAPI()?O(e):e}}),i.Patch=u,i.Transaction=a,i.requester=b.defaultRequester,e.exports=i},{"./assets/assetsClient":1,"./auth/authClient":2,"./config":3,"./data/dataMethods":4,"./data/patch":7,"./data/transaction":8,"./datasets/datasetsClient":9,"./http/request":10,"./http/requestOptions":11,"./projects/projectsClient":12,"./users/usersClient":14,"./util/omit":17,"object-assign":42}],14:[function(t,e,r){"use strict";function n(t){this.client=t}var o=t("object-assign");o(n.prototype,{getById:function(t){return this.client.request({uri:"/users/"+t})}}),e.exports=n},{"object-assign":42}],15:[function(t,e,r){"use strict";e.exports=function(t,e){return Object.keys(e).concat(Object.keys(t)).reduce(function(r,n){return r[n]="undefined"==typeof t[n]?e[n]:t[n],r},{})}},{}],16:[function(t,e,r){"use strict";e.exports=function(t){if("string"==typeof t||Array.isArray(t))return{id:t};if(t&&t.query)return{query:t.query};var e=["* Document ID (<docId>)","* Array of document IDs","* Object containing `query`"].join("\n");throw new Error("Unknown selection - must be one of:\n\n"+e)}},{}],17:[function(t,e,r){"use strict";e.exports=function(t,e){return Object.keys(t).reduce(function(r,n){return e.indexOf(n)!==-1?r:(r[n]=t[n],r)},{})}},{}],18:[function(t,e,r){"use strict";e.exports=function(t,e){return e.reduce(function(e,r){return"undefined"==typeof t[r]?e:(e[r]=t[r],e)},{})}},{}],19:[function(t,e,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=["image","file"],i=["before","after","replace"];r.dataset=function(t){if(!/^[-\w]{1,128}$/.test(t))throw new Error("Datasets can only contain lowercase characters, numbers, underscores and dashes")},r.projectId=function(t){if(!/^[-a-z0-9]+$/i.test(t))throw new Error("`projectId` can only contain only a-z, 0-9 and dashes")},r.validateAssetType=function(t){if(o.indexOf(t)===-1)throw new Error("Invalid asset type: "+t+". Must be one of "+o.join(", "))},r.validateObject=function(t,e){if(null===e||"object"!==("undefined"==typeof e?"undefined":n(e))||Array.isArray(e))throw new Error(t+"() takes an object of properties")},r.requireDocumentId=function(t,e){if(!e._id)throw new Error(t+'() requires that the document contains an ID ("_id" property)');r.validateDocumentId(t,e._id)},r.validateDocumentId=function(t,e){if("string"!=typeof e||!/^[a-z0-9_.-]+$/i.test(e))throw new Error(t+'(): "'+e+'" is not a valid document ID')},r.validateInsert=function(t,e,r){var n="insert(at, selector, items)";if(i.indexOf(t)===-1){var o=i.map(function(t){return'"'+t+'"'}).join(", ");throw new Error(n+' takes an "at"-argument which is one of: '+o)}if("string"!=typeof e)throw new Error(n+' takes a "selector"-argument which must be a string');if(!Array.isArray(r))throw new Error(n+' takes an "items"-argument which must be an array')},r.hasDataset=function(t){if(!t.gradientMode&&!t.dataset)throw new Error("`dataset` must be provided to perform queries");return t.dataset||""}},{}],20:[function(t,e,r){"use strict";e.exports=Error.captureStackTrace||function(t){var e=new Error;Object.defineProperty(t,"stack",{configurable:!0,get:function(){var t=e.stack;return Object.defineProperty(this,"stack",{value:t}),t}})}},{}],21:[function(t,e,r){"use strict";function n(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}var o=t("capture-stack-trace");e.exports=function(t,e){if("string"!=typeof t)throw new TypeError("Expected className to be a string");if(/[^0-9a-zA-Z_$]/.test(t))throw new Error("className contains invalid characters");e=e||function(t){this.message=t};var r=function(){Object.defineProperty(this,"name",{configurable:!0,value:t,writable:!0}),o(this,this.constructor),e.apply(this,arguments)};return n(r,Error),r}},{"capture-stack-trace":20}],22:[function(t,e,r){"use strict";function n(t){if(null===t||void 0===t)throw new TypeError("Sources cannot be null or undefined");return Object(t)}function o(t,e,r){var n=e[r];if(void 0!==n&&null!==n){if(u.call(t,r)&&(void 0===t[r]||null===t[r]))throw new TypeError("Cannot convert undefined or null to object ("+r+")");u.call(t,r)&&s(n)?t[r]=i(Object(t[r]),e[r]):t[r]=n}}function i(t,e){if(t===e)return t;e=Object(e);for(var r in e)u.call(e,r)&&o(t,e,r);if(Object.getOwnPropertySymbols)for(var n=Object.getOwnPropertySymbols(e),i=0;i<n.length;i++)a.call(e,n[i])&&o(t,e,n[i]);return t}var s=t("is-obj"),u=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;e.exports=function(t){t=n(t);for(var e=1;e<arguments.length;e++)i(t,arguments[e]);return t}},{"is-obj":38}],23:[function(t,e,r){function n(t,e,r){if(!u(e))throw new TypeError("iterator must be a function");arguments.length<3&&(r=this),"[object Array]"===a.call(t)?o(t,e,r):"string"==typeof t?i(t,e,r):s(t,e,r)}function o(t,e,r){for(var n=0,o=t.length;n<o;n++)c.call(t,n)&&e.call(r,t[n],n,t)}function i(t,e,r){for(var n=0,o=t.length;n<o;n++)e.call(r,t.charAt(n),n,t)}function s(t,e,r){for(var n in t)c.call(t,n)&&e.call(r,t[n],n,t)}var u=t("is-function");e.exports=n;var a=Object.prototype.toString,c=Object.prototype.hasOwnProperty},{"is-function":37}],24:[function(t,e,r){"use strict";var n=t("nano-pubsub"),o=t("./util/middlewareReducer"),i=t("./middleware/defaultOptionsProcessor"),s=t("./request"),u=["request","response","progress","error","abort"],a=["processOptions","onRequest","onResponse","onError","onReturn","onHeaders"];e.exports=function t(){function e(t){function e(t,e,n){var o=t,s=e;if(!o)try{s=i("onResponse",e,n)}catch(t){s=null,o=t}o=o&&i("onError",o,n),o?r.error.publish(o):s&&r.response.publish(s)}var r=u.reduce(function(t,e){return t[e]=n(),t},{}),i=o(l),a=i("processOptions",t),c={options:a,channels:r,applyMiddleware:i},f=null,p=r.request.subscribe(function(t){f=s(t,function(r,n){return e(r,n,t)})});r.abort.subscribe(function(){p(),f&&f.abort()});var h=i("onReturn",r,c);return h===r&&r.request.publish(c),h}var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],c=[],l=a.reduce(function(t,e){return t[e]=t[e]||[],t},{processOptions:[i]});return e.use=function(t){if(!t)throw new Error("Tried to add middleware that resolved to falsey value");if("function"==typeof t)throw new Error("Tried to add middleware that was a function. It probably expects you to pass options to it.");if(t.onReturn&&l.onReturn.length>0)throw new Error("Tried to add new middleware with `onReturn` handler, but another handler has already been registered for this event");a.forEach(function(e){t[e]&&l[e].push(t[e])}),c.push(t)},e.clone=function(){return t(c)},r.forEach(e.use),e}},{"./middleware/defaultOptionsProcessor":25,"./request":33,"./util/middlewareReducer":36,"nano-pubsub":41}],25:[function(t,e,r){"use strict";function n(t){if(t===!1||0===t)return!1;if(t.connect||t.socket)return t;var e=Number(t);return isNaN(e)?n(u.timeout):{connect:e,socket:e}}function o(t){var e={};for(var r in t)void 0!==t[r]&&(e[r]=t[r]);return e}var i=t("object-assign"),s=t("url-parse"),u={timeout:12e4};e.exports=function(t){var e="string"==typeof t?i({url:t},u):i({},u,t),r=s(e.url,{},!0);return e.timeout=n(e.timeout),e.query&&(r.query=i({},r.query,o(e.query))),e.method=e.body&&!e.method?"POST":(e.method||"GET").toUpperCase(),e.url=r.toString(),e}},{"object-assign":42,"url-parse":49}],26:[function(t,e,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=t("object-assign"),i=t("is-plain-object"),s=["boolean","string","number"],u=function(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)};e.exports=function(){return{processOptions:function(t){var e=t.body,r=e&&!u(e)&&(s.indexOf("undefined"==typeof e?"undefined":n(e))!==-1||Array.isArray(e)||i(e)||e&&"function"==typeof e.toJSON);return r?o({},t,{body:JSON.stringify(t.body),headers:o({},t.headers,{"Content-Type":"application/json"})}):t}}}},{"is-plain-object":39,"object-assign":42}],27:[function(t,e,r){"use strict";function n(t){try{return JSON.parse(t)}catch(t){throw t.message="Failed to parsed response body as JSON: "+t.message,t}}var o=t("object-assign");e.exports=function(){return{onResponse:function(t){var e=t.headers["content-type"];return t.body&&e&&e.indexOf("application/json")!==-1?o({},t,{body:n(t.body)}):t},processOptions:function(t){return o({},t,{headers:o({Accept:"application/json"},t.headers)})}}}},{"object-assign":42}],28:[function(t,e,r){"use strict";var n=t("../util/global"),o=t("object-assign");e.exports=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.implementation||n.Observable;if(!e)throw new Error("`Observable` is not available in global scope, and no implementation was passed");return{onReturn:function(t,r){return new e(function(e){return t.error.subscribe(function(t){return e.error(t)}),t.progress.subscribe(function(t){return e.next(o({type:"progress"},t))}),t.response.subscribe(function(t){e.next(o({type:"response"},t)),e.complete()}),t.request.publish(r),function(){return t.abort.publish()}})}}}},{"../util/global":35,"object-assign":42}],29:[function(t,e,r){"use strict";e.exports=function(){return{onRequest:function(t){function e(t){return function(e){var r=e.lengthComputable?e.loaded/e.total*100:-1;n.channels.progress.publish({stage:t,percent:r,total:e.total,loaded:e.loaded,lengthComputable:e.lengthComputable})}}if("xhr"===t.adapter){var r=t.request,n=t.context;"upload"in r&&"onprogress"in r.upload&&(r.upload.onprogress=e("upload")),"onprogress"in r&&(r.onprogress=e("download"))}}}}},{}],30:[function(t,e,r){"use strict";e.exports=t("./node-progress")},{"./node-progress":29}],31:[function(t,e,r){"use strict";function n(t){return 100*Math.pow(2,t)+100*Math.random()}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=t("object-assign"),s=t("../util/node-shouldRetry"),u=function(t){return null!==t&&"object"===("undefined"==typeof t?"undefined":o(t))&&"function"==typeof t.pipe},a=e.exports=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.maxRetries||5,r=t.retryDelay||n,o=t.shouldRetry||s;return{onError:function(t,n){var s=n.options,a=s.maxRetries||e,c=s.shouldRetry||o,l=s.attemptNumber||0;if(u(s.body))return t;if(!c(t,l,s)||l>=a)return t;var f=i({},n,{options:i({},s,{attemptNumber:l+1})});return setTimeout(function(){return n.channels.request.publish(f)},r(l)),null}}};a.shouldRetry=s},{"../util/node-shouldRetry":34,"object-assign":42}],32:[function(t,e,r){"use strict";var n=t("same-origin"),o=t("parse-headers"),i=function(){},s=window,u=s.XMLHttpRequest||i,a="withCredentials"in new u,c=a?u:s.XDomainRequest,l="xhr";e.exports=function(t,e){function r(){O=!0,m.abort()}function i(e){_=!0,m.abort();var r=new Error("ESOCKETTIMEDOUT"===e?"Socket timed out on request to "+b.url:"Connection timed out on request to "+b.url);r.code=e,t.channels.error.publish(r)}function a(){S&&(f(),v.socket=setTimeout(function(){return i("ESOCKETTIMEDOUT")},S.socket))}function f(){(O||m.readyState>=2&&v.connect)&&clearTimeout(v.connect),v.socket&&clearTimeout(v.socket)}function p(){if(!j){f(),j=!0,m=null;var t=new Error("Network error while attempting to reach "+b.url);t.isNetworkError=!0,t.request=b,e(t)}}function h(){var t=m.status,e=m.statusText;if(g&&void 0===t)t=200;else{if(t>12e3&&t<12156)return p();t=1223===m.status?204:m.status,e=1223===m.status?"No Content":e}return{body:m.response||m.responseText,url:b.url,method:b.method,headers:g?{}:o(m.getAllResponseHeaders()),statusCode:t,statusMessage:e}}function d(){if(!(O||j||_)){if(0===m.status)return void p(new Error("Unknown XHR error"));f(),j=!0,e(null,h())}}var b=t.options,y=!n(s.location.href,b.url),v={},m=y?new c:new u,g=s.XDomainRequest&&m instanceof s.XDomainRequest,w=b.headers,O=!1,j=!1,_=!1;m.onerror=p,m.ontimeout=p,m.onabort=function(){O=!0},m.onprogress=function(){};var x=g?"onload":"onreadystatechange";if(m[x]=function(){a(),O||4!==m.readyState&&!g||0!==m.status&&d()},m.open(b.method,b.url,!0),m.withCredentials=!!b.withCredentials,w&&m.setRequestHeader)for(var E in w)w.hasOwnProperty(E)&&m.setRequestHeader(E,w[E]);else if(w&&g)throw new Error("Headers cannot be set on an XDomainRequest object");b.rawBody&&(m.responseType="arraybuffer"),t.applyMiddleware("onRequest",{options:b,adapter:l,request:m,context:t}),m.send(b.body||null);var S=b.timeout;return S&&(v.connect=setTimeout(function(){return i("ETIMEDOUT")},S.connect)),{abort:r}}},{"parse-headers":43,"same-origin":46}],33:[function(t,e,r){"use strict";e.exports=t("./node-request")},{"./node-request":32}],34:[function(t,e,r){"use strict";e.exports=function(t){return t.isNetworkError||!1}},{}],35:[function(t,e,r){(function(t){"use strict";"undefined"!=typeof window?e.exports=window:"undefined"!=typeof t?e.exports=t:"undefined"!=typeof self?e.exports=self:e.exports={}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],36:[function(t,e,r){"use strict";e.exports=function(t){var e=function(e,r){for(var n=arguments.length,o=Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];return t[e].reduce(function(t,e){return e.apply(void 0,[t].concat(o))},r)};return e}},{}],37:[function(t,e,r){function n(t){var e=o.call(t);return"[object Function]"===e||"function"==typeof t&&"[object RegExp]"!==e||"undefined"!=typeof window&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)}e.exports=n;var o=Object.prototype.toString},{}],38:[function(t,e,r){"use strict";e.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}},{}],39:[function(t,e,r){"use strict";function n(t){return o(t)===!0&&"[object Object]"===Object.prototype.toString.call(t)}var o=t("isobject");e.exports=function(t){var e,r;return n(t)!==!1&&(e=t.constructor,"function"==typeof e&&(r=e.prototype,n(r)!==!1&&r.hasOwnProperty("isPrototypeOf")!==!1))}},{isobject:40}],40:[function(t,e,r){"use strict";e.exports=function(t){return null!=t&&"object"==typeof t&&!Array.isArray(t)}},{}],41:[function(t,e,r){e.exports=function(){function t(t){return r.push(t),function(){var e=r.indexOf(t);e>-1&&r.splice(e,1)}}function e(){for(var t=0;t<r.length;t++)r[t].apply(null,arguments)}var r=[];return{subscribe:t,publish:e}}},{}],42:[function(t,e,r){"use strict";function n(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function o(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;var n=Object.getOwnPropertyNames(e).map(function(t){return e[t]});if("0123456789"!==n.join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach(function(t){o[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(t){return!1}}var i=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,u=Object.prototype.propertyIsEnumerable;e.exports=o()?Object.assign:function(t,e){for(var r,o,a=n(t),c=1;c<arguments.length;c++){r=Object(arguments[c]);for(var l in r)s.call(r,l)&&(a[l]=r[l]);if(i){o=i(r);for(var f=0;f<o.length;f++)u.call(r,o[f])&&(a[o[f]]=r[o[f]]);
}}return a}},{}],43:[function(t,e,r){var n=t("trim"),o=t("for-each"),i=function(t){return"[object Array]"===Object.prototype.toString.call(t)};e.exports=function(t){if(!t)return{};var e={};return o(n(t).split("\n"),function(t){var r=t.indexOf(":"),o=n(t.slice(0,r)).toLowerCase(),s=n(t.slice(r+1));"undefined"==typeof e[o]?e[o]=s:i(e[o])?e[o].push(s):e[o]=[e[o],s]}),e}},{"for-each":23,trim:48}],44:[function(t,e,r){"use strict";function n(t){for(var e,r=/([^=?&]+)=?([^&]*)/g,n={};e=r.exec(t);n[decodeURIComponent(e[1])]=decodeURIComponent(e[2]));return n}function o(t,e){e=e||"";var r=[];"string"!=typeof e&&(e="?");for(var n in t)i.call(t,n)&&r.push(encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return r.length?e+r.join("&"):""}var i=Object.prototype.hasOwnProperty;r.stringify=o,r.parse=n},{}],45:[function(t,e,r){"use strict";e.exports=function(t,e){if(e=e.split(":")[0],t=+t,!t)return!1;switch(e){case"http":case"ws":return 80!==t;case"https":case"wss":return 443!==t;case"ftp":return 21!==t;case"gopher":return 70!==t;case"file":return!1}return 0!==t}},{}],46:[function(t,e,r){"use strict";var n=t("url");e.exports=function(t,e,r){if(t===e)return!0;var o=n.parse(t,!1,!0),i=n.parse(e,!1,!0),s=0|o.port||("https"===o.protocol?443:80),u=0|i.port||("https"===i.protocol?443:80),a={proto:o.protocol===i.protocol,hostname:o.hostname===i.hostname,port:s===u};return a.proto&&a.hostname&&(a.port||r)}},{url:47}],47:[function(t,e,r){"use strict";var n=/^(?:(?:(?:([^:\/#\?]+:)?(?:(?:\/\/)((?:((?:[^:@\/#\?]+)(?:\:(?:[^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((?:\/?(?:[^\/\?#]+\/+)*)(?:[^\?#]*)))?(\?[^#]+)?)(#.*)?/;e.exports={regex:n,parse:function(t){var e=n.exec(t);return e?{protocol:(e[1]||"").toLowerCase()||void 0,hostname:(e[5]||"").toLowerCase()||void 0,port:e[6]||void 0}:{}}}},{}],48:[function(t,e,r){function n(t){return t.replace(/^\s*|\s*$/g,"")}r=e.exports=n,r.left=function(t){return t.replace(/^\s*/,"")},r.right=function(t){return t.replace(/\s*$/,"")}},{}],49:[function(t,e,r){"use strict";function n(t){var e=f.exec(t);return{protocol:e[1]?e[1].toLowerCase():"",slashes:!!e[2],rest:e[3]}}function o(t,e){for(var r=(e||"/").split("/").slice(0,-1).concat(t.split("/")),n=r.length,o=r[n-1],i=!1,s=0;n--;)"."===r[n]?r.splice(n,1):".."===r[n]?(r.splice(n,1),s++):s&&(0===n&&(i=!0),r.splice(n,1),s--);return i&&r.unshift(""),"."!==o&&".."!==o||r.push(""),r.join("/")}function i(t,e,r){if(!(this instanceof i))return new i(t,e,r);var s,u,f,h,d,b,y=p.slice(),v=typeof e,m=this,g=0;for("object"!==v&&"string"!==v&&(r=e,e=null),r&&"function"!=typeof r&&(r=l.parse),e=c(e),u=n(t||""),s=!u.protocol&&!u.slashes,m.slashes=u.slashes||s&&e.slashes,m.protocol=u.protocol||e.protocol||"",t=u.rest,u.slashes||(y[2]=[/(.*)/,"pathname"]);g<y.length;g++)h=y[g],f=h[0],b=h[1],f!==f?m[b]=t:"string"==typeof f?~(d=t.indexOf(f))&&("number"==typeof h[2]?(m[b]=t.slice(0,d),t=t.slice(d+h[2])):(m[b]=t.slice(d),t=t.slice(0,d))):(d=f.exec(t))&&(m[b]=d[1],t=t.slice(0,d.index)),m[b]=m[b]||(s&&h[3]?e[b]||"":""),h[4]&&(m[b]=m[b].toLowerCase());r&&(m.query=r(m.query)),s&&e.slashes&&"/"!==m.pathname.charAt(0)&&(""!==m.pathname||""!==e.pathname)&&(m.pathname=o(m.pathname,e.pathname)),a(m.port,m.protocol)||(m.host=m.hostname,m.port=""),m.username=m.password="",m.auth&&(h=m.auth.split(":"),m.username=h[0]||"",m.password=h[1]||""),m.origin=m.protocol&&m.host&&"file:"!==m.protocol?m.protocol+"//"+m.host:"null",m.href=m.toString()}function s(t,e,r){var n=this;switch(t){case"query":"string"==typeof e&&e.length&&(e=(r||l.parse)(e)),n[t]=e;break;case"port":n[t]=e,a(e,n.protocol)?e&&(n.host=n.hostname+":"+e):(n.host=n.hostname,n[t]="");break;case"hostname":n[t]=e,n.port&&(e+=":"+n.port),n.host=e;break;case"host":n[t]=e,/:\d+$/.test(e)?(e=e.split(":"),n.port=e.pop(),n.hostname=e.join(":")):(n.hostname=e,n.port="");break;case"protocol":n.protocol=e.toLowerCase(),n.slashes=!r;break;case"pathname":n.pathname=e.length&&"/"!==e.charAt(0)?"/"+e:e;break;default:n[t]=e}for(var o=0;o<p.length;o++){var i=p[o];i[4]&&(n[i[1]]=n[i[1]].toLowerCase())}return n.origin=n.protocol&&n.host&&"file:"!==n.protocol?n.protocol+"//"+n.host:"null",n.href=n.toString(),n}function u(t){t&&"function"==typeof t||(t=l.stringify);var e,r=this,n=r.protocol;n&&":"!==n.charAt(n.length-1)&&(n+=":");var o=n+(r.slashes?"//":"");return r.username&&(o+=r.username,r.password&&(o+=":"+r.password),o+="@"),o+=r.host+r.pathname,e="object"==typeof r.query?t(r.query):r.query,e&&(o+="?"!==e.charAt(0)?"?"+e:e),r.hash&&(o+=r.hash),o}var a=t("requires-port"),c=t("./lolcation"),l=t("querystringify"),f=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,p=[["#","hash"],["?","query"],["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]];i.prototype={set:s,toString:u},i.extractProtocol=n,i.location=c,i.qs=l,e.exports=i},{"./lolcation":50,querystringify:44,"requires-port":45}],50:[function(t,e,r){(function(r){"use strict";var n,o=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,i={hash:1,query:1};e.exports=function(e){e=e||r.location||{},n=n||t("./");var s,u={},a=typeof e;if("blob:"===e.protocol)u=new n(unescape(e.pathname),{});else if("string"===a){u=new n(e,{});for(s in i)delete u[s]}else if("object"===a){for(s in e)s in i||(u[s]=e[s]);void 0===u.slashes&&(u.slashes=o.test(e.href))}return u}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./":49}],51:[function(t,e,r){var n=t("eventsource-polyfill/dist/eventsource");e.exports=window.EventSource||n.EventSource},{"eventsource-polyfill/dist/eventsource":52}],52:[function(t,e,r){!function(t){function e(t,e,r,n){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.data=e||null,this.origin=r||"",this.lastEventId=n||"",this.type=t||"message"}function r(){return!(!window.XDomainRequest||!window.XMLHttpRequest||void 0!==(new XMLHttpRequest).responseType)}if(!t.EventSource||t._eventSourceImportPrefix){var n=(t._eventSourceImportPrefix||"")+"EventSource",o=function(t,e){if(!t||"string"!=typeof t)throw new SyntaxError("Not enough arguments");this.URL=t,this.setOptions(e);var r=this;setTimeout(function(){r.poll()},0)};if(o.prototype={CONNECTING:0,OPEN:1,CLOSED:2,defaultOptions:{loggingEnabled:!1,loggingPrefix:"eventsource",interval:500,bufferSizeLimit:262144,silentTimeout:3e5,getArgs:{evs_buffer_size_limit:262144},xhrHeaders:{Accept:"text/event-stream","Cache-Control":"no-cache","X-Requested-With":"XMLHttpRequest"}},setOptions:function(t){var e,r=this.defaultOptions;for(e in r)r.hasOwnProperty(e)&&(this[e]=r[e]);for(e in t)e in r&&t.hasOwnProperty(e)&&(this[e]=t[e]);this.getArgs&&this.bufferSizeLimit&&(this.getArgs.evs_buffer_size_limit=this.bufferSizeLimit),"undefined"!=typeof console&&"undefined"!=typeof console.log||(this.loggingEnabled=!1)},log:function(t){this.loggingEnabled&&console.log("["+this.loggingPrefix+"]:"+t)},poll:function(){try{if(this.readyState==this.CLOSED)return;this.cleanup(),this.readyState=this.CONNECTING,this.cursor=0,this.cache="",this._xhr=new this.XHR(this),this.resetNoActivityTimer()}catch(t){this.log("There were errors inside the pool try-catch"),this.dispatchEvent("error",{type:"error",data:t.message})}},pollAgain:function(t){var e=this;e.readyState=e.CONNECTING,e.dispatchEvent("error",{type:"error",data:"Reconnecting "}),this._pollTimer=setTimeout(function(){e.poll()},t||0)},cleanup:function(){this.log("evs cleaning up"),this._pollTimer&&(clearInterval(this._pollTimer),this._pollTimer=null),this._noActivityTimer&&(clearInterval(this._noActivityTimer),this._noActivityTimer=null),this._xhr&&(this._xhr.abort(),this._xhr=null)},resetNoActivityTimer:function(){if(this.silentTimeout){this._noActivityTimer&&clearInterval(this._noActivityTimer);var t=this;this._noActivityTimer=setTimeout(function(){t.log("Timeout! silentTImeout:"+t.silentTimeout),t.pollAgain()},this.silentTimeout)}},close:function(){this.readyState=this.CLOSED,this.log("Closing connection. readyState: "+this.readyState),this.cleanup()},ondata:function(){var t=this._xhr;if(t.isReady()&&!t.hasError()){this.resetNoActivityTimer(),this.readyState==this.CONNECTING&&(this.readyState=this.OPEN,this.dispatchEvent("open",{type:"open"}));var e=t.getBuffer();e.length>this.bufferSizeLimit&&(this.log("buffer.length > this.bufferSizeLimit"),this.pollAgain()),0==this.cursor&&e.length>0&&"\ufeff"==e.substring(0,1)&&(this.cursor=1);var r=this.lastMessageIndex(e);if(r[0]>=this.cursor){var n=r[1],o=e.substring(this.cursor,n);this.parseStream(o),this.cursor=n}t.isDone()&&(this.log("request.isDone(). reopening the connection"),this.pollAgain(this.interval))}else this.readyState!==this.CLOSED&&(this.log("this.readyState !== this.CLOSED"),this.pollAgain(this.interval))},parseStream:function(t){t=this.cache+this.normalizeToLF(t);var r,n,o,i,s,u,a=t.split("\n\n");for(r=0;r<a.length-1;r++){for(o="message",i=[],parts=a[r].split("\n"),n=0;n<parts.length;n++)s=this.trimWhiteSpace(parts[n]),0==s.indexOf("event")?o=s.replace(/event:?\s*/,""):0==s.indexOf("retry")?(u=parseInt(s.replace(/retry:?\s*/,"")),isNaN(u)||(this.interval=u)):0==s.indexOf("data")?i.push(s.replace(/data:?\s*/,"")):0==s.indexOf("id:")?this.lastEventId=s.replace(/id:?\s*/,""):0==s.indexOf("id")&&(this.lastEventId=null);if(i.length){var c=new e(o,i.join("\n"),window.location.origin,this.lastEventId);this.dispatchEvent(o,c)}}this.cache=a[a.length-1]},dispatchEvent:function(t,e){var r=this["_"+t+"Handlers"];if(r)for(var n=0;n<r.length;n++)r[n].call(this,e);this["on"+t]&&this["on"+t].call(this,e)},addEventListener:function(t,e){this["_"+t+"Handlers"]||(this["_"+t+"Handlers"]=[]),this["_"+t+"Handlers"].push(e)},removeEventListener:function(t,e){var r=this["_"+t+"Handlers"];if(r)for(var n=r.length-1;n>=0;--n)if(r[n]===e){r.splice(n,1);break}},_pollTimer:null,_noactivityTimer:null,_xhr:null,lastEventId:null,cache:"",cursor:0,onerror:null,onmessage:null,onopen:null,readyState:0,urlWithParams:function(t,e){var r=[];if(e){var n,o,i=encodeURIComponent;for(n in e)e.hasOwnProperty(n)&&(o=i(n)+"="+i(e[n]),r.push(o))}return r.length>0?t.indexOf("?")==-1?t+"?"+r.join("&"):t+"&"+r.join("&"):t},lastMessageIndex:function(t){var e=t.lastIndexOf("\n\n"),r=t.lastIndexOf("\r\r"),n=t.lastIndexOf("\r\n\r\n");return n>Math.max(e,r)?[n,n+4]:[Math.max(e,r),Math.max(e,r)+2]},trimWhiteSpace:function(t){var e=/^(\s|\u00A0)+|(\s|\u00A0)+$/g;return t.replace(e,"")},normalizeToLF:function(t){return t.replace(/\r\n|\r/g,"\n")}},r()){o.isPolyfill="IE_8-9";var i=o.prototype.defaultOptions;i.xhrHeaders=null,i.getArgs.evs_preamble=2056,o.prototype.XHR=function(t){request=new XDomainRequest,this._request=request,request.onprogress=function(){request._ready=!0,t.ondata()},request.onload=function(){this._loaded=!0,t.ondata()},request.onerror=function(){this._failed=!0,t.readyState=t.CLOSED,t.dispatchEvent("error",{type:"error",data:"XDomainRequest error"})},request.ontimeout=function(){this._failed=!0,t.readyState=t.CLOSED,t.dispatchEvent("error",{type:"error",data:"XDomainRequest timed out"})};var e={};if(t.getArgs){var r=t.getArgs;for(var n in r)r.hasOwnProperty(n)&&(e[n]=r[n]);t.lastEventId&&(e.evs_last_event_id=t.lastEventId)}request.open("GET",t.urlWithParams(t.URL,e)),request.send()},o.prototype.XHR.prototype={useXDomainRequest:!0,_request:null,_ready:!1,_loaded:!1,_failed:!1,isReady:function(){return this._request._ready},isDone:function(){return this._request._loaded},hasError:function(){return this._request._failed},getBuffer:function(){var t="";try{t=this._request.responseText||""}catch(t){}return t},abort:function(){this._request&&this._request.abort()}}}else o.isPolyfill="XHR",o.prototype.XHR=function(t){request=new XMLHttpRequest,this._request=request,t._xhr=this,request.onreadystatechange=function(){request.readyState>1&&t.readyState!=t.CLOSED&&(200==request.status||request.status>=300&&request.status<400?t.ondata():(request._failed=!0,t.readyState=t.CLOSED,t.dispatchEvent("error",{type:"error",data:"The server responded with "+request.status}),t.close()))},request.onprogress=function(){},request.open("GET",t.urlWithParams(t.URL,t.getArgs),!0);var e=t.xhrHeaders;for(var r in e)e.hasOwnProperty(r)&&request.setRequestHeader(r,e[r]);t.lastEventId&&request.setRequestHeader("Last-Event-Id",t.lastEventId),request.send()},o.prototype.XHR.prototype={useXDomainRequest:!1,_request:null,_failed:!1,isReady:function(){return this._request.readyState>=2},isDone:function(){return 4==this._request.readyState},hasError:function(){return this._failed||this._request.status>=400},getBuffer:function(){var t="";try{t=this._request.responseText||""}catch(t){}return t},abort:function(){this._request&&this._request.abort()}};t[n]=o}}(this)},{}],53:[function(t,e,r){"use strict";function n(){i.apply(this,arguments)}var o=t("rxjs/Observable"),i=o.Observable,s=t("rxjs/operator/map"),u=s.map,a=t("rxjs/operator/filter"),c=a.filter,l=t("rxjs/operator/reduce"),f=l.reduce,p=t("rxjs/operator/toPromise"),h=p.toPromise,d=t("object-assign");n.prototype=Object.create(d(Object.create(null),i.prototype)),Object.defineProperty(n.prototype,"constructor",{value:n,enumerable:!1,writable:!0,configurable:!0}),n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.map=u,n.prototype.filter=c,n.prototype.reduce=f,n.prototype.toPromise=h,e.exports=n},{"object-assign":55,"rxjs/Observable":56,"rxjs/operator/filter":60,"rxjs/operator/map":61,"rxjs/operator/reduce":62,"rxjs/operator/toPromise":63}],54:[function(t,e,r){e.exports=t("./lib/SanityObservableMinimal")},{"./lib/SanityObservableMinimal":53}],55:[function(t,e,r){arguments[4][42][0].apply(r,arguments)},{dup:42}],56:[function(t,e,r){"use strict";var n=t("./util/root"),o=t("./util/toSubscriber"),i=t("./symbol/observable"),s=function(){function t(t){this._isScalar=!1,t&&(this._subscribe=t)}return t.prototype.lift=function(e){var r=new t;return r.source=this,r.operator=e,r},t.prototype.subscribe=function(t,e,r){var n=this.operator,i=o.toSubscriber(t,e,r);if(n?n.call(i,this.source):i.add(this._subscribe(i)),i.syncErrorThrowable&&(i.syncErrorThrowable=!1,i.syncErrorThrown))throw i.syncErrorValue;return i},t.prototype.forEach=function(t,e){var r=this;if(e||(n.root.Rx&&n.root.Rx.config&&n.root.Rx.config.Promise?e=n.root.Rx.config.Promise:n.root.Promise&&(e=n.root.Promise)),!e)throw new Error("no Promise impl found");return new e(function(e,n){var o=r.subscribe(function(e){if(o)try{t(e)}catch(t){n(t),o.unsubscribe()}else t(e)},n,e)})},t.prototype._subscribe=function(t){return this.source.subscribe(t)},t.prototype[i.$$observable]=function(){return this},t.create=function(e){return new t(e)},t}();r.Observable=s},{"./symbol/observable":64,"./util/root":71,"./util/toSubscriber":72}],57:[function(t,e,r){"use strict";r.empty={closed:!0,next:function(t){},error:function(t){throw t},complete:function(){}}},{}],58:[function(t,e,r){"use strict";var n=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},o=t("./util/isFunction"),i=t("./Subscription"),s=t("./Observer"),u=t("./symbol/rxSubscriber"),a=function(t){function e(r,n,o){switch(t.call(this),this.syncErrorValue=null,this.syncErrorThrown=!1,this.syncErrorThrowable=!1,this.isStopped=!1,arguments.length){case 0:this.destination=s.empty;break;case 1:if(!r){this.destination=s.empty;break}if("object"==typeof r){r instanceof e?(this.destination=r,this.destination.add(this)):(this.syncErrorThrowable=!0,this.destination=new c(this,r));break}default:this.syncErrorThrowable=!0,this.destination=new c(this,r,n,o)}}return n(e,t),e.prototype[u.$$rxSubscriber]=function(){return this},e.create=function(t,r,n){var o=new e(t,r,n);return o.syncErrorThrowable=!1,o},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this))},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){this.destination.error(t),this.unsubscribe()},e.prototype._complete=function(){this.destination.complete(),this.unsubscribe()},e}(i.Subscription);r.Subscriber=a;var c=function(t){function e(e,r,n,i){t.call(this),this._parent=e;var s,u=this;o.isFunction(r)?s=r:r&&(u=r,s=r.next,n=r.error,i=r.complete,o.isFunction(u.unsubscribe)&&this.add(u.unsubscribe.bind(u)),u.unsubscribe=this.unsubscribe.bind(this)),this._context=u,this._next=s,this._error=n,this._complete=i}return n(e,t),e.prototype.next=function(t){if(!this.isStopped&&this._next){var e=this._parent;e.syncErrorThrowable?this.__tryOrSetError(e,this._next,t)&&this.unsubscribe():this.__tryOrUnsub(this._next,t)}},e.prototype.error=function(t){if(!this.isStopped){var e=this._parent;if(this._error)e.syncErrorThrowable?(this.__tryOrSetError(e,this._error,t),this.unsubscribe()):(this.__tryOrUnsub(this._error,t),this.unsubscribe());else{if(!e.syncErrorThrowable)throw this.unsubscribe(),t;e.syncErrorValue=t,e.syncErrorThrown=!0,this.unsubscribe()}}},e.prototype.complete=function(){if(!this.isStopped){var t=this._parent;this._complete?t.syncErrorThrowable?(this.__tryOrSetError(t,this._complete),this.unsubscribe()):(this.__tryOrUnsub(this._complete),this.unsubscribe()):this.unsubscribe()}},e.prototype.__tryOrUnsub=function(t,e){try{t.call(this._context,e)}catch(t){throw this.unsubscribe(),t}},e.prototype.__tryOrSetError=function(t,e,r){try{e.call(this._context,r)}catch(e){return t.syncErrorValue=e,t.syncErrorThrown=!0,!0}return!1},e.prototype._unsubscribe=function(){var t=this._parent;this._context=null,this._parent=null,t.unsubscribe()},e}(a)},{"./Observer":57,"./Subscription":59,"./symbol/rxSubscriber":65,"./util/isFunction":69}],59:[function(t,e,r){"use strict";function n(t){return t.reduce(function(t,e){return t.concat(e instanceof l.UnsubscriptionError?e.errors:e)},[])}var o=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},i=t("./util/isArray"),s=t("./util/isObject"),u=t("./util/isFunction"),a=t("./util/tryCatch"),c=t("./util/errorObject"),l=t("./util/UnsubscriptionError"),f=function(){function t(t){this.closed=!1,t&&(this._unsubscribe=t)}return t.prototype.unsubscribe=function(){var t,e=!1;if(!this.closed){this.closed=!0;var r=this,o=r._unsubscribe,f=r._subscriptions;if(this._subscriptions=null,u.isFunction(o)){var p=a.tryCatch(o).call(this);p===c.errorObject&&(e=!0,t=t||(c.errorObject.e instanceof l.UnsubscriptionError?n(c.errorObject.e.errors):[c.errorObject.e]))}if(i.isArray(f))for(var h=-1,d=f.length;++h<d;){var b=f[h];if(s.isObject(b)){var p=a.tryCatch(b.unsubscribe).call(b);if(p===c.errorObject){e=!0,t=t||[];var y=c.errorObject.e;y instanceof l.UnsubscriptionError?t=t.concat(n(y.errors)):t.push(y)}}}if(e)throw new l.UnsubscriptionError(t)}},t.prototype.add=function(e){if(!e||e===t.EMPTY)return t.EMPTY;if(e===this)return this;var r=e;switch(typeof e){case"function":r=new t(e);case"object":if(r.closed||"function"!=typeof r.unsubscribe)return r;if(this.closed)return r.unsubscribe(),r;break;default:throw new Error("unrecognized teardown "+e+" added to Subscription.")}var n=new p(r,this);return this._subscriptions=this._subscriptions||[],this._subscriptions.push(n),n},t.prototype.remove=function(e){if(null!=e&&e!==this&&e!==t.EMPTY){var r=this._subscriptions;if(r){var n=r.indexOf(e);n!==-1&&r.splice(n,1)}}},t.EMPTY=function(t){return t.closed=!0,t}(new t),t}();r.Subscription=f;var p=function(t){function e(e,r){t.call(this),this._innerSub=e,this._parent=r}return o(e,t),e.prototype._unsubscribe=function(){var t=this,e=t._innerSub,r=t._parent;r.remove(this),e.unsubscribe()},e}(f);r.ChildSubscription=p},{"./util/UnsubscriptionError":66,"./util/errorObject":67,"./util/isArray":68,"./util/isFunction":69,"./util/isObject":70,"./util/tryCatch":73}],60:[function(t,e,r){"use strict";function n(t,e){return this.lift(new s(t,e))}var o=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},i=t("../Subscriber");r.filter=n;var s=function(){function t(t,e){this.predicate=t,this.thisArg=e}return t.prototype.call=function(t,e){return e.subscribe(new u(t,this.predicate,this.thisArg))},t}(),u=function(t){function e(e,r,n){t.call(this,e),this.predicate=r,this.thisArg=n,this.count=0,this.predicate=r}return o(e,t),e.prototype._next=function(t){var e;try{e=this.predicate.call(this.thisArg,t,this.count++)}catch(t){return void this.destination.error(t)}e&&this.destination.next(t)},e}(i.Subscriber)},{"../Subscriber":58}],61:[function(t,e,r){"use strict";function n(t,e){if("function"!=typeof t)throw new TypeError("argument is not a function. Are you looking for `mapTo()`?");return this.lift(new s(t,e))}var o=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},i=t("../Subscriber");r.map=n;var s=function(){function t(t,e){this.project=t,this.thisArg=e}return t.prototype.call=function(t,e){return e.subscribe(new u(t,this.project,this.thisArg))},t}();r.MapOperator=s;var u=function(t){function e(e,r,n){t.call(this,e),this.project=r,this.count=0,this.thisArg=n||this}return o(e,t),e.prototype._next=function(t){var e;try{e=this.project.call(this.thisArg,t,this.count++)}catch(t){return void this.destination.error(t)}this.destination.next(e)},e}(i.Subscriber)},{"../Subscriber":58}],62:[function(t,e,r){"use strict";function n(t,e){var r=!1;return arguments.length>=2&&(r=!0),this.lift(new s(t,e,r))}var o=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},i=t("../Subscriber");r.reduce=n;var s=function(){function t(t,e,r){void 0===r&&(r=!1),this.accumulator=t,this.seed=e,this.hasSeed=r}return t.prototype.call=function(t,e){return e.subscribe(new u(t,this.accumulator,this.seed,this.hasSeed))},t}();r.ReduceOperator=s;var u=function(t){function e(e,r,n,o){t.call(this,e),this.accumulator=r,this.hasSeed=o,this.hasValue=!1,this.acc=n}return o(e,t),e.prototype._next=function(t){this.hasValue||(this.hasValue=this.hasSeed)?this._tryReduce(t):(this.acc=t,this.hasValue=!0)},e.prototype._tryReduce=function(t){var e;try{e=this.accumulator(this.acc,t)}catch(t){return void this.destination.error(t)}this.acc=e},e.prototype._complete=function(){(this.hasValue||this.hasSeed)&&this.destination.next(this.acc),this.destination.complete()},e}(i.Subscriber);r.ReduceSubscriber=u},{"../Subscriber":58}],63:[function(t,e,r){"use strict";function n(t){var e=this;if(t||(o.root.Rx&&o.root.Rx.config&&o.root.Rx.config.Promise?t=o.root.Rx.config.Promise:o.root.Promise&&(t=o.root.Promise)),!t)throw new Error("no Promise impl found");return new t(function(t,r){var n;e.subscribe(function(t){return n=t},function(t){return r(t)},function(){return t(n)})})}var o=t("../util/root");r.toPromise=n},{"../util/root":71}],64:[function(t,e,r){"use strict";function n(t){var e,r=t.Symbol;return"function"==typeof r?r.observable?e=r.observable:(e=r("observable"),r.observable=e):e="@@observable",e}var o=t("../util/root");r.getSymbolObservable=n,r.$$observable=n(o.root)},{"../util/root":71}],65:[function(t,e,r){"use strict";var n=t("../util/root"),o=n.root.Symbol;r.$$rxSubscriber="function"==typeof o&&"function"==typeof o.for?o.for("rxSubscriber"):"@@rxSubscriber"},{"../util/root":71}],66:[function(t,e,r){"use strict";var n=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)},o=function(t){function e(e){t.call(this),this.errors=e;var r=Error.call(this,e?e.length+" errors occurred during unsubscription:\n "+e.map(function(t,e){return e+1+") "+t.toString()}).join("\n "):"");this.name=r.name="UnsubscriptionError",this.stack=r.stack,this.message=r.message}return n(e,t),e}(Error);r.UnsubscriptionError=o},{}],67:[function(t,e,r){"use strict";r.errorObject={e:{}}},{}],68:[function(t,e,r){"use strict";r.isArray=Array.isArray||function(t){return t&&"number"==typeof t.length}},{}],69:[function(t,e,r){"use strict";function n(t){return"function"==typeof t}r.isFunction=n},{}],70:[function(t,e,r){"use strict";function n(t){return null!=t&&"object"==typeof t}r.isObject=n},{}],71:[function(t,e,r){(function(t){"use strict";if(r.root="object"==typeof window&&window.window===window&&window||"object"==typeof self&&self.self===self&&self||"object"==typeof t&&t.global===t&&t,!r.root)throw new Error("RxJS could not find any global context (window, self, global)")}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],72:[function(t,e,r){"use strict";function n(t,e,r){if(t){if(t instanceof o.Subscriber)return t;if(t[i.$$rxSubscriber])return t[i.$$rxSubscriber]()}return t||e||r?new o.Subscriber(t,e,r):new o.Subscriber(s.empty)}var o=t("../Subscriber"),i=t("../symbol/rxSubscriber"),s=t("../Observer");r.toSubscriber=n},{"../Observer":57,"../Subscriber":58,"../symbol/rxSubscriber":65}],73:[function(t,e,r){"use strict";function n(){try{return i.apply(this,arguments)}catch(t){return s.errorObject.e=t,s.errorObject}}function o(t){return i=t,n}var i,s=t("./errorObject");r.tryCatch=o},{"./errorObject":67}]},{},[13])(13)});

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc