@sanity/client
Advanced tools
Comparing version 0.3.4 to 0.3.5
@@ -15,3 +15,3 @@ 'use strict'; | ||
// Always return IDs | ||
{ returnIDs: true }, | ||
{ returnIds: true }, | ||
@@ -104,3 +104,3 @@ // Allow user to disable returning documents | ||
}); | ||
return _defineProperty({ transactionId: res.transactionID }, key, ids); | ||
return _defineProperty({ transactionId: res.transactionId }, key, ids); | ||
}); | ||
@@ -107,0 +107,0 @@ }, |
{ | ||
"name": "@sanity/client", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "Client for retrieving data from Sanity", | ||
@@ -5,0 +5,0 @@ "main": "lib/sanityClient.js", |
@@ -256,5 +256,5 @@ // (Node 4 compat) | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', {mutations: [{create: doc}]}) | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', {mutations: [{create: doc}]}) | ||
.reply(200, { | ||
transactionID: 'abc123', | ||
transactionId: 'abc123', | ||
results: [{ | ||
@@ -278,5 +278,5 @@ document: {_id: 'foo/123', _createdAt: '2016-10-24T08:09:32.997Z', name: 'Raptor'}, | ||
const expectedBody = {mutations: [{create: Object.assign({}, doc, {_id: 'foo/'})}]} | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', expectedBody) | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', expectedBody) | ||
.reply(200, { | ||
transactionID: '123abc', | ||
transactionId: '123abc', | ||
results: [{ | ||
@@ -298,4 +298,4 @@ id: 'foo/456', | ||
const doc = {_id: 'foo/123', name: 'Raptor'} | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIDs=true', {mutations: [{create: doc}]}) | ||
.reply(200, {transactionID: 'abc123', results: [{id: 'foo/123', operation: 'create'}]}) | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true', {mutations: [{create: doc}]}) | ||
.reply(200, {transactionId: 'abc123', results: [{id: 'foo/123', operation: 'create'}]}) | ||
@@ -314,4 +314,4 @@ getClient().create(doc, {returnDocuments: false}) | ||
const expectedBody = {mutations: [{createIfNotExists: doc}]} | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', expectedBody) | ||
.reply(200, {transactionID: '123abc', results: [{id: 'foo/123', document: doc, operation: 'create'}]}) | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', expectedBody) | ||
.reply(200, {transactionId: '123abc', results: [{id: 'foo/123', document: doc, operation: 'create'}]}) | ||
@@ -324,4 +324,4 @@ getClient().createIfNotExists(doc).then(() => t.end()).catch(t.ifError) | ||
const expectedBody = {mutations: [{createIfNotExists: doc}]} | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIDs=true', expectedBody) | ||
.reply(200, {transactionID: 'abc123', results: [{id: 'foo/123', operation: 'create'}]}) | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true', expectedBody) | ||
.reply(200, {transactionId: 'abc123', results: [{id: 'foo/123', operation: 'create'}]}) | ||
@@ -340,4 +340,4 @@ getClient().createIfNotExists(doc, {returnDocuments: false}) | ||
const expectedBody = {mutations: [{createOrReplace: doc}]} | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', expectedBody) | ||
.reply(200, {transactionID: '123abc', results: [{id: 'foo/123', operation: 'create'}]}) | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', expectedBody) | ||
.reply(200, {transactionId: '123abc', results: [{id: 'foo/123', operation: 'create'}]}) | ||
@@ -350,4 +350,4 @@ getClient().createOrReplace(doc).then(() => t.end()).catch(t.ifError) | ||
const expectedBody = {mutations: [{createOrReplace: doc}]} | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIDs=true', expectedBody) | ||
.reply(200, {transactionID: 'abc123', results: [{id: 'foo/123', operation: 'create'}]}) | ||
nock(projectHost()).post('/v1/data/mutate/foo?returnIds=true', expectedBody) | ||
.reply(200, {transactionId: 'abc123', results: [{id: 'foo/123', operation: 'create'}]}) | ||
@@ -366,4 +366,4 @@ getClient().createOrReplace(doc, {returnDocuments: false}) | ||
nock(projectHost()) | ||
.post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', expectedBody) | ||
.reply(200, {transactionID: 'abc123', results: [{id: 'foo/123', operation: 'delete'}]}) | ||
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', expectedBody) | ||
.reply(200, {transactionId: 'abc123', results: [{id: 'foo/123', operation: 'delete'}]}) | ||
@@ -390,4 +390,4 @@ getClient().delete('foo/123').then(() => t.end()).catch(t.ifError) | ||
nock(projectHost()) | ||
.post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', {mutations}) | ||
.reply(200, {transactionID: 'foo', results: [ | ||
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', {mutations}) | ||
.reply(200, {transactionId: 'foo', results: [ | ||
{id: 'movie/raiders-of-the-lost-ark', operation: 'create', document: docs[0]}, | ||
@@ -507,4 +507,4 @@ {id: 'movie/the-phantom-menace', operation: 'delete', document: docs[1]} | ||
nock(projectHost()) | ||
.post('/v1/data/mutate/foo?returnIDs=true', {mutations: [expectedPatch]}) | ||
.reply(200, {transactionID: 'blatti'}) | ||
.post('/v1/data/mutate/foo?returnIds=true', {mutations: [expectedPatch]}) | ||
.reply(200, {transactionId: 'blatti'}) | ||
@@ -526,4 +526,4 @@ getClient().patch('foo/123') | ||
nock(projectHost()) | ||
.post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', expectedBody) | ||
.reply(200, {transactionID: 'blatti', results: [{ | ||
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', expectedBody) | ||
.reply(200, {transactionId: 'blatti', results: [{ | ||
id: 'foo/123', | ||
@@ -554,3 +554,3 @@ operation: 'update', | ||
nock(projectHost()) | ||
.post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', expectedBody) | ||
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', expectedBody) | ||
.reply(400) | ||
@@ -741,4 +741,4 @@ | ||
nock(projectHost()) | ||
.post('/v1/data/mutate/foo?returnIDs=true', {mutations}) | ||
.reply(200, {transactionID: 'blatti'}) | ||
.post('/v1/data/mutate/foo?returnIds=true', {mutations}) | ||
.reply(200, {transactionId: 'blatti'}) | ||
@@ -867,3 +867,3 @@ getClient().transaction() | ||
nock(projectHost()) | ||
.post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', expectedBody) | ||
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', expectedBody) | ||
.replyWithError(new Error('Something went wrong')) | ||
@@ -887,3 +887,3 @@ | ||
nock(projectHost()) | ||
.post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', expectedBody) | ||
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', expectedBody) | ||
.socketDelay(75) | ||
@@ -909,3 +909,3 @@ .delay({head: 500, body: 750}) | ||
nock(projectHost()) | ||
.post('/v1/data/mutate/foo?returnIDs=true&returnDocuments=true', expectedBody) | ||
.post('/v1/data/mutate/foo?returnIds=true&returnDocuments=true', expectedBody) | ||
.socketDelay(300) | ||
@@ -912,0 +912,0 @@ .reply(200) |
@@ -10,3 +10,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SanityClient = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
},{"./validators":18,"xtend/mutable":31}],4:[function(require,module,exports){ | ||
"use strict";function _defineProperty(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var assign=require("xtend/mutable"),validators=require("../validators"),encodeQueryString=require("./encodeQueryString"),Transaction=require("./transaction"),Patch=require("./patch"),listen=require("./listen"),getMutationQuery=function(t){return assign({returnIDs:!0},t.returnDocuments===!1?{}:{returnDocuments:!0})},getQuerySizeLimit=1948;module.exports={listen:listen,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:"/data/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 Patch(t,e,this)},delete:function(t){return validators.validateDocumentId("delete",t),this.dataRequest("mutate",{mutations:[{delete:{id:t}}]})},mutate:function(t,e){var r=t instanceof Patch?t.serialize():t,n=Array.isArray(r)?r:[r];return this.dataRequest("mutate",{mutations:n},e)},transaction:function(t){return new Transaction(t,this)},dataRequest:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i="mutate"===t,u=!i&&encodeQueryString(e),a=!i&&u.length<getQuerySizeLimit,s=a?u:"",o=n.returnFirst;return validators.promise.hasDataset(this.clientConfig).then(function(u){return r.request({method:a?"GET":"POST",uri:"/data/"+t+"/"+u+s,json:!0,body:a?void 0:e,query:i&&getMutationQuery(n)})}).then(function(t){if(!i)return t;var e=t.results||[];if(n.returnDocuments)return o?e[0]&&e[0].document:e.map(function(t){return t.document});var r=o?"documentId":"documentIds",u=o?e[0]&&e[0].id:e.map(function(t){return t.id});return _defineProperty({transactionId:t.transactionID},r,u)})},_create:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=validators.hasDataset(this.clientConfig),i=_defineProperty({},e,assign({},t,{_id:t._id||n+"/"})),u=assign({returnFirst:!0,returnDocuments:!0},r);return this.dataRequest("mutate",{mutations:[i]},u)}}; | ||
"use strict";function _defineProperty(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var assign=require("xtend/mutable"),validators=require("../validators"),encodeQueryString=require("./encodeQueryString"),Transaction=require("./transaction"),Patch=require("./patch"),listen=require("./listen"),getMutationQuery=function(t){return assign({returnIds:!0},t.returnDocuments===!1?{}:{returnDocuments:!0})},getQuerySizeLimit=1948;module.exports={listen:listen,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:"/data/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 Patch(t,e,this)},delete:function(t){return validators.validateDocumentId("delete",t),this.dataRequest("mutate",{mutations:[{delete:{id:t}}]})},mutate:function(t,e){var r=t instanceof Patch?t.serialize():t,n=Array.isArray(r)?r:[r];return this.dataRequest("mutate",{mutations:n},e)},transaction:function(t){return new Transaction(t,this)},dataRequest:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i="mutate"===t,u=!i&&encodeQueryString(e),a=!i&&u.length<getQuerySizeLimit,s=a?u:"",o=n.returnFirst;return validators.promise.hasDataset(this.clientConfig).then(function(u){return r.request({method:a?"GET":"POST",uri:"/data/"+t+"/"+u+s,json:!0,body:a?void 0:e,query:i&&getMutationQuery(n)})}).then(function(t){if(!i)return t;var e=t.results||[];if(n.returnDocuments)return o?e[0]&&e[0].document:e.map(function(t){return t.document});var r=o?"documentId":"documentIds",u=o?e[0]&&e[0].id:e.map(function(t){return t.id});return _defineProperty({transactionId:t.transactionId},r,u)})},_create:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=validators.hasDataset(this.clientConfig),i=_defineProperty({},e,assign({},t,{_id:t._id||n+"/"})),u=assign({returnFirst:!0,returnDocuments:!0},r);return this.dataRequest("mutate",{mutations:[i]},u)}}; | ||
@@ -60,4 +60,6 @@ },{"../validators":18,"./encodeQueryString":5,"./listen":6,"./patch":7,"./transaction":8,"xtend/mutable":31}],5:[function(require,module,exports){ | ||
"use strict";function toObject(r){if(null===r||void 0===r)throw new TypeError("Sources cannot be null or undefined");return Object(r)}function assignKey(r,e,n){var t=e[n];if(void 0!==t&&null!==t){if(hasOwnProperty.call(r,n)&&(void 0===r[n]||null===r[n]))throw new TypeError("Cannot convert undefined or null to object ("+n+")");hasOwnProperty.call(r,n)&&isObj(t)?r[n]=assign(Object(r[n]),e[n]):r[n]=t}}function assign(r,e){if(r===e)return r;e=Object(e);for(var n in e)hasOwnProperty.call(e,n)&&assignKey(r,e,n);if(Object.getOwnPropertySymbols)for(var t=Object.getOwnPropertySymbols(e),o=0;o<t.length;o++)propIsEnumerable.call(e,t[o])&&assignKey(r,e,t[o]);return r}var isObj=require("is-obj"),hasOwnProperty=Object.prototype.hasOwnProperty,propIsEnumerable=Object.prototype.propertyIsEnumerable;module.exports=function(r){r=toObject(r);for(var e=1;e<arguments.length;e++)assign(r,arguments[e]);return r}; | ||
},{"is-obj":27}],23:[function(require,module,exports){ | ||
!function(t){function e(t,e,i,r){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.data=e||null,this.origin=i||"",this.lastEventId=r||"",this.type=t||"message"}function i(){return!(!window.XDomainRequest||!window.XMLHttpRequest||void 0!==(new XMLHttpRequest).responseType)}if(!t.EventSource||t._eventSourceImportPrefix){var r=(t._eventSourceImportPrefix||"")+"EventSource",s=function(t,e){if(!t||"string"!=typeof t)throw new SyntaxError("Not enough arguments");this.URL=t,this.setOptions(e);var i=this;setTimeout(function(){i.poll()},0)};if(s.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,i=this.defaultOptions;for(e in i)i.hasOwnProperty(e)&&(this[e]=i[e]);for(e in t)e in i&&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 i=this.lastMessageIndex(e);if(i[0]>=this.cursor){var r=i[1],s=e.substring(this.cursor,r);this.parseStream(s),this.cursor=r}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 i,r,s,n,a,o,h=t.split("\n\n");for(i=0;i<h.length-1;i++){for(s="message",n=[],parts=h[i].split("\n"),r=0;r<parts.length;r++)a=this.trimWhiteSpace(parts[r]),0==a.indexOf("event")?s=a.replace(/event:?\s*/,""):0==a.indexOf("retry")?(o=parseInt(a.replace(/retry:?\s*/,"")),isNaN(o)||(this.interval=o)):0==a.indexOf("data")?n.push(a.replace(/data:?\s*/,"")):0==a.indexOf("id:")?this.lastEventId=a.replace(/id:?\s*/,""):0==a.indexOf("id")&&(this.lastEventId=null);if(n.length){var u=new e(s,n.join("\n"),window.location.origin,this.lastEventId);this.dispatchEvent(s,u)}}this.cache=h[h.length-1]},dispatchEvent:function(t,e){var i=this["_"+t+"Handlers"];if(i)for(var r=0;r<i.length;r++)i[r].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 i=this["_"+t+"Handlers"];if(i)for(var r=i.length-1;r>=0;--r)if(i[r]===e){i.splice(r,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 i=[];if(e){var r,s,n=encodeURIComponent;for(r in e)e.hasOwnProperty(r)&&(s=n(r)+"="+n(e[r]),i.push(s))}return i.length>0?t.indexOf("?")==-1?t+"?"+i.join("&"):t+"&"+i.join("&"):t},lastMessageIndex:function(t){var e=t.lastIndexOf("\n\n"),i=t.lastIndexOf("\r\r"),r=t.lastIndexOf("\r\n\r\n");return r>Math.max(e,i)?[r,r+4]:[Math.max(e,i),Math.max(e,i)+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")}},i()){s.isPolyfill="IE_8-9";var n=s.prototype.defaultOptions;n.xhrHeaders=null,n.getArgs.evs_preamble=2056,s.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 i=t.getArgs;for(var r in i)i.hasOwnProperty(r)&&(e[r]=i[r]);t.lastEventId&&(e.evs_last_event_id=t.lastEventId)}request.open("GET",t.urlWithParams(t.URL,e)),request.send()},s.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 s.isPolyfill="XHR",s.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 i in e)e.hasOwnProperty(i)&&request.setRequestHeader(i,e[i]);t.lastEventId&&request.setRequestHeader("Last-Event-Id",t.lastEventId),request.send()},s.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[r]=s}}(this); | ||
},{}],24:[function(require,module,exports){ | ||
@@ -72,3 +74,2 @@ function forEach(r,t,o){if(!isFunction(t))throw new TypeError("iterator must be a function");arguments.length<3&&(o=this),"[object Array]"===toString.call(r)?forEachArray(r,t,o):"string"==typeof r?forEachString(r,t,o):forEachObject(r,t,o)}function forEachArray(r,t,o){for(var n=0,a=r.length;n<a;n++)hasOwnProperty.call(r,n)&&t.call(o,r[n],n,r)}function forEachString(r,t,o){for(var n=0,a=r.length;n<a;n++)t.call(o,r.charAt(n),n,r)}function forEachObject(r,t,o){for(var n in r)hasOwnProperty.call(r,n)&&t.call(o,r[n],n,r)}var isFunction=require("is-function");module.exports=forEach;var toString=Object.prototype.toString,hasOwnProperty=Object.prototype.hasOwnProperty; | ||
function isFunction(o){var t=toString.call(o);return"[object Function]"===t||"function"==typeof o&&"[object RegExp]"!==t||"undefined"!=typeof window&&(o===window.setTimeout||o===window.alert||o===window.confirm||o===window.prompt)}module.exports=isFunction;var toString=Object.prototype.toString; | ||
},{}],27:[function(require,module,exports){ | ||
@@ -84,2 +85,3 @@ "use strict";module.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}; | ||
function extend(){for(var r={},e=0;e<arguments.length;e++){var t=arguments[e];for(var n in t)hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}module.exports=extend;var hasOwnProperty=Object.prototype.hasOwnProperty; | ||
},{}],31:[function(require,module,exports){ | ||
@@ -90,3 +92,2 @@ function extend(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}module.exports=extend;var hasOwnProperty=Object.prototype.hasOwnProperty; | ||
module.exports=require("./zen-observable.js").Observable; | ||
},{"./zen-observable.js":33}],33:[function(require,module,exports){ | ||
@@ -93,0 +94,0 @@ "use strict";!function(r,t){"undefined"!=typeof exports?r(exports,module):"undefined"!=typeof self&&r("*"===t?self:t?self[t]={}:{})}(function(r,t){function n(r){return"function"==typeof Symbol&&Boolean(Symbol[r])}function e(r){return n(r)?Symbol[r]:"@@"+r}function o(r,t){var n=r[t];if(null!=n){if("function"!=typeof n)throw new TypeError(n+" is not a function");return n}}function i(r){var t=e("species");return t?r[t]:r}function c(r,t){Object.keys(t).forEach(function(n){var e=Object.getOwnPropertyDescriptor(t,n);e.enumerable=!1,Object.defineProperty(r,n,e)})}function u(r){var t=r._cleanup;t&&(r._cleanup=void 0,t())}function f(r){return void 0===r._observer}function s(r){f(r)||(r._observer=void 0,u(r))}function a(r){return function(t){r.unsubscribe()}}function l(r,t){if(Object(r)!==r)throw new TypeError("Observer must be an object");this._cleanup=void 0,this._observer=r;var n=o(r,"start");if(n&&n.call(r,this),!f(this)){r=new b(this);try{var e=t.call(void 0,r);if(null!=e){if("function"==typeof e.unsubscribe)e=a(e);else if("function"!=typeof e)throw new TypeError(e+" is not a function");this._cleanup=e}}catch(t){return void r.error(t)}f(this)&&u(this)}}function b(r){this._subscription=r}function p(r){if("function"!=typeof r)throw new TypeError("Observable initializer must be a function");this._subscriber=r}c(l.prototype={},{get closed(){return f(this)},unsubscribe:function(){s(this)}}),c(b.prototype={},{get closed(){return f(this._subscription)},next:function(r){var t=this._subscription;if(!f(t)){var n=t._observer;try{var e=o(n,"next");if(!e)return;return e.call(n,r)}catch(r){try{s(t)}finally{throw r}}}},error:function(r){var t=this._subscription;if(f(t))throw r;var n=t._observer;t._observer=void 0;try{var e=o(n,"error");if(!e)throw r;r=e.call(n,r)}catch(r){try{u(t)}finally{throw r}}return u(t),r},complete:function(r){var t=this._subscription;if(!f(t)){var n=t._observer;t._observer=void 0;try{var e=o(n,"complete");r=e?e.call(n,r):void 0}catch(r){try{u(t)}finally{throw r}}return u(t),r}}}),c(p.prototype,{subscribe:function(r){for(var t=[],n=1;n<arguments.length;++n)t.push(arguments[n]);return"function"==typeof r&&(r={next:r,error:t[0],complete:t[1]}),new l(r,this._subscriber)},forEach:function(r){var t=this;return new Promise(function(n,e){return"function"!=typeof r?Promise.reject(new TypeError(r+" is not a function")):void t.subscribe({_subscription:null,start:function(r){if(Object(r)!==r)throw new TypeError(r+" is not an object");this._subscription=r},next:function(t){var n=this._subscription;if(!n.closed)try{return r(t)}catch(r){e(r),n.unsubscribe()}},error:e,complete:n})})},map:function(r){var t=this;if("function"!=typeof r)throw new TypeError(r+" is not a function");var n=i(this.constructor);return new n(function(n){return t.subscribe({next:function(t){if(!n.closed){try{t=r(t)}catch(r){return n.error(r)}return n.next(t)}},error:function(r){return n.error(r)},complete:function(r){return n.complete(r)}})})},filter:function(r){var t=this;if("function"!=typeof r)throw new TypeError(r+" is not a function");var n=i(this.constructor);return new n(function(n){return t.subscribe({next:function(t){if(!n.closed){try{if(!r(t))return}catch(r){return n.error(r)}return n.next(t)}},error:function(r){return n.error(r)},complete:function(){return n.complete()}})})},reduce:function(r){var t=this;if("function"!=typeof r)throw new TypeError(r+" is not a function");var n=i(this.constructor),e=arguments.length>1,o=!1,c=arguments[1],u=c;return new n(function(n){return t.subscribe({next:function(t){if(!n.closed){var i=!o;if(o=!0,!i||e)try{u=r(u,t)}catch(r){return n.error(r)}else u=t}},error:function(r){return n.error(r)},complete:function(){return o||e?(n.next(u),void n.complete()):void n.error(new TypeError("Cannot reduce an empty sequence"))}})})},flatMap:function(r){var t=this;if("function"!=typeof r)throw new TypeError(r+" is not a function");var n=i(this.constructor);return new n(function(n){function e(){o&&0===i.length&&n.complete()}var o=!1,i=[],c=t.subscribe({next:function(t){if(r)try{t=r(t)}catch(r){return void n.error(r)}p.from(t).subscribe({_subscription:null,start:function(r){i.push(this._subscription=r)},next:function(r){n.next(r)},error:function(r){n.error(r)},complete:function(){var r=i.indexOf(this._subscription);r>=0&&i.splice(r,1),e()}})},error:function(r){return n.error(r)},complete:function(){o=!0,e()}});return function(r){i.forEach(function(r){return r.unsubscribe()}),c.unsubscribe()}})}}),Object.defineProperty(p.prototype,e("observable"),{value:function(){return this},writable:!0,configurable:!0}),c(p,{from:function(r){var t="function"==typeof this?this:p;if(null==r)throw new TypeError(r+" is not an object");var i=o(r,e("observable"));if(i){var c=i.call(r);if(Object(c)!==c)throw new TypeError(c+" is not an object");return c.constructor===t?c:new t(function(r){return c.subscribe(r)})}if(n("iterator")&&(i=o(r,e("iterator"))))return new t(function(t){for(var n,e=i.call(r)[Symbol.iterator]();n=e.next(),!n.done;){var o=n.value;if(t.next(o),t.closed)return}t.complete()});if(Array.isArray(r))return new t(function(t){for(var n=0;n<r.length;++n)if(t.next(r[n]),t.closed)return;t.complete()});throw new TypeError(r+" is not observable")},of:function(){for(var r=[],t=0;t<arguments.length;++t)r.push(arguments[t]);var n="function"==typeof this?this:p;return new n(function(t){for(var n=0;n<r.length;++n)if(t.next(r[n]),t.closed)return;t.complete()})}}),Object.defineProperty(p,e("species"),{get:function(){return this},configurable:!0}),r.Observable=p},"*"); |
@@ -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,n,r){function i(s,u){if(!n[s]){if(!e[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[s]={exports:{}};e[s][0].call(f.exports,function(t){var n=e[s][1][t];return i(n?n:t)},f,f.exports,t,e,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(t,e,n){"use strict";function r(t){this.client=t}var i=t("xtend/mutable"),o=t("../validators"),s={image:"images",file:"files"};i(r.prototype,{upload:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};o.validateAssetType(t);var r=o.hasDataset(this.client.clientConfig),u="contentType"in n?{"Content-Type":n.contentType}:{},a=s[t];return this.client.requestObservable({method:"POST",headers:i({Accept:"application/json"},u),uri:"/assets/"+a+"/"+r,body:e,json:!1,timeout:0}).map(function(t){return"response"!==t.type?t:i({},t,{body:JSON.parse(t.body)})})}}),e.exports=r},{"../validators":18,"xtend/mutable":31}],2:[function(t,e,n){"use strict";function r(t){this.client=t}var i=t("xtend/mutable");i(r.prototype,{getLoginProviders:function(){return this.client.request({uri:"/auth/providers"})},logout:function(){return this.client.request({uri:"/auth/logout"})}}),e.exports=r},{"xtend/mutable":31}],3:[function(t,e,n){"use strict";var r=t("xtend/mutable"),i=t("./validators"),o=n.defaultConfig={apiHost:"https://api.sanity.io",useProjectHostname:!0};n.initConfig=function(t,e){var n=r({},o,e,t),s=n.useProjectHostname;if("undefined"==typeof Promise)throw new Error("No native `Promise`-implementation found, polyfill needed");if(s&&!n.projectId)throw new Error("Configuration must contain `projectId`");s&&i.projectId(n.projectId),n.dataset&&i.dataset(n.dataset);var u=n.apiHost.split("://",2),a=u[0],c=u[1];return n.useProjectHostname?n.url=a+"://"+n.projectId+"."+c+"/v1":n.url=n.apiHost+"/v1",n}},{"./validators":18,"xtend/mutable":31}],4:[function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var i=t("xtend/mutable"),o=t("../validators"),s=t("./encodeQueryString"),u=t("./transaction"),a=t("./patch"),c=t("./listen"),f=function(t){return i({returnIDs:!0},t.returnDocuments===!1?{}:{returnDocuments:!0})},l=1948;e.exports={listen:c,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:"/data/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 a(t,e,this)},delete:function(t){return o.validateDocumentId("delete",t),this.dataRequest("mutate",{mutations:[{delete:{id:t}}]})},mutate:function(t,e){var n=t instanceof a?t.serialize():t,r=Array.isArray(n)?n:[n];return this.dataRequest("mutate",{mutations:r},e)},transaction:function(t){return new u(t,this)},dataRequest:function(t,e){var n=this,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u="mutate"===t,a=!u&&s(e),c=!u&&a.length<l,d=c?a:"",p=i.returnFirst;return o.promise.hasDataset(this.clientConfig).then(function(r){return n.request({method:c?"GET":"POST",uri:"/data/"+t+"/"+r+d,json:!0,body:c?void 0:e,query:u&&f(i)})}).then(function(t){if(!u)return t;var e=t.results||[];if(i.returnDocuments)return p?e[0]&&e[0].document:e.map(function(t){return t.document});var n=p?"documentId":"documentIds",o=p?e[0]&&e[0].id:e.map(function(t){return t.id});return r({transactionId:t.transactionID},n,o)})},_create:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=o.hasDataset(this.clientConfig),u=r({},e,i({},t,{_id:t._id||s+"/"})),a=i({returnFirst:!0,returnDocuments:!0},n);return this.dataRequest("mutate",{mutations:[u]},a)}}},{"../validators":18,"./encodeQueryString":5,"./listen":6,"./patch":7,"./transaction":8,"xtend/mutable":31}],5:[function(t,e,n){"use strict";var r=encodeURIComponent;e.exports=function(t){var e=t.query,n=t.params,i=void 0===n?{}:n,o=t.options,s=void 0===o?{}:o,u=Object.keys(i).reduce(function(t,e){return t+"&"+r("$"+e)+"="+r(JSON.stringify(i[e]))},"?query="+r(e));return Object.keys(s).reduce(function(t,e){return s[e]?t+"&"+r(e)+"="+r(s[e]):t},u)}},{}],6:[function(t,e,n){"use strict";function r(t){try{var e=t.data&&JSON.parse(t.data)||{};return o({type:t.type},e)}catch(t){return t}}function i(t){if(t instanceof Error)return t;var e=r(t);return e instanceof Error?e:new Error(e.error||"Unknown listener error")}var o=t("xtend/mutable"),s=t("zen-observable"),u=t("./encodeQueryString"),a=t("../validators"),c=t("../util/pick"),f=t("../util/defaults"),l="undefined"!=typeof window&&window.EventSource?window.EventSource:t("@sanity/eventsource"),d=function(t,e,n){t.removeEventListener?t.removeEventListener(e,n,!1):t.removeListener(e,n)},p=["includePreviousRevision","includeResult"],h={includeResult:!0};e.exports=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},v=f(n,h),y=c(v,p),m=u({query:t,params:e,options:y}),b=a.hasDataset(this.clientConfig),g=this.getUrl("/data/listen/"+b+m),w=this.clientConfig.token,x=v.events?v.events:["document"],E=x.indexOf("reconnect")!==-1,_=new l(g,o({withCredentials:!0},w?{headers:{"Sanity-Token":w}}:{}));return new s(function(t){function e(e){e.data?t.error(i(e)):_.readyState===l.CLOSED?t.complete():_.readyState===l.CONNECTING&&u()}function n(e){var n=r(e);return n instanceof Error?t.error(n):t.next(n)}function o(e){t.complete(),s()}function s(){x.forEach(function(t){return d(_,t,n)}),d(_,"error",e),d(_,"disconnect",o),_.close()}function u(){E&&t.next({type:"reconnect"})}return _.addEventListener("error",e,!1),_.addEventListener("disconnect",o,!1),x.forEach(function(t){return _.addEventListener(t,n,!1)}),s})}},{"../util/defaults":16,"../util/pick":17,"../validators":18,"./encodeQueryString":5,"@sanity/eventsource":20,"xtend/mutable":31,"zen-observable":32}],7:[function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.selection=t,this.operations=u({},e),this.client=n}function o(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 for patch - must be one of:\n\n"+e)}var s=t("deep-assign"),u=t("xtend/mutable"),a=t("../validators").validateObject;u(i.prototype,{clone:function(){return new i(this.selection,u({},this.operations),this.client)},merge:function(t){return a("merge",t),this._assign("merge",s(this.operations.merge||{},t))},set:function(t){return this._assign("set",t)},setIfMissing:function(t){return this._assign("setIfMissing",t)},replace:function(t){return a("replace",t),this._set("replace",t)},inc:function(t){return this._assign("inc",t)},dec:function(t){return this._assign("dec",t)},unset:function(t){throw new Error("Not implemented yet")},append:function(t){throw new Error("Not implemented yet")},prepend:function(t){throw new Error("Not implemented yet")},splice:function(t){throw new Error("Not implemented yet")},serialize:function(){return u(o(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,n=u({returnFirst:e,returnDocuments:!0},t);return this.client.mutate({patch:this.serialize()},n)},reset:function(){return this.operations={},this},_set:function(t,e){return this._assign(t,e,!1)},_assign:function(t,e){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return a(t,e),this.operations=u({},this.operations,r({},t,u({},n&&this.operations[t]||{},e))),this}}),e.exports=i},{"../validators":18,"deep-assign":22,"xtend/mutable":31}],8:[function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments[1];this.operations=t,this.client=e}var o=t("xtend/mutable"),s=t("../validators"),u=t("./patch"),a={returnDocuments:!1};o(i.prototype,{clone:function(){return new i(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,n){var r="function"==typeof n,i=e instanceof u;if(i)return this._add({patch:e.serialize()});if(r){var t=n(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:o({id:e},n)})},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 n=s.hasDataset(this.client.clientConfig),i=r({},e,o({},t,{_id:t._id||n+"/"}));return this._add(i)},_add:function(t){return this.operations.push(t),this}}),e.exports=i},{"../validators":18,"./patch":7,"xtend/mutable":31}],9:[function(t,e,n){"use strict";function r(t){this.request=t.request.bind(t)}var i=t("xtend/mutable"),o=t("../validators");i(r.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 o.dataset(e),this.request({method:t,uri:"/datasets/"+e})}}),e.exports=r},{"../validators":18,"xtend/mutable":31}],10:[function(t,e,n){"use strict";function r(t){var e=function(e,n){return e.concat(i(n)+"="+i(t[n]))};return Object.keys(t).reduce(e,[]).join("&")}var i=function(t){return encodeURIComponent(t)};n.stringify=r},{}],11:[function(t,e,n){"use strict";function r(t){return"Server responded with HTTP "+t.statusCode+" "+(t.statusMessage||"")+", no description"}function i(t,e){var n=(e.headers["content-type"]||"").toLowerCase(),r=n.indexOf("application/json")!==-1;return r?JSON.stringify(t,null,2):t}var o=t("@sanity/request"),s=t("./queryString"),u=t("zen-observable"),a=t("xtend/mutable"),c="".indexOf("sanity")!==-1,f=function(){};e.exports=function(t){t.query&&(t.uri+="?"+s.stringify(t.query)),c&&(f("HTTP %s %s",t.method||"GET",t.uri),"POST"===t.method&&t.body&&f("Request body: %s",JSON.stringify(t.body,null,2)));var e=new u(function(e){function n(t){return function(n){var r=n.lengthComputable?n.loaded/n.total*100:-1;e.next({type:"progress",stage:t,percent:r})}}var s=a({},t,{beforeSend:function(r){t.beforeSend&&t.beforeSend(r),"upload"in r&&"onprogress"in r.upload&&(r.upload.onprogress=n("upload")),"onprogress"in r&&(r.onprogress=n("download")),r.onabort=function(){e.next({type:"abort"}),e.complete()}}}),u=o(s,function(t,n,o){if(t)return void e.error(t);f("Response code: %s",n.statusCode),c&&o&&f("Response body: %s",i(o,n));var s=n.statusCode>=400;if(s&&o){var u=(o.errors?o.errors.map(function(t){return t.message}):[]).concat([o.error,o.message]).filter(Boolean).join("\n"),a=new Error(u||r(n));return a.responseBody=i(o,n),a.statusCode=n.statusCode,void e.error(a)}if(s){var l=new Error(r(n));return l.statusCode=n.statusCode,void e.error(l)}e.next({type:"response",body:o}),e.complete()});return function(){return u.abort()}});return e.toPromise=function(){var t=void 0;return e.forEach(function(e){t=e}).then(function(){return t.body})},e}},{"./queryString":10,"@sanity/request":21,"xtend/mutable":31,"zen-observable":32}],12:[function(t,e,n){"use strict";var r="Sanity-Token",i="Sanity-Project-ID";e.exports=function(t){var e={};return t.token&&(e[r]=t.token),!t.useProjectHostname&&t.projectId&&(e[i]=t.projectId),{headers:e,timeout:"timeout"in t?t.timeout:15e3,withCredentials:!0,json:!0}}},{}],13:[function(t,e,n){"use strict";function r(t){this.client=t}var i=t("xtend/mutable");i(r.prototype,{list:function(){return this.client.request({uri:"/projects"})},getById:function(t){return this.client.request({uri:"/projects/"+t})}}),e.exports=r},{"xtend/mutable":31}],14:[function(t,e,n){"use strict";function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b;this.config(t),this.assets=new d(this),this.datasets=new f(this),this.projects=new l(this),this.users=new p(this),this.auth=new h(this)}function i(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=e.reduce(function(t,e){return t||e.headers?s(t||{},e.headers||{}):null},null);return s.apply(void 0,e.concat([r?{headers:r}:{}]))}function o(t){return new r(t)}var s=t("xtend/mutable"),u=t("./data/patch"),a=t("./data/transaction"),c=t("./data/dataMethods"),f=t("./datasets/datasetsClient"),l=t("./projects/projectsClient"),d=t("./assets/assetsClient"),p=t("./users/usersClient"),h=t("./auth/authClient"),v=t("./http/request"),y=t("./http/requestOptions"),m=t("./config"),b=m.defaultConfig,g=m.initConfig;s(r.prototype,c),s(r.prototype,{config:function(t){return"undefined"==typeof t?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 v(i(y(this.clientConfig),t,{uri:this.getUrl(t.uri)}))}}),o.Patch=u,o.Transaction=a,e.exports=o},{"./assets/assetsClient":1,"./auth/authClient":2,"./config":3,"./data/dataMethods":4,"./data/patch":7,"./data/transaction":8,"./datasets/datasetsClient":9,"./http/request":11,"./http/requestOptions":12,"./projects/projectsClient":13,"./users/usersClient":15,"xtend/mutable":31}],15:[function(t,e,n){"use strict";function r(t){this.client=t}var i=t("xtend/mutable");i(r.prototype,{getById:function(t){return this.client.request({uri:"/users/"+t})}}),e.exports=r},{"xtend/mutable":31}],16:[function(t,e,n){"use strict";e.exports=function(t,e){return Object.keys(e).concat(Object.keys(t)).reduce(function(n,r){return n[r]="undefined"==typeof t[r]?e[r]:t[r],n},{})}},{}],17:[function(t,e,n){"use strict";e.exports=function(t,e){return e.reduce(function(e,n){return"undefined"==typeof t[n]?e:(e[n]=t[n],e)},{})}},{}],18:[function(t,e,n){"use strict";var r="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=["image","file"];n.dataset=function(t){if(!/^[-\w]{1,128}$/.test(t))throw new Error("Datasets can only contain lowercase characters, numbers, underscores and dashes")},n.projectId=function(t){if(!/^[-a-z0-9]+$/i.test(t))throw new Error("`projectId` can only contain only a-z, 0-9 and dashes")},n.validateAssetType=function(t){if(i.indexOf(t)===-1)throw new Error("Invalid asset type: "+t+". Must be one of "+i.join(", "))},n.validateObject=function(t,e){if(null===e||"object"!==("undefined"==typeof e?"undefined":r(e))||Array.isArray(e))throw new Error(t+"() takes an object of properties")},n.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")},n.hasDataset=function(t){if(!t.dataset)throw new Error("`dataset` must be provided to perform queries");return t.dataset},n.promise={hasDataset:function(t){return new Promise(function(e){return e(n.hasDataset(t))})}}},{}],19:[function(t,e,n){"use strict";function r(t,e){for(var n=0;n<t.length;n++)e(t[n])}function i(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function o(t,e,n){var r=t;return l(e)?(n=e,"string"==typeof t&&(r={uri:t})):r=p(e,{uri:t}),r.callback=n,r}function s(t,e,n){return e=o(t,e,n),u(e)}function u(t){function e(){4===l.readyState&&o()}function n(){var t=void 0;if(t=l.response?l.response:l.responseText||a(l),x)try{t=JSON.parse(t)}catch(t){}return t}function r(t){return clearTimeout(v),t instanceof Error||(t=new Error(""+(t||"Unknown XMLHttpRequest Error"))),t.statusCode=0,c(t,f)}function o(){if(!h){var e;clearTimeout(v),e=t.useXDR&&void 0===l.status?200:1223===l.status?204:l.status;var r=f,i=null;return 0!==e?(r={body:n(),statusCode:e,method:m,headers:{},url:y,rawRequest:l},l.getAllResponseHeaders&&(r.headers=d(l.getAllResponseHeaders()))):i=new Error("Internal XMLHttpRequest Error"),c(i,r,r.body)}}if("undefined"==typeof t.callback)throw new Error("callback argument missing");var u=!1,c=function(e,n,r){u||(u=!0,t.callback(e,n,r))},f={body:void 0,headers:{},statusCode:0,method:m,url:y,rawRequest:l},l=t.xhr||null;l||(l=t.cors||t.useXDR?new s.XDomainRequest:new s.XMLHttpRequest);var p,h,v,y=l.url=t.uri||t.url,m=l.method=t.method||"GET",b=t.body||t.data||null,g=l.headers=t.headers||{},w=!!t.sync,x=!1;if(t.json===!0&&(x=!0,g.accept||g.Accept||(g.Accept="application/json"),"GET"!==m&&"HEAD"!==m&&(g["content-type"]||g["Content-Type"]||(g["Content-Type"]="application/json"),b=JSON.stringify(t.body))),l.onreadystatechange=e,l.onload=o,l.onerror=r,l.onprogress=function(){},l.ontimeout=r,l.open(m,y,!w,t.username,t.password),w||(l.withCredentials=!!t.withCredentials),!w&&t.timeout>0&&(v=setTimeout(function(){h=!0,l.abort("timeout");var t=new Error("XMLHttpRequest timeout");t.code="ETIMEDOUT",r(t)},t.timeout)),l.setRequestHeader)for(p in g)g.hasOwnProperty(p)&&l.setRequestHeader(p,g[p]);else if(t.headers&&!i(t.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in t&&(l.responseType=t.responseType),"beforeSend"in t&&"function"==typeof t.beforeSend&&t.beforeSend(l),l.send(b),l}function a(t){if("document"===t.responseType)return t.responseXML;var e=204===t.status&&t.responseXML&&"parsererror"===t.responseXML.documentElement.nodeName;return""!==t.responseType||e?null:t.responseXML}function c(){}var f=t("global/window"),l=t("is-function"),d=t("parse-headers"),p=t("xtend");e.exports=s,s.XMLHttpRequest=f.XMLHttpRequest||c,s.XDomainRequest="withCredentials"in new s.XMLHttpRequest?s.XMLHttpRequest:f.XDomainRequest,r(["get","put","post","patch","head","delete"],function(t){s["delete"===t?"del":t]=function(e,n,r){return n=o(e,n,r),n.method=t.toUpperCase(),u(n)}})},{"global/window":25,"is-function":26,"parse-headers":28,xtend:30}],20:[function(t,e,n){e.exports=t("eventsource-polyfill/dist/eventsource")},{"eventsource-polyfill/dist/eventsource":23}],21:[function(t,e,n){e.exports=t("@bjoerge/xhr")},{"@bjoerge/xhr":19}],22:[function(t,e,n){"use strict";function r(t){if(null===t||void 0===t)throw new TypeError("Sources cannot be null or undefined");return Object(t)}function i(t,e,n){var r=e[n];if(void 0!==r&&null!==r){if(u.call(t,n)&&(void 0===t[n]||null===t[n]))throw new TypeError("Cannot convert undefined or null to object ("+n+")");u.call(t,n)&&s(r)?t[n]=o(Object(t[n]),e[n]):t[n]=r}}function o(t,e){if(t===e)return t;e=Object(e);for(var n in e)u.call(e,n)&&i(t,e,n);if(Object.getOwnPropertySymbols)for(var r=Object.getOwnPropertySymbols(e),o=0;o<r.length;o++)a.call(e,r[o])&&i(t,e,r[o]);return t}var s=t("is-obj"),u=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;e.exports=function(t){t=r(t);for(var e=1;e<arguments.length;e++)o(t,arguments[e]);return t}},{"is-obj":27}],23:[function(t,e,n){!function(t){function e(t,e,n,r){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.data=e||null,this.origin=n||"",this.lastEventId=r||"",this.type=t||"message"}function n(){return!(!window.XDomainRequest||!window.XMLHttpRequest||void 0!==(new XMLHttpRequest).responseType)}if(!t.EventSource||t._eventSourceImportPrefix){var r=(t._eventSourceImportPrefix||"")+"EventSource",i=function(t,e){if(!t||"string"!=typeof t)throw new SyntaxError("Not enough arguments");this.URL=t,this.setOptions(e);var n=this;setTimeout(function(){n.poll()},0)};if(i.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,n=this.defaultOptions;for(e in n)n.hasOwnProperty(e)&&(this[e]=n[e]);for(e in t)e in n&&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 n=this.lastMessageIndex(e);if(n[0]>=this.cursor){var r=n[1],i=e.substring(this.cursor,r);this.parseStream(i),this.cursor=r}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 n,r,i,o,s,u,a=t.split("\n\n");for(n=0;n<a.length-1;n++){for(i="message",o=[],parts=a[n].split("\n"),r=0;r<parts.length;r++)s=this.trimWhiteSpace(parts[r]),0==s.indexOf("event")?i=s.replace(/event:?\s*/,""):0==s.indexOf("retry")?(u=parseInt(s.replace(/retry:?\s*/,"")),isNaN(u)||(this.interval=u)):0==s.indexOf("data")?o.push(s.replace(/data:?\s*/,"")):0==s.indexOf("id:")?this.lastEventId=s.replace(/id:?\s*/,""):0==s.indexOf("id")&&(this.lastEventId=null);if(o.length){var c=new e(i,o.join("\n"),window.location.origin,this.lastEventId);this.dispatchEvent(i,c)}}this.cache=a[a.length-1]},dispatchEvent:function(t,e){var n=this["_"+t+"Handlers"];if(n)for(var r=0;r<n.length;r++)n[r].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 n=this["_"+t+"Handlers"];if(n)for(var r=n.length-1;r>=0;--r)if(n[r]===e){n.splice(r,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 n=[];if(e){var r,i,o=encodeURIComponent;for(r in e)e.hasOwnProperty(r)&&(i=o(r)+"="+o(e[r]),n.push(i))}return n.length>0?t.indexOf("?")==-1?t+"?"+n.join("&"):t+"&"+n.join("&"):t},lastMessageIndex:function(t){var e=t.lastIndexOf("\n\n"),n=t.lastIndexOf("\r\r"),r=t.lastIndexOf("\r\n\r\n");return r>Math.max(e,n)?[r,r+4]:[Math.max(e,n),Math.max(e,n)+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")}},n()){i.isPolyfill="IE_8-9";var o=i.prototype.defaultOptions;o.xhrHeaders=null,o.getArgs.evs_preamble=2056,i.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 n=t.getArgs;for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r]);t.lastEventId&&(e.evs_last_event_id=t.lastEventId)}request.open("GET",t.urlWithParams(t.URL,e)),request.send()},i.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 i.isPolyfill="XHR",i.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 n in e)e.hasOwnProperty(n)&&request.setRequestHeader(n,e[n]);t.lastEventId&&request.setRequestHeader("Last-Event-Id",t.lastEventId),request.send()},i.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[r]=i}}(this)},{}],24:[function(t,e,n){function r(t,e,n){if(!u(e))throw new TypeError("iterator must be a function");arguments.length<3&&(n=this),"[object Array]"===a.call(t)?i(t,e,n):"string"==typeof t?o(t,e,n):s(t,e,n)}function i(t,e,n){for(var r=0,i=t.length;r<i;r++)c.call(t,r)&&e.call(n,t[r],r,t)}function o(t,e,n){for(var r=0,i=t.length;r<i;r++)e.call(n,t.charAt(r),r,t)}function s(t,e,n){for(var r in t)c.call(t,r)&&e.call(n,t[r],r,t)}var u=t("is-function");e.exports=r;var a=Object.prototype.toString,c=Object.prototype.hasOwnProperty},{"is-function":26}],25:[function(t,e,n){(function(t){"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:{})},{}],26:[function(t,e,n){function r(t){var e=i.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=r;var i=Object.prototype.toString},{}],27:[function(t,e,n){"use strict";e.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}},{}],28:[function(t,e,n){var r=t("trim"),i=t("for-each"),o=function(t){return"[object Array]"===Object.prototype.toString.call(t)};e.exports=function(t){if(!t)return{};var e={};return i(r(t).split("\n"),function(t){var n=t.indexOf(":"),i=r(t.slice(0,n)).toLowerCase(),s=r(t.slice(n+1));"undefined"==typeof e[i]?e[i]=s:o(e[i])?e[i].push(s):e[i]=[e[i],s]}),e}},{"for-each":24,trim:29}],29:[function(t,e,n){function r(t){return t.replace(/^\s*|\s*$/g,"")}n=e.exports=r,n.left=function(t){return t.replace(/^\s*/,"")},n.right=function(t){return t.replace(/\s*$/,"")}},{}],30:[function(t,e,n){function r(){for(var t={},e=0;e<arguments.length;e++){var n=arguments[e];for(var r in n)i.call(n,r)&&(t[r]=n[r])}return t}e.exports=r;var i=Object.prototype.hasOwnProperty},{}],31:[function(t,e,n){function r(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)i.call(n,r)&&(t[r]=n[r])}return t}e.exports=r;var i=Object.prototype.hasOwnProperty},{}],32:[function(t,e,n){e.exports=t("./zen-observable.js").Observable},{"./zen-observable.js":33}],33:[function(t,e,n){"use strict";!function(t,r){"undefined"!=typeof n?t(n,e):"undefined"!=typeof self&&t("*"===r?self:r?self[r]={}:{})}(function(t,e){function n(t){return"function"==typeof Symbol&&Boolean(Symbol[t])}function r(t){return n(t)?Symbol[t]:"@@"+t}function i(t,e){var n=t[e];if(null!=n){if("function"!=typeof n)throw new TypeError(n+" is not a function");return n}}function o(t){var e=r("species");return e?t[e]:t}function s(t,e){Object.keys(e).forEach(function(n){var r=Object.getOwnPropertyDescriptor(e,n);r.enumerable=!1,Object.defineProperty(t,n,r)})}function u(t){var e=t._cleanup;e&&(t._cleanup=void 0,e())}function a(t){return void 0===t._observer}function c(t){a(t)||(t._observer=void 0,u(t))}function f(t){return function(e){t.unsubscribe()}}function l(t,e){if(Object(t)!==t)throw new TypeError("Observer must be an object");this._cleanup=void 0,this._observer=t;var n=i(t,"start");if(n&&n.call(t,this),!a(this)){t=new d(this);try{var r=e.call(void 0,t);if(null!=r){if("function"==typeof r.unsubscribe)r=f(r);else if("function"!=typeof r)throw new TypeError(r+" is not a function");this._cleanup=r}}catch(e){return void t.error(e)}a(this)&&u(this)}}function d(t){this._subscription=t}function p(t){if("function"!=typeof t)throw new TypeError("Observable initializer must be a function");this._subscriber=t}s(l.prototype={},{get closed(){return a(this)},unsubscribe:function(){c(this)}}),s(d.prototype={},{get closed(){return a(this._subscription)},next:function(t){var e=this._subscription;if(!a(e)){var n=e._observer;try{var r=i(n,"next");if(!r)return;return r.call(n,t)}catch(t){try{c(e)}finally{throw t}}}},error:function(t){var e=this._subscription;if(a(e))throw t;var n=e._observer;e._observer=void 0;try{var r=i(n,"error");if(!r)throw t;t=r.call(n,t)}catch(t){try{u(e)}finally{throw t}}return u(e),t},complete:function(t){var e=this._subscription;if(!a(e)){var n=e._observer;e._observer=void 0;try{var r=i(n,"complete");t=r?r.call(n,t):void 0}catch(t){try{ | ||
!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,n,r){function i(s,u){if(!n[s]){if(!e[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[s]={exports:{}};e[s][0].call(f.exports,function(t){var n=e[s][1][t];return i(n?n:t)},f,f.exports,t,e,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(t,e,n){"use strict";function r(t){this.client=t}var i=t("xtend/mutable"),o=t("../validators"),s={image:"images",file:"files"};i(r.prototype,{upload:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};o.validateAssetType(t);var r=o.hasDataset(this.client.clientConfig),u="contentType"in n?{"Content-Type":n.contentType}:{},a=s[t];return this.client.requestObservable({method:"POST",headers:i({Accept:"application/json"},u),uri:"/assets/"+a+"/"+r,body:e,json:!1,timeout:0}).map(function(t){return"response"!==t.type?t:i({},t,{body:JSON.parse(t.body)})})}}),e.exports=r},{"../validators":18,"xtend/mutable":31}],2:[function(t,e,n){"use strict";function r(t){this.client=t}var i=t("xtend/mutable");i(r.prototype,{getLoginProviders:function(){return this.client.request({uri:"/auth/providers"})},logout:function(){return this.client.request({uri:"/auth/logout"})}}),e.exports=r},{"xtend/mutable":31}],3:[function(t,e,n){"use strict";var r=t("xtend/mutable"),i=t("./validators"),o=n.defaultConfig={apiHost:"https://api.sanity.io",useProjectHostname:!0};n.initConfig=function(t,e){var n=r({},o,e,t),s=n.useProjectHostname;if("undefined"==typeof Promise)throw new Error("No native `Promise`-implementation found, polyfill needed");if(s&&!n.projectId)throw new Error("Configuration must contain `projectId`");s&&i.projectId(n.projectId),n.dataset&&i.dataset(n.dataset);var u=n.apiHost.split("://",2),a=u[0],c=u[1];return n.useProjectHostname?n.url=a+"://"+n.projectId+"."+c+"/v1":n.url=n.apiHost+"/v1",n}},{"./validators":18,"xtend/mutable":31}],4:[function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var i=t("xtend/mutable"),o=t("../validators"),s=t("./encodeQueryString"),u=t("./transaction"),a=t("./patch"),c=t("./listen"),f=function(t){return i({returnIds:!0},t.returnDocuments===!1?{}:{returnDocuments:!0})},l=1948;e.exports={listen:c,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:"/data/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 a(t,e,this)},delete:function(t){return o.validateDocumentId("delete",t),this.dataRequest("mutate",{mutations:[{delete:{id:t}}]})},mutate:function(t,e){var n=t instanceof a?t.serialize():t,r=Array.isArray(n)?n:[n];return this.dataRequest("mutate",{mutations:r},e)},transaction:function(t){return new u(t,this)},dataRequest:function(t,e){var n=this,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u="mutate"===t,a=!u&&s(e),c=!u&&a.length<l,d=c?a:"",p=i.returnFirst;return o.promise.hasDataset(this.clientConfig).then(function(r){return n.request({method:c?"GET":"POST",uri:"/data/"+t+"/"+r+d,json:!0,body:c?void 0:e,query:u&&f(i)})}).then(function(t){if(!u)return t;var e=t.results||[];if(i.returnDocuments)return p?e[0]&&e[0].document:e.map(function(t){return t.document});var n=p?"documentId":"documentIds",o=p?e[0]&&e[0].id:e.map(function(t){return t.id});return r({transactionId:t.transactionId},n,o)})},_create:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=o.hasDataset(this.clientConfig),u=r({},e,i({},t,{_id:t._id||s+"/"})),a=i({returnFirst:!0,returnDocuments:!0},n);return this.dataRequest("mutate",{mutations:[u]},a)}}},{"../validators":18,"./encodeQueryString":5,"./listen":6,"./patch":7,"./transaction":8,"xtend/mutable":31}],5:[function(t,e,n){"use strict";var r=encodeURIComponent;e.exports=function(t){var e=t.query,n=t.params,i=void 0===n?{}:n,o=t.options,s=void 0===o?{}:o,u=Object.keys(i).reduce(function(t,e){return t+"&"+r("$"+e)+"="+r(JSON.stringify(i[e]))},"?query="+r(e));return Object.keys(s).reduce(function(t,e){return s[e]?t+"&"+r(e)+"="+r(s[e]):t},u)}},{}],6:[function(t,e,n){"use strict";function r(t){try{var e=t.data&&JSON.parse(t.data)||{};return o({type:t.type},e)}catch(t){return t}}function i(t){if(t instanceof Error)return t;var e=r(t);return e instanceof Error?e:new Error(e.error||"Unknown listener error")}var o=t("xtend/mutable"),s=t("zen-observable"),u=t("./encodeQueryString"),a=t("../validators"),c=t("../util/pick"),f=t("../util/defaults"),l="undefined"!=typeof window&&window.EventSource?window.EventSource:t("@sanity/eventsource"),d=function(t,e,n){t.removeEventListener?t.removeEventListener(e,n,!1):t.removeListener(e,n)},p=["includePreviousRevision","includeResult"],h={includeResult:!0};e.exports=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},v=f(n,h),y=c(v,p),m=u({query:t,params:e,options:y}),b=a.hasDataset(this.clientConfig),g=this.getUrl("/data/listen/"+b+m),w=this.clientConfig.token,x=v.events?v.events:["document"],E=x.indexOf("reconnect")!==-1,_=new l(g,o({withCredentials:!0},w?{headers:{"Sanity-Token":w}}:{}));return new s(function(t){function e(e){e.data?t.error(i(e)):_.readyState===l.CLOSED?t.complete():_.readyState===l.CONNECTING&&u()}function n(e){var n=r(e);return n instanceof Error?t.error(n):t.next(n)}function o(e){t.complete(),s()}function s(){x.forEach(function(t){return d(_,t,n)}),d(_,"error",e),d(_,"disconnect",o),_.close()}function u(){E&&t.next({type:"reconnect"})}return _.addEventListener("error",e,!1),_.addEventListener("disconnect",o,!1),x.forEach(function(t){return _.addEventListener(t,n,!1)}),s})}},{"../util/defaults":16,"../util/pick":17,"../validators":18,"./encodeQueryString":5,"@sanity/eventsource":20,"xtend/mutable":31,"zen-observable":32}],7:[function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.selection=t,this.operations=u({},e),this.client=n}function o(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 for patch - must be one of:\n\n"+e)}var s=t("deep-assign"),u=t("xtend/mutable"),a=t("../validators").validateObject;u(i.prototype,{clone:function(){return new i(this.selection,u({},this.operations),this.client)},merge:function(t){return a("merge",t),this._assign("merge",s(this.operations.merge||{},t))},set:function(t){return this._assign("set",t)},setIfMissing:function(t){return this._assign("setIfMissing",t)},replace:function(t){return a("replace",t),this._set("replace",t)},inc:function(t){return this._assign("inc",t)},dec:function(t){return this._assign("dec",t)},unset:function(t){throw new Error("Not implemented yet")},append:function(t){throw new Error("Not implemented yet")},prepend:function(t){throw new Error("Not implemented yet")},splice:function(t){throw new Error("Not implemented yet")},serialize:function(){return u(o(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,n=u({returnFirst:e,returnDocuments:!0},t);return this.client.mutate({patch:this.serialize()},n)},reset:function(){return this.operations={},this},_set:function(t,e){return this._assign(t,e,!1)},_assign:function(t,e){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return a(t,e),this.operations=u({},this.operations,r({},t,u({},n&&this.operations[t]||{},e))),this}}),e.exports=i},{"../validators":18,"deep-assign":22,"xtend/mutable":31}],8:[function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments[1];this.operations=t,this.client=e}var o=t("xtend/mutable"),s=t("../validators"),u=t("./patch"),a={returnDocuments:!1};o(i.prototype,{clone:function(){return new i(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,n){var r="function"==typeof n,i=e instanceof u;if(i)return this._add({patch:e.serialize()});if(r){var t=n(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:o({id:e},n)})},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 n=s.hasDataset(this.client.clientConfig),i=r({},e,o({},t,{_id:t._id||n+"/"}));return this._add(i)},_add:function(t){return this.operations.push(t),this}}),e.exports=i},{"../validators":18,"./patch":7,"xtend/mutable":31}],9:[function(t,e,n){"use strict";function r(t){this.request=t.request.bind(t)}var i=t("xtend/mutable"),o=t("../validators");i(r.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 o.dataset(e),this.request({method:t,uri:"/datasets/"+e})}}),e.exports=r},{"../validators":18,"xtend/mutable":31}],10:[function(t,e,n){"use strict";function r(t){var e=function(e,n){return e.concat(i(n)+"="+i(t[n]))};return Object.keys(t).reduce(e,[]).join("&")}var i=function(t){return encodeURIComponent(t)};n.stringify=r},{}],11:[function(t,e,n){"use strict";function r(t){return"Server responded with HTTP "+t.statusCode+" "+(t.statusMessage||"")+", no description"}function i(t,e){var n=(e.headers["content-type"]||"").toLowerCase(),r=n.indexOf("application/json")!==-1;return r?JSON.stringify(t,null,2):t}var o=t("@sanity/request"),s=t("./queryString"),u=t("zen-observable"),a=t("xtend/mutable"),c="".indexOf("sanity")!==-1,f=function(){};e.exports=function(t){t.query&&(t.uri+="?"+s.stringify(t.query)),c&&(f("HTTP %s %s",t.method||"GET",t.uri),"POST"===t.method&&t.body&&f("Request body: %s",JSON.stringify(t.body,null,2)));var e=new u(function(e){function n(t){return function(n){var r=n.lengthComputable?n.loaded/n.total*100:-1;e.next({type:"progress",stage:t,percent:r})}}var s=a({},t,{beforeSend:function(r){t.beforeSend&&t.beforeSend(r),"upload"in r&&"onprogress"in r.upload&&(r.upload.onprogress=n("upload")),"onprogress"in r&&(r.onprogress=n("download")),r.onabort=function(){e.next({type:"abort"}),e.complete()}}}),u=o(s,function(t,n,o){if(t)return void e.error(t);f("Response code: %s",n.statusCode),c&&o&&f("Response body: %s",i(o,n));var s=n.statusCode>=400;if(s&&o){var u=(o.errors?o.errors.map(function(t){return t.message}):[]).concat([o.error,o.message]).filter(Boolean).join("\n"),a=new Error(u||r(n));return a.responseBody=i(o,n),a.statusCode=n.statusCode,void e.error(a)}if(s){var l=new Error(r(n));return l.statusCode=n.statusCode,void e.error(l)}e.next({type:"response",body:o}),e.complete()});return function(){return u.abort()}});return e.toPromise=function(){var t=void 0;return e.forEach(function(e){t=e}).then(function(){return t.body})},e}},{"./queryString":10,"@sanity/request":21,"xtend/mutable":31,"zen-observable":32}],12:[function(t,e,n){"use strict";var r="Sanity-Token",i="Sanity-Project-ID";e.exports=function(t){var e={};return t.token&&(e[r]=t.token),!t.useProjectHostname&&t.projectId&&(e[i]=t.projectId),{headers:e,timeout:"timeout"in t?t.timeout:15e3,withCredentials:!0,json:!0}}},{}],13:[function(t,e,n){"use strict";function r(t){this.client=t}var i=t("xtend/mutable");i(r.prototype,{list:function(){return this.client.request({uri:"/projects"})},getById:function(t){return this.client.request({uri:"/projects/"+t})}}),e.exports=r},{"xtend/mutable":31}],14:[function(t,e,n){"use strict";function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b;this.config(t),this.assets=new d(this),this.datasets=new f(this),this.projects=new l(this),this.users=new p(this),this.auth=new h(this)}function i(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=e.reduce(function(t,e){return t||e.headers?s(t||{},e.headers||{}):null},null);return s.apply(void 0,e.concat([r?{headers:r}:{}]))}function o(t){return new r(t)}var s=t("xtend/mutable"),u=t("./data/patch"),a=t("./data/transaction"),c=t("./data/dataMethods"),f=t("./datasets/datasetsClient"),l=t("./projects/projectsClient"),d=t("./assets/assetsClient"),p=t("./users/usersClient"),h=t("./auth/authClient"),v=t("./http/request"),y=t("./http/requestOptions"),m=t("./config"),b=m.defaultConfig,g=m.initConfig;s(r.prototype,c),s(r.prototype,{config:function(t){return"undefined"==typeof t?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 v(i(y(this.clientConfig),t,{uri:this.getUrl(t.uri)}))}}),o.Patch=u,o.Transaction=a,e.exports=o},{"./assets/assetsClient":1,"./auth/authClient":2,"./config":3,"./data/dataMethods":4,"./data/patch":7,"./data/transaction":8,"./datasets/datasetsClient":9,"./http/request":11,"./http/requestOptions":12,"./projects/projectsClient":13,"./users/usersClient":15,"xtend/mutable":31}],15:[function(t,e,n){"use strict";function r(t){this.client=t}var i=t("xtend/mutable");i(r.prototype,{getById:function(t){return this.client.request({uri:"/users/"+t})}}),e.exports=r},{"xtend/mutable":31}],16:[function(t,e,n){"use strict";e.exports=function(t,e){return Object.keys(e).concat(Object.keys(t)).reduce(function(n,r){return n[r]="undefined"==typeof t[r]?e[r]:t[r],n},{})}},{}],17:[function(t,e,n){"use strict";e.exports=function(t,e){return e.reduce(function(e,n){return"undefined"==typeof t[n]?e:(e[n]=t[n],e)},{})}},{}],18:[function(t,e,n){"use strict";var r="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=["image","file"];n.dataset=function(t){if(!/^[-\w]{1,128}$/.test(t))throw new Error("Datasets can only contain lowercase characters, numbers, underscores and dashes")},n.projectId=function(t){if(!/^[-a-z0-9]+$/i.test(t))throw new Error("`projectId` can only contain only a-z, 0-9 and dashes")},n.validateAssetType=function(t){if(i.indexOf(t)===-1)throw new Error("Invalid asset type: "+t+". Must be one of "+i.join(", "))},n.validateObject=function(t,e){if(null===e||"object"!==("undefined"==typeof e?"undefined":r(e))||Array.isArray(e))throw new Error(t+"() takes an object of properties")},n.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")},n.hasDataset=function(t){if(!t.dataset)throw new Error("`dataset` must be provided to perform queries");return t.dataset},n.promise={hasDataset:function(t){return new Promise(function(e){return e(n.hasDataset(t))})}}},{}],19:[function(t,e,n){"use strict";function r(t,e){for(var n=0;n<t.length;n++)e(t[n])}function i(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function o(t,e,n){var r=t;return l(e)?(n=e,"string"==typeof t&&(r={uri:t})):r=p(e,{uri:t}),r.callback=n,r}function s(t,e,n){return e=o(t,e,n),u(e)}function u(t){function e(){4===l.readyState&&o()}function n(){var t=void 0;if(t=l.response?l.response:l.responseText||a(l),x)try{t=JSON.parse(t)}catch(t){}return t}function r(t){return clearTimeout(v),t instanceof Error||(t=new Error(""+(t||"Unknown XMLHttpRequest Error"))),t.statusCode=0,c(t,f)}function o(){if(!h){var e;clearTimeout(v),e=t.useXDR&&void 0===l.status?200:1223===l.status?204:l.status;var r=f,i=null;return 0!==e?(r={body:n(),statusCode:e,method:m,headers:{},url:y,rawRequest:l},l.getAllResponseHeaders&&(r.headers=d(l.getAllResponseHeaders()))):i=new Error("Internal XMLHttpRequest Error"),c(i,r,r.body)}}if("undefined"==typeof t.callback)throw new Error("callback argument missing");var u=!1,c=function(e,n,r){u||(u=!0,t.callback(e,n,r))},f={body:void 0,headers:{},statusCode:0,method:m,url:y,rawRequest:l},l=t.xhr||null;l||(l=t.cors||t.useXDR?new s.XDomainRequest:new s.XMLHttpRequest);var p,h,v,y=l.url=t.uri||t.url,m=l.method=t.method||"GET",b=t.body||t.data||null,g=l.headers=t.headers||{},w=!!t.sync,x=!1;if(t.json===!0&&(x=!0,g.accept||g.Accept||(g.Accept="application/json"),"GET"!==m&&"HEAD"!==m&&(g["content-type"]||g["Content-Type"]||(g["Content-Type"]="application/json"),b=JSON.stringify(t.body))),l.onreadystatechange=e,l.onload=o,l.onerror=r,l.onprogress=function(){},l.ontimeout=r,l.open(m,y,!w,t.username,t.password),w||(l.withCredentials=!!t.withCredentials),!w&&t.timeout>0&&(v=setTimeout(function(){h=!0,l.abort("timeout");var t=new Error("XMLHttpRequest timeout");t.code="ETIMEDOUT",r(t)},t.timeout)),l.setRequestHeader)for(p in g)g.hasOwnProperty(p)&&l.setRequestHeader(p,g[p]);else if(t.headers&&!i(t.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in t&&(l.responseType=t.responseType),"beforeSend"in t&&"function"==typeof t.beforeSend&&t.beforeSend(l),l.send(b),l}function a(t){if("document"===t.responseType)return t.responseXML;var e=204===t.status&&t.responseXML&&"parsererror"===t.responseXML.documentElement.nodeName;return""!==t.responseType||e?null:t.responseXML}function c(){}var f=t("global/window"),l=t("is-function"),d=t("parse-headers"),p=t("xtend");e.exports=s,s.XMLHttpRequest=f.XMLHttpRequest||c,s.XDomainRequest="withCredentials"in new s.XMLHttpRequest?s.XMLHttpRequest:f.XDomainRequest,r(["get","put","post","patch","head","delete"],function(t){s["delete"===t?"del":t]=function(e,n,r){return n=o(e,n,r),n.method=t.toUpperCase(),u(n)}})},{"global/window":25,"is-function":26,"parse-headers":28,xtend:30}],20:[function(t,e,n){e.exports=t("eventsource-polyfill/dist/eventsource")},{"eventsource-polyfill/dist/eventsource":23}],21:[function(t,e,n){e.exports=t("@bjoerge/xhr")},{"@bjoerge/xhr":19}],22:[function(t,e,n){"use strict";function r(t){if(null===t||void 0===t)throw new TypeError("Sources cannot be null or undefined");return Object(t)}function i(t,e,n){var r=e[n];if(void 0!==r&&null!==r){if(u.call(t,n)&&(void 0===t[n]||null===t[n]))throw new TypeError("Cannot convert undefined or null to object ("+n+")");u.call(t,n)&&s(r)?t[n]=o(Object(t[n]),e[n]):t[n]=r}}function o(t,e){if(t===e)return t;e=Object(e);for(var n in e)u.call(e,n)&&i(t,e,n);if(Object.getOwnPropertySymbols)for(var r=Object.getOwnPropertySymbols(e),o=0;o<r.length;o++)a.call(e,r[o])&&i(t,e,r[o]);return t}var s=t("is-obj"),u=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;e.exports=function(t){t=r(t);for(var e=1;e<arguments.length;e++)o(t,arguments[e]);return t}},{"is-obj":27}],23:[function(t,e,n){!function(t){function e(t,e,n,r){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.data=e||null,this.origin=n||"",this.lastEventId=r||"",this.type=t||"message"}function n(){return!(!window.XDomainRequest||!window.XMLHttpRequest||void 0!==(new XMLHttpRequest).responseType)}if(!t.EventSource||t._eventSourceImportPrefix){var r=(t._eventSourceImportPrefix||"")+"EventSource",i=function(t,e){if(!t||"string"!=typeof t)throw new SyntaxError("Not enough arguments");this.URL=t,this.setOptions(e);var n=this;setTimeout(function(){n.poll()},0)};if(i.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,n=this.defaultOptions;for(e in n)n.hasOwnProperty(e)&&(this[e]=n[e]);for(e in t)e in n&&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 n=this.lastMessageIndex(e);if(n[0]>=this.cursor){var r=n[1],i=e.substring(this.cursor,r);this.parseStream(i),this.cursor=r}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 n,r,i,o,s,u,a=t.split("\n\n");for(n=0;n<a.length-1;n++){for(i="message",o=[],parts=a[n].split("\n"),r=0;r<parts.length;r++)s=this.trimWhiteSpace(parts[r]),0==s.indexOf("event")?i=s.replace(/event:?\s*/,""):0==s.indexOf("retry")?(u=parseInt(s.replace(/retry:?\s*/,"")),isNaN(u)||(this.interval=u)):0==s.indexOf("data")?o.push(s.replace(/data:?\s*/,"")):0==s.indexOf("id:")?this.lastEventId=s.replace(/id:?\s*/,""):0==s.indexOf("id")&&(this.lastEventId=null);if(o.length){var c=new e(i,o.join("\n"),window.location.origin,this.lastEventId);this.dispatchEvent(i,c)}}this.cache=a[a.length-1]},dispatchEvent:function(t,e){var n=this["_"+t+"Handlers"];if(n)for(var r=0;r<n.length;r++)n[r].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 n=this["_"+t+"Handlers"];if(n)for(var r=n.length-1;r>=0;--r)if(n[r]===e){n.splice(r,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 n=[];if(e){var r,i,o=encodeURIComponent;for(r in e)e.hasOwnProperty(r)&&(i=o(r)+"="+o(e[r]),n.push(i))}return n.length>0?t.indexOf("?")==-1?t+"?"+n.join("&"):t+"&"+n.join("&"):t},lastMessageIndex:function(t){var e=t.lastIndexOf("\n\n"),n=t.lastIndexOf("\r\r"),r=t.lastIndexOf("\r\n\r\n");return r>Math.max(e,n)?[r,r+4]:[Math.max(e,n),Math.max(e,n)+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")}},n()){i.isPolyfill="IE_8-9";var o=i.prototype.defaultOptions;o.xhrHeaders=null,o.getArgs.evs_preamble=2056,i.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 n=t.getArgs;for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r]);t.lastEventId&&(e.evs_last_event_id=t.lastEventId)}request.open("GET",t.urlWithParams(t.URL,e)),request.send()},i.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 i.isPolyfill="XHR",i.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 n in e)e.hasOwnProperty(n)&&request.setRequestHeader(n,e[n]);t.lastEventId&&request.setRequestHeader("Last-Event-Id",t.lastEventId),request.send()},i.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[r]=i}}(this)},{}],24:[function(t,e,n){function r(t,e,n){if(!u(e))throw new TypeError("iterator must be a function");arguments.length<3&&(n=this),"[object Array]"===a.call(t)?i(t,e,n):"string"==typeof t?o(t,e,n):s(t,e,n)}function i(t,e,n){for(var r=0,i=t.length;r<i;r++)c.call(t,r)&&e.call(n,t[r],r,t)}function o(t,e,n){for(var r=0,i=t.length;r<i;r++)e.call(n,t.charAt(r),r,t)}function s(t,e,n){for(var r in t)c.call(t,r)&&e.call(n,t[r],r,t)}var u=t("is-function");e.exports=r;var a=Object.prototype.toString,c=Object.prototype.hasOwnProperty},{"is-function":26}],25:[function(t,e,n){(function(t){"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:{})},{}],26:[function(t,e,n){function r(t){var e=i.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=r;var i=Object.prototype.toString},{}],27:[function(t,e,n){"use strict";e.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}},{}],28:[function(t,e,n){var r=t("trim"),i=t("for-each"),o=function(t){return"[object Array]"===Object.prototype.toString.call(t)};e.exports=function(t){if(!t)return{};var e={};return i(r(t).split("\n"),function(t){var n=t.indexOf(":"),i=r(t.slice(0,n)).toLowerCase(),s=r(t.slice(n+1));"undefined"==typeof e[i]?e[i]=s:o(e[i])?e[i].push(s):e[i]=[e[i],s]}),e}},{"for-each":24,trim:29}],29:[function(t,e,n){function r(t){return t.replace(/^\s*|\s*$/g,"")}n=e.exports=r,n.left=function(t){return t.replace(/^\s*/,"")},n.right=function(t){return t.replace(/\s*$/,"")}},{}],30:[function(t,e,n){function r(){for(var t={},e=0;e<arguments.length;e++){var n=arguments[e];for(var r in n)i.call(n,r)&&(t[r]=n[r])}return t}e.exports=r;var i=Object.prototype.hasOwnProperty},{}],31:[function(t,e,n){function r(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)i.call(n,r)&&(t[r]=n[r])}return t}e.exports=r;var i=Object.prototype.hasOwnProperty},{}],32:[function(t,e,n){e.exports=t("./zen-observable.js").Observable},{"./zen-observable.js":33}],33:[function(t,e,n){"use strict";!function(t,r){"undefined"!=typeof n?t(n,e):"undefined"!=typeof self&&t("*"===r?self:r?self[r]={}:{})}(function(t,e){function n(t){return"function"==typeof Symbol&&Boolean(Symbol[t])}function r(t){return n(t)?Symbol[t]:"@@"+t}function i(t,e){var n=t[e];if(null!=n){if("function"!=typeof n)throw new TypeError(n+" is not a function");return n}}function o(t){var e=r("species");return e?t[e]:t}function s(t,e){Object.keys(e).forEach(function(n){var r=Object.getOwnPropertyDescriptor(e,n);r.enumerable=!1,Object.defineProperty(t,n,r)})}function u(t){var e=t._cleanup;e&&(t._cleanup=void 0,e())}function a(t){return void 0===t._observer}function c(t){a(t)||(t._observer=void 0,u(t))}function f(t){return function(e){t.unsubscribe()}}function l(t,e){if(Object(t)!==t)throw new TypeError("Observer must be an object");this._cleanup=void 0,this._observer=t;var n=i(t,"start");if(n&&n.call(t,this),!a(this)){t=new d(this);try{var r=e.call(void 0,t);if(null!=r){if("function"==typeof r.unsubscribe)r=f(r);else if("function"!=typeof r)throw new TypeError(r+" is not a function");this._cleanup=r}}catch(e){return void t.error(e)}a(this)&&u(this)}}function d(t){this._subscription=t}function p(t){if("function"!=typeof t)throw new TypeError("Observable initializer must be a function");this._subscriber=t}s(l.prototype={},{get closed(){return a(this)},unsubscribe:function(){c(this)}}),s(d.prototype={},{get closed(){return a(this._subscription)},next:function(t){var e=this._subscription;if(!a(e)){var n=e._observer;try{var r=i(n,"next");if(!r)return;return r.call(n,t)}catch(t){try{c(e)}finally{throw t}}}},error:function(t){var e=this._subscription;if(a(e))throw t;var n=e._observer;e._observer=void 0;try{var r=i(n,"error");if(!r)throw t;t=r.call(n,t)}catch(t){try{u(e)}finally{throw t}}return u(e),t},complete:function(t){var e=this._subscription;if(!a(e)){var n=e._observer;e._observer=void 0;try{var r=i(n,"complete");t=r?r.call(n,t):void 0}catch(t){try{ | ||
u(e)}finally{throw t}}return u(e),t}}}),s(p.prototype,{subscribe:function(t){for(var e=[],n=1;n<arguments.length;++n)e.push(arguments[n]);return"function"==typeof t&&(t={next:t,error:e[0],complete:e[1]}),new l(t,this._subscriber)},forEach:function(t){var e=this;return new Promise(function(n,r){return"function"!=typeof t?Promise.reject(new TypeError(t+" is not a function")):void e.subscribe({_subscription:null,start:function(t){if(Object(t)!==t)throw new TypeError(t+" is not an object");this._subscription=t},next:function(e){var n=this._subscription;if(!n.closed)try{return t(e)}catch(t){r(t),n.unsubscribe()}},error:r,complete:n})})},map:function(t){var e=this;if("function"!=typeof t)throw new TypeError(t+" is not a function");var n=o(this.constructor);return new n(function(n){return e.subscribe({next:function(e){if(!n.closed){try{e=t(e)}catch(t){return n.error(t)}return n.next(e)}},error:function(t){return n.error(t)},complete:function(t){return n.complete(t)}})})},filter:function(t){var e=this;if("function"!=typeof t)throw new TypeError(t+" is not a function");var n=o(this.constructor);return new n(function(n){return e.subscribe({next:function(e){if(!n.closed){try{if(!t(e))return}catch(t){return n.error(t)}return n.next(e)}},error:function(t){return n.error(t)},complete:function(){return n.complete()}})})},reduce:function(t){var e=this;if("function"!=typeof t)throw new TypeError(t+" is not a function");var n=o(this.constructor),r=arguments.length>1,i=!1,s=arguments[1],u=s;return new n(function(n){return e.subscribe({next:function(e){if(!n.closed){var o=!i;if(i=!0,!o||r)try{u=t(u,e)}catch(t){return n.error(t)}else u=e}},error:function(t){return n.error(t)},complete:function(){return i||r?(n.next(u),void n.complete()):void n.error(new TypeError("Cannot reduce an empty sequence"))}})})},flatMap:function(t){var e=this;if("function"!=typeof t)throw new TypeError(t+" is not a function");var n=o(this.constructor);return new n(function(n){function r(){i&&0===o.length&&n.complete()}var i=!1,o=[],s=e.subscribe({next:function(e){if(t)try{e=t(e)}catch(t){return void n.error(t)}p.from(e).subscribe({_subscription:null,start:function(t){o.push(this._subscription=t)},next:function(t){n.next(t)},error:function(t){n.error(t)},complete:function(){var t=o.indexOf(this._subscription);t>=0&&o.splice(t,1),r()}})},error:function(t){return n.error(t)},complete:function(){i=!0,r()}});return function(t){o.forEach(function(t){return t.unsubscribe()}),s.unsubscribe()}})}}),Object.defineProperty(p.prototype,r("observable"),{value:function(){return this},writable:!0,configurable:!0}),s(p,{from:function(t){var e="function"==typeof this?this:p;if(null==t)throw new TypeError(t+" is not an object");var o=i(t,r("observable"));if(o){var s=o.call(t);if(Object(s)!==s)throw new TypeError(s+" is not an object");return s.constructor===e?s:new e(function(t){return s.subscribe(t)})}if(n("iterator")&&(o=i(t,r("iterator"))))return new e(function(e){for(var n,r=o.call(t)[Symbol.iterator]();n=r.next(),!n.done;){var i=n.value;if(e.next(i),e.closed)return}e.complete()});if(Array.isArray(t))return new e(function(e){for(var n=0;n<t.length;++n)if(e.next(t[n]),e.closed)return;e.complete()});throw new TypeError(t+" is not observable")},of:function(){for(var t=[],e=0;e<arguments.length;++e)t.push(arguments[e]);var n="function"==typeof this?this:p;return new n(function(e){for(var n=0;n<t.length;++n)if(e.next(t[n]),e.closed)return;e.complete()})}}),Object.defineProperty(p,r("species"),{get:function(){return this},configurable:!0}),t.Observable=p},"*")},{}]},{},[14])(14)}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
355906