@sanity/client
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -6,7 +6,9 @@ 'use strict'; | ||
var assign = require('xtend/mutable'); | ||
var validators = require('../validators'); | ||
var encodeQueryString = require('./encodeQueryString'); | ||
var Transaction = require('./transaction'); | ||
var Patch = require('./patch'); | ||
var validators = require('../validators'); | ||
var mutationDefaults = { returnIds: true }; | ||
var getQuerySizeLimit = 1948; | ||
@@ -54,10 +56,17 @@ function DataClient(client) { | ||
var query = endpoint === 'm' && mutationDefaults; | ||
var isMutation = endpoint === 'm'; | ||
// Check if the query string is within a configured threshold, | ||
// in which case we can use GET. Otherwise, use POST. | ||
var strQuery = !isMutation && encodeQueryString(body); | ||
var useGet = !isMutation && strQuery.length < getQuerySizeLimit; | ||
var stringQuery = useGet ? strQuery : ''; | ||
return this.client.emit('request', method, body).then(function () { | ||
var dataset = validators.hasDataset(_this.client.clientConfig); | ||
return _this.client.request({ | ||
method: 'POST', | ||
uri: '/data/' + endpoint + '/' + dataset, | ||
json: body, | ||
query: query | ||
method: useGet ? 'GET' : 'POST', | ||
uri: '/data/' + endpoint + '/' + dataset + stringQuery, | ||
json: useGet ? true : body, | ||
query: isMutation && mutationDefaults | ||
}); | ||
@@ -64,0 +73,0 @@ }); |
@@ -6,4 +6,4 @@ 'use strict'; | ||
var assign = require('xtend/mutable'); | ||
var validators = require('../validators'); | ||
var Patch = require('./patch'); | ||
var validators = require('../validators'); | ||
@@ -10,0 +10,0 @@ function Transaction() { |
{ | ||
"name": "@sanity/client", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Client for retrieving data from Sanity", | ||
@@ -5,0 +5,0 @@ "main": "lib/sanityClient.js", |
@@ -164,4 +164,5 @@ const test = require('tape') | ||
const params = {beerName: 'Headroom Double IPA'} | ||
const qs = 'beerfiesta.beer%5B.title%20%3D%3D%20%25beerName%5D&beerName=%22Headroom%20Double%20IPA%22' | ||
nock(projectHost()).post('/v1/data/q/foo', {query, params}).reply(200, { | ||
nock(projectHost()).get(`/v1/data/q/foo?query=${qs}`).reply(200, { | ||
ms: 123, | ||
@@ -186,3 +187,3 @@ q: query, | ||
nock(projectHost()).post('/v1/data/q/foo', {query: 'area51'}).reply(403, response) | ||
nock(projectHost()).get('/v1/data/q/foo?query=area51').reply(403, response) | ||
@@ -202,5 +203,5 @@ getClient().data.fetch('area51') | ||
const query = '*[.$id == %id]' | ||
const params = {id: 'foo:123'} | ||
const qs = '?query=*%5B.%24id%20%3D%3D%20%25id%5D&id=%22foo%3A123%22' | ||
nock(projectHost()).post('/v1/data/q/foo', {query, params}).reply(200, { | ||
nock(projectHost()).get(`/v1/data/q/foo${qs}`).reply(200, { | ||
ms: 123, | ||
@@ -218,3 +219,5 @@ q: query, | ||
test('joins multi-error into one message', t => { | ||
nock(projectHost()).post('/v1/data/q/foo').reply(400, { | ||
const qs = '?query=*%5B.%24id%20%3D%3D%20%25id%5D&id=%22foo%3A123%22' | ||
nock(projectHost()).get(`/v1/data/q/foo${qs}`).reply(400, { | ||
statusCode: 400, | ||
@@ -235,3 +238,4 @@ errors: [{message: '2 slow'}, {message: '2 placid'}] | ||
test('gives http statuscode as error if no body is present on >= 400', t => { | ||
nock(projectHost()).post('/v1/data/q/foo').reply(500) | ||
const qs = '?query=*%5B.%24id%20%3D%3D%20%25id%5D&id=%22foo%3A123%22' | ||
nock(projectHost()).get(`/v1/data/q/foo${qs}`).reply(500) | ||
@@ -248,3 +252,4 @@ getClient().data.getDocument('foo:123') | ||
test('populates response body on errors', t => { | ||
nock(projectHost()).post('/v1/data/q/foo').reply(500, 'Internal Server Error') | ||
const qs = '?query=*%5B.%24id%20%3D%3D%20%25id%5D&id=%22foo%3A123%22' | ||
nock(projectHost()).get(`/v1/data/q/foo${qs}`).reply(500, 'Internal Server Error') | ||
@@ -351,2 +356,30 @@ getClient().data.getDocument('foo:123') | ||
test('uses POST for long queries', t => { | ||
// Please dont ever do this. Just... don't. | ||
const clause = [] | ||
const params = {} | ||
for (let i = 1866; i <= 2016; i++) { | ||
clause.push(`.title == %beerName${i}`) | ||
params[`beerName${i}`] = `some beer ${i}` | ||
} | ||
// Again, just... don't do this. | ||
const query = `beerfiesta.beer[${clause.join(' || ')}]` | ||
nock(projectHost()) | ||
.filteringRequestBody(/.*/, '*') | ||
.post('/v1/data/q/foo', '*') | ||
.reply(200, { | ||
ms: 123, | ||
q: query, | ||
result: [{$id: 'beerfiesta.beer:njgNkngskjg', rating: 5}] | ||
}) | ||
getClient().data.fetch(query, params).then(res => { | ||
t.equal(res.length, 1, 'length should match') | ||
t.equal(res[0].rating, 5, 'data should match') | ||
t.end() | ||
}).catch(t.ifError) | ||
}) | ||
/***************** | ||
@@ -703,7 +736,6 @@ * PATCH OPS * | ||
test('includes token if set', t => { | ||
const qs = '?query=foo.bar' | ||
const token = 'abcdefghijklmnopqrstuvwxyz' | ||
const reqheaders = {'Sanity-Token': token} | ||
nock(projectHost(), {reqheaders}) | ||
.post('/v1/data/q/foo', {query: 'foo.bar'}) | ||
.reply(200, {}) | ||
nock(projectHost(), {reqheaders}).get(`/v1/data/q/foo${qs}`).reply(200, {}) | ||
@@ -710,0 +742,0 @@ getClient({token}).data.fetch('foo.bar') |
(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){ | ||
"use strict";function AuthClient(t){this.client=t}var assign=require("xtend/mutable");assign(AuthClient.prototype,{getLoginProviders:function(){return this.client.request({uri:"/auth/providers"})},logout:function(){return this.client.request({uri:"/auth/logout"})}}),module.exports=AuthClient; | ||
},{"xtend/mutable":24}],2:[function(require,module,exports){ | ||
},{"xtend/mutable":25}],2:[function(require,module,exports){ | ||
"use strict";var assign=require("xtend/mutable"),validate=require("./validators"),defaultConfig=exports.defaultConfig={apiHost:"https://api.sanity.io",useProjectHostname:!0,promise:Promise};exports.initConfig=function(e,t){var o=assign({},defaultConfig,t,e),i=o.useProjectHostname;if(!o.promise&&"undefined"==typeof Promise)throw new Error("No native `Promise`-implementation found, polyfill needed");if(i&&!o.projectId)throw new Error("Configuration must contain `projectId`");i&&validate.projectId(o.projectId),o.dataset&&validate.dataset(o.dataset);var r=o.apiHost.split("://",2),a=r[0],s=r[1];return o.useProjectHostname?o.url=a+"://"+o.projectId+"."+s+"/v1":o.url=o.apiHost+"/v1",o}; | ||
},{"./validators":13,"xtend/mutable":24}],3:[function(require,module,exports){ | ||
"use strict";function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function DataClient(t){this.client=t}var assign=require("xtend/mutable"),Transaction=require("./transaction"),Patch=require("./patch"),validators=require("../validators"),mutationDefaults={returnIds:!0};assign(DataClient.prototype,{fetch:function(t,e){return this.dataRequest("fetch","q",{query:t,params:e}).then(function(t){return t.result||[]})},getDocument:function(t){return this.fetch("*[.$id == %id]",{id:t}).then(function(t){return t[0]})},create:function(t){return this._create(t,"create")},createIfNotExists:function(t){return this._create(t,"createIfNotExists")},createOrReplace:function(t){return this._create(t,"createOrReplace")},patch:function(t,e){return validators.validateDocumentId("patch",t),new Patch(t,e,this)},delete:function(t){return validators.validateDocumentId("delete",t),this.dataRequest("delete","m",{delete:{id:t}})},mutate:function(t){return this.dataRequest("mutate","m",t instanceof Patch?t.serialize():t)},transaction:function(t){return new Transaction(t,this)},dataRequest:function(t,e,n){var a=this,r="m"===e&&mutationDefaults;return this.client.emit("request",t,n).then(function(){var t=validators.hasDataset(a.client.clientConfig);return a.client.request({method:"POST",uri:"/data/"+e+"/"+t,json:n,query:r})})},_create:function(t,e){var n=validators.hasDataset(this.client.clientConfig),a=_defineProperty({},e,assign({},t,{$id:t.$id||n+":"}));return this.dataRequest(e,"m",a).then(function(t){return{transactionId:t.transactionId,documentId:t.docIds[0]}})}}),module.exports=DataClient; | ||
},{"./validators":14,"xtend/mutable":25}],3:[function(require,module,exports){ | ||
"use strict";function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function DataClient(t){this.client=t}var assign=require("xtend/mutable"),validators=require("../validators"),encodeQueryString=require("./encodeQueryString"),Transaction=require("./transaction"),Patch=require("./patch"),mutationDefaults={returnIds:!0},getQuerySizeLimit=1948;assign(DataClient.prototype,{fetch:function(t,e){return this.dataRequest("fetch","q",{query:t,params:e}).then(function(t){return t.result||[]})},getDocument:function(t){return this.fetch("*[.$id == %id]",{id:t}).then(function(t){return t[0]})},create:function(t){return this._create(t,"create")},createIfNotExists:function(t){return this._create(t,"createIfNotExists")},createOrReplace:function(t){return this._create(t,"createOrReplace")},patch:function(t,e){return validators.validateDocumentId("patch",t),new Patch(t,e,this)},delete:function(t){return validators.validateDocumentId("delete",t),this.dataRequest("delete","m",{delete:{id:t}})},mutate:function(t){return this.dataRequest("mutate","m",t instanceof Patch?t.serialize():t)},transaction:function(t){return new Transaction(t,this)},dataRequest:function(t,e,n){var r=this,i="m"===e,a=!i&&encodeQueryString(n),u=!i&&a.length<getQuerySizeLimit,c=u?a:"";return this.client.emit("request",t,n).then(function(){var t=validators.hasDataset(r.client.clientConfig);return r.client.request({method:u?"GET":"POST",uri:"/data/"+e+"/"+t+c,json:!!u||n,query:i&&mutationDefaults})})},_create:function(t,e){var n=validators.hasDataset(this.client.clientConfig),r=_defineProperty({},e,assign({},t,{$id:t.$id||n+":"}));return this.dataRequest(e,"m",r).then(function(t){return{transactionId:t.transactionId,documentId:t.docIds[0]}})}}),module.exports=DataClient; | ||
},{"../validators":13,"./patch":4,"./transaction":5,"xtend/mutable":24}],4:[function(require,module,exports){ | ||
},{"../validators":14,"./encodeQueryString":4,"./patch":5,"./transaction":6,"xtend/mutable":25}],4:[function(require,module,exports){ | ||
"use strict";var enc=encodeURIComponent;module.exports=function(e){var r=e.query,n=e.params,t=void 0===n?{}:n;if(t.query)throw new Error('Parameter "query" is reserved, cannot be used as a parameter');return Object.keys(t).reduce(function(e,r){return e+"&"+enc(r)+"="+enc(JSON.stringify(t[r]))},"?query="+enc(r))}; | ||
},{}],5:[function(require,module,exports){ | ||
"use strict";function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Patch(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.documentId=e,this.operations=assign({},t),this.client=n}function throwPromiseError(e){return function(){throw new Error(e+"() called on an uncommited patch, did you forget to call commit()?")}}var deepAssign=require("deep-assign"),assign=require("xtend/mutable"),validateObject=require("../validators").validateObject;assign(Patch.prototype,{clone:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return new Patch(this.documentId,assign({},this.operations,e),this.client)},merge:function(e){return validateObject("merge",e),this.clone({merge:deepAssign(this.operations.merge||{},e)})},set:function(e){return this._assign("set",e)},setIfMissing:function(e){return this._assign("setIfMissing",e)},replace:function(e){return validateObject("replace",e),this.clone({replace:e})},inc:function(e){return this._assign("inc",e)},dec:function(e){return this._assign("dec",e)},unset:function(e){throw new Error("Not implemented yet")},append:function(e){throw new Error("Not implemented yet")},prepend:function(e){throw new Error("Not implemented yet")},splice:function(e){throw new Error("Not implemented yet")},serialize:function(){return assign({id:this.documentId},this.operations)},toJSON:function(){return this.serialize()},commit:function(){if(this.client)return this.client.mutate({patch:this.serialize()});throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `data.mutate()` method")},reset:function(){return new Patch(this.documentId,{},this.client)},_assign:function(e,t){return validateObject(e,t),this.clone(_defineProperty({},e,assign({},this.operations[e]||{},t)))},then:throwPromiseError("then"),catch:throwPromiseError("catch")}),module.exports=Patch; | ||
},{"../validators":13,"deep-assign":15,"xtend/mutable":24}],5:[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}function Transaction(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],e=arguments[1];this.operations=t,this.dataClient=e}function throwPromiseError(t){return function(){throw new Error(t+"() called on an uncommited transaction, did you forget to call commit()?")}}var assign=require("xtend/mutable"),Patch=require("./patch"),validators=require("../validators");assign(Transaction.prototype,{clone:function(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0];return new Transaction(this.operations.concat(t),this.dataClient)},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 validators.validateDocumentId("delete",t),this._add({delete:{id:t}})},patch:function t(e,r){var i="function"==typeof r,a=e instanceof Patch;if(a)return this._add({patch:e.serialize()});if(i){var t=r(new Patch(e,{},this.dataClient&&this.dataClient.client));if(!(t instanceof Patch))throw new Error("function passed to `patch()` must return the patch");return this._add({patch:t.serialize()})}return this._add({patch:assign({id:e},r)})},serialize:function(){return this.operations.slice()},toJSON:function(){return this.serialize()},commit:function(){if(this.dataClient)return this.dataClient.mutate(this.serialize());throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `data.mutate()` method")},reset:function(){return this.operations=[],this},_create:function(t,e){if(!t.$id&&!this.dataClient)throw new Error('Document needs an $id property when transaction is create outside a client scope. Pass `{$id: "<datasetName>:"}` to have Sanity generate an ID for you.');validators.validateObject(e,t);var r=validators.hasDataset(this.dataClient.client.clientConfig),i=_defineProperty({},e,assign({},t,{$id:t.$id||r+":"}));return this._add(i)},_add:function(t){return this.clone(t)},then:throwPromiseError("then"),catch:throwPromiseError("catch")}),module.exports=Transaction; | ||
},{"../validators":14,"deep-assign":16,"xtend/mutable":25}],6:[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}function Transaction(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],e=arguments[1];this.operations=t,this.dataClient=e}function throwPromiseError(t){return function(){throw new Error(t+"() called on an uncommited transaction, did you forget to call commit()?")}}var assign=require("xtend/mutable"),validators=require("../validators"),Patch=require("./patch");assign(Transaction.prototype,{clone:function(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0];return new Transaction(this.operations.concat(t),this.dataClient)},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 validators.validateDocumentId("delete",t),this._add({delete:{id:t}})},patch:function t(e,r){var i="function"==typeof r,a=e instanceof Patch;if(a)return this._add({patch:e.serialize()});if(i){var t=r(new Patch(e,{},this.dataClient&&this.dataClient.client));if(!(t instanceof Patch))throw new Error("function passed to `patch()` must return the patch");return this._add({patch:t.serialize()})}return this._add({patch:assign({id:e},r)})},serialize:function(){return this.operations.slice()},toJSON:function(){return this.serialize()},commit:function(){if(this.dataClient)return this.dataClient.mutate(this.serialize());throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `data.mutate()` method")},reset:function(){return this.operations=[],this},_create:function(t,e){if(!t.$id&&!this.dataClient)throw new Error('Document needs an $id property when transaction is create outside a client scope. Pass `{$id: "<datasetName>:"}` to have Sanity generate an ID for you.');validators.validateObject(e,t);var r=validators.hasDataset(this.dataClient.client.clientConfig),i=_defineProperty({},e,assign({},t,{$id:t.$id||r+":"}));return this._add(i)},_add:function(t){return this.clone(t)},then:throwPromiseError("then"),catch:throwPromiseError("catch")}),module.exports=Transaction; | ||
},{"../validators":13,"./patch":4,"xtend/mutable":24}],6:[function(require,module,exports){ | ||
},{"../validators":14,"./patch":5,"xtend/mutable":25}],7:[function(require,module,exports){ | ||
"use strict";function DatasetsClient(t){this.request=t.request.bind(t)}var assign=require("xtend/mutable"),validate=require("../validators");assign(DatasetsClient.prototype,{create:function(t){return this._modify("PUT",t)},delete:function(t){return this._modify("DELETE",t)},_modify:function(t,e){return validate.dataset(e),this.request({method:t,uri:"/datasets/"+e})}}),module.exports=DatasetsClient; | ||
},{"../validators":13,"xtend/mutable":24}],7:[function(require,module,exports){ | ||
},{"../validators":14,"xtend/mutable":25}],8:[function(require,module,exports){ | ||
"use strict";function queryString(e){var n=function(n,r){return n.concat(encode(r)+"="+encode(e[r]))};return Object.keys(e).reduce(n,[]).join("&")}var encode=function(e){return encodeURIComponent(e)};exports.stringify=queryString; | ||
},{}],8:[function(require,module,exports){ | ||
},{}],9:[function(require,module,exports){ | ||
"use strict";function httpError(r){return"Server responded with HTTP "+r.statusCode+" "+(r.statusMessage||"")+", no description"}function stringifyBody(r,e){var t=(e.headers["content-type"]||"").toLowerCase(),n=t.indexOf("application/json")!==-1;return n?JSON.stringify(r,null,2):r}var request=require("@sanity/request"),queryString=require("./queryString"),debug="".indexOf("sanity")!==-1,log=function(){};module.exports=function(r,e){r.query&&(r.uri+="?"+queryString.stringify(r.query)),debug&&(log("HTTP %s %s",r.method||"GET",r.uri),"POST"===r.method&&r.json&&log("Request body: %s",JSON.stringify(r.json,null,2)));var t=r.promise;return new t(function(e,t){request(r,function(r,n,o){if(r)return t(r);log("Response code: %s",n.statusCode),debug&&o&&log("Response body: %s",stringifyBody(o,n));var s=n.statusCode>=400;if(s&&o){var i=(o.errors?o.errors.map(function(r){return r.message}):[]).concat([o.error,o.message]).filter(Boolean).join("\n"),u=new Error(i||httpError(n));return u.responseBody=stringifyBody(o,n),t(u)}return s?t(new Error(httpError(n))):e(o)})})}; | ||
},{"./queryString":7,"@sanity/request":14}],9:[function(require,module,exports){ | ||
},{"./queryString":8,"@sanity/request":15}],10:[function(require,module,exports){ | ||
"use strict";var tokenHeader="Sanity-Token",projectHeader="Sanity-Project-ID";exports.getRequestOptions=function(e){var t={};return e.token&&(t[tokenHeader]=e.token),!e.useProjectHostname&&e.projectId&&(t[projectHeader]=e.projectId),{headers:t,timeout:e.timeout||15e3,withCredentials:!0,json:!0}}; | ||
},{}],10:[function(require,module,exports){ | ||
},{}],11:[function(require,module,exports){ | ||
"use strict";function ProjectsClient(t){this.client=t}var assign=require("xtend/mutable");assign(ProjectsClient.prototype,{list:function(){return this.client.request({uri:"/projects"})},getById:function(t){return this.client.request({uri:"/projects/"+t})}}),module.exports=ProjectsClient; | ||
},{"xtend/mutable":24}],11:[function(require,module,exports){ | ||
},{"xtend/mutable":25}],12:[function(require,module,exports){ | ||
"use strict";function SanityClient(){var e=arguments.length<=0||void 0===arguments[0]?defaultConfig:arguments[0];this.config(e),this.data=new DataClient(this),this.datasets=new DatasetsClient(this),this.projects=new ProjectsClient(this),this.users=new UsersClient(this),this.auth=new AuthClient(this),this.eventHandlers=allowedEvents.reduce(function(e,t){return e[t]=[],e},{})}function createClient(e){return new SanityClient(e)}var assign=require("xtend/mutable"),Patch=require("./data/patch"),Transaction=require("./data/transaction"),DataClient=require("./data/dataClient"),DatasetsClient=require("./datasets/datasetsClient"),ProjectsClient=require("./projects/projectsClient"),UsersClient=require("./users/usersClient"),AuthClient=require("./auth/authClient"),httpRequest=require("./http/request"),_require=require("./http/requestOptions"),getRequestOptions=_require.getRequestOptions,_require2=require("./config"),defaultConfig=_require2.defaultConfig,initConfig=_require2.initConfig,allowedEvents=["request"],verifyEvent=function(e,t){if(allowedEvents.indexOf(e)===-1)throw new Error('Unknown event type "'+e+'"');if("function"!=typeof t)throw new Error("Event handler must be a function")};assign(SanityClient.prototype,{config:function(e){return"undefined"==typeof e?this.clientConfig:(this.clientConfig=initConfig(e,this.clientConfig||{}),this)},on:function(e,t){return verifyEvent(e,t),this.eventHandlers[e].push(t),this},removeListener:function(e,t){verifyEvent(e,t);var n=this.eventHandlers[e].indexOf(t);return n!==-1&&this.eventHandlers[e].splice(n,1),this},emit:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];var r=this.eventHandlers[e],s=this.clientConfig.promise;return r.length?s.all(r.map(function(e){return e.apply(void 0,n)})):s.resolve()},getUrl:function(e){return this.clientConfig.url+"/"+e.replace(/^\//,"")},request:function(e){return httpRequest(assign({promise:this.clientConfig.promise},getRequestOptions(this.clientConfig),e,{uri:this.getUrl(e.uri)}))}}),createClient.Patch=Patch,createClient.Transaction=Transaction,module.exports=createClient; | ||
},{"./auth/authClient":1,"./config":2,"./data/dataClient":3,"./data/patch":4,"./data/transaction":5,"./datasets/datasetsClient":6,"./http/request":8,"./http/requestOptions":9,"./projects/projectsClient":10,"./users/usersClient":12,"xtend/mutable":24}],12:[function(require,module,exports){ | ||
},{"./auth/authClient":1,"./config":2,"./data/dataClient":3,"./data/patch":5,"./data/transaction":6,"./datasets/datasetsClient":7,"./http/request":9,"./http/requestOptions":10,"./projects/projectsClient":11,"./users/usersClient":13,"xtend/mutable":25}],13:[function(require,module,exports){ | ||
"use strict";function UsersClient(e){this.client=e}var assign=require("xtend/mutable");assign(UsersClient.prototype,{getById:function(e){return this.client.request({uri:"/users/"+e})}}),module.exports=UsersClient; | ||
},{"xtend/mutable":24}],13:[function(require,module,exports){ | ||
},{"xtend/mutable":25}],14:[function(require,module,exports){ | ||
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t};exports.dataset=function(t){if(!/^[-\w]{1,128}$/.test(t))throw new Error("Datasets can only contain lowercase characters, numbers, underscores and dashes")},exports.projectId=function(t){if(!/^[-a-z0-9]+$/i.test(t))throw new Error("`projectId` can only contain only a-z, 0-9 and dashes")},exports.validateObject=function(t,e){if(null===e||"object"!==("undefined"==typeof e?"undefined":_typeof(e))||Array.isArray(e))throw new Error(t+"() takes an object of properties")},exports.validateDocumentId=function(t,e){if("string"!=typeof e||!/^[-\w]{1,128}:[-_a-z0-9]+$/i.test(e))throw new Error(t+"() takes a document ID in format dataset:docId")},exports.hasDataset=function(t){if(!t.dataset)throw new Error("`dataset` must be provided to perform queries");return t.dataset}; | ||
},{}],14:[function(require,module,exports){ | ||
},{}],15:[function(require,module,exports){ | ||
module.exports=require("xhr"); | ||
},{"xhr":22}],15:[function(require,module,exports){ | ||
},{"xhr":23}],16:[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":19}],16:[function(require,module,exports){ | ||
},{"is-obj":20}],17:[function(require,module,exports){ | ||
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; | ||
},{"is-function":18}],17:[function(require,module,exports){ | ||
},{"is-function":19}],18:[function(require,module,exports){ | ||
(function (global){ | ||
@@ -48,21 +51,21 @@ "undefined"!=typeof window?module.exports=window:"undefined"!=typeof global?module.exports=global:"undefined"!=typeof self?module.exports=self:module.exports={}; | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}],18:[function(require,module,exports){ | ||
},{}],19:[function(require,module,exports){ | ||
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; | ||
},{}],19:[function(require,module,exports){ | ||
},{}],20:[function(require,module,exports){ | ||
"use strict";module.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}; | ||
},{}],20:[function(require,module,exports){ | ||
},{}],21:[function(require,module,exports){ | ||
var trim=require("trim"),forEach=require("for-each"),isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)};module.exports=function(r){if(!r)return{};var e={};return forEach(trim(r).split("\n"),function(r){var t=r.indexOf(":"),i=trim(r.slice(0,t)).toLowerCase(),o=trim(r.slice(t+1));"undefined"==typeof e[i]?e[i]=o:isArray(e[i])?e[i].push(o):e[i]=[e[i],o]}),e}; | ||
},{"for-each":16,"trim":21}],21:[function(require,module,exports){ | ||
},{"for-each":17,"trim":22}],22:[function(require,module,exports){ | ||
function trim(r){return r.replace(/^\s*|\s*$/g,"")}exports=module.exports=trim,exports.left=function(r){return r.replace(/^\s*/,"")},exports.right=function(r){return r.replace(/\s*$/,"")}; | ||
},{}],22:[function(require,module,exports){ | ||
},{}],23:[function(require,module,exports){ | ||
"use strict";function forEachArray(e,t){for(var r=0;r<e.length;r++)t(e[r])}function isEmpty(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0}function initParams(e,t,r){var n=e;return isFunction(t)?(r=t,"string"==typeof e&&(n={uri:e})):n=xtend(t,{uri:e}),n.callback=r,n}function createXHR(e,t,r){return t=initParams(e,t,r),_createXHR(t)}function _createXHR(e){function t(){4===u.readyState&&o()}function r(){var e=void 0;if(e=u.response?u.response:u.responseText||getXml(u),h)try{e=JSON.parse(e)}catch(e){}return e}function n(e){return clearTimeout(p),e instanceof Error||(e=new Error(""+(e||"Unknown XMLHttpRequest Error"))),e.statusCode=0,a(e,i)}function o(){if(!d){var t;clearTimeout(p),t=e.useXDR&&void 0===u.status?200:1223===u.status?204:u.status;var n=i,o=null;return 0!==t?(n={body:r(),statusCode:t,method:f,headers:{},url:l,rawRequest:u},u.getAllResponseHeaders&&(n.headers=parseHeaders(u.getAllResponseHeaders()))):o=new Error("Internal XMLHttpRequest Error"),a(o,n,n.body)}}if("undefined"==typeof e.callback)throw new Error("callback argument missing");var s=!1,a=function(t,r,n){s||(s=!0,e.callback(t,r,n))},i={body:void 0,headers:{},statusCode:0,method:f,url:l,rawRequest:u},u=e.xhr||null;u||(u=e.cors||e.useXDR?new createXHR.XDomainRequest:new createXHR.XMLHttpRequest);var c,d,p,l=u.url=e.uri||e.url,f=u.method=e.method||"GET",m=e.body||e.data||null,R=u.headers=e.headers||{},X=!!e.sync,h=!1;if("json"in e&&(h=!0,R.accept||R.Accept||(R.Accept="application/json"),"GET"!==f&&"HEAD"!==f&&(R["content-type"]||R["Content-Type"]||(R["Content-Type"]="application/json"),m=JSON.stringify(e.json))),u.onreadystatechange=t,u.onload=o,u.onerror=n,u.onprogress=function(){},u.ontimeout=n,u.open(f,l,!X,e.username,e.password),X||(u.withCredentials=!!e.withCredentials),!X&&e.timeout>0&&(p=setTimeout(function(){d=!0,u.abort("timeout");var e=new Error("XMLHttpRequest timeout");e.code="ETIMEDOUT",n(e)},e.timeout)),u.setRequestHeader)for(c in R)R.hasOwnProperty(c)&&u.setRequestHeader(c,R[c]);else if(e.headers&&!isEmpty(e.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in e&&(u.responseType=e.responseType),"beforeSend"in e&&"function"==typeof e.beforeSend&&e.beforeSend(u),u.send(m),u}function getXml(e){if("document"===e.responseType)return e.responseXML;var t=204===e.status&&e.responseXML&&"parsererror"===e.responseXML.documentElement.nodeName;return""!==e.responseType||t?null:e.responseXML}function noop(){}var window=require("global/window"),isFunction=require("is-function"),parseHeaders=require("parse-headers"),xtend=require("xtend");module.exports=createXHR,createXHR.XMLHttpRequest=window.XMLHttpRequest||noop,createXHR.XDomainRequest="withCredentials"in new createXHR.XMLHttpRequest?createXHR.XMLHttpRequest:window.XDomainRequest,forEachArray(["get","put","post","patch","head","delete"],function(e){createXHR["delete"===e?"del":e]=function(t,r,n){return r=initParams(t,r,n),r.method=e.toUpperCase(),_createXHR(r)}}); | ||
},{"global/window":17,"is-function":18,"parse-headers":20,"xtend":23}],23:[function(require,module,exports){ | ||
},{"global/window":18,"is-function":19,"parse-headers":21,"xtend":24}],24:[function(require,module,exports){ | ||
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; | ||
},{}],24:[function(require,module,exports){ | ||
},{}],25:[function(require,module,exports){ | ||
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; | ||
},{}]},{},[11])(11) | ||
},{}]},{},[12])(12) | ||
}); |
@@ -1,1 +0,1 @@ | ||
!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 o(s,a){if(!n[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(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 o(n?n:t)},f,f.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(t,e,n){"use strict";function r(t){this.client=t}var o=t("xtend/mutable");o(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":24}],2:[function(t,e,n){"use strict";var r=t("xtend/mutable"),o=t("./validators"),i=n.defaultConfig={apiHost:"https://api.sanity.io",useProjectHostname:!0,promise:Promise};n.initConfig=function(t,e){var n=r({},i,e,t),s=n.useProjectHostname;if(!n.promise&&"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&&o.projectId(n.projectId),n.dataset&&o.dataset(n.dataset);var a=n.apiHost.split("://",2),u=a[0],c=a[1];return n.useProjectHostname?n.url=u+"://"+n.projectId+"."+c+"/v1":n.url=n.apiHost+"/v1",n}},{"./validators":13,"xtend/mutable":24}],3:[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 o(t){this.client=t}var i=t("xtend/mutable"),s=t("./transaction"),a=t("./patch"),u=t("../validators"),c={returnIds:!0};i(o.prototype,{fetch:function(t,e){return this.dataRequest("fetch","q",{query:t,params:e}).then(function(t){return t.result||[]})},getDocument:function(t){return this.fetch("*[.$id == %id]",{id:t}).then(function(t){return t[0]})},create:function(t){return this._create(t,"create")},createIfNotExists:function(t){return this._create(t,"createIfNotExists")},createOrReplace:function(t){return this._create(t,"createOrReplace")},patch:function(t,e){return u.validateDocumentId("patch",t),new a(t,e,this)},delete:function(t){return u.validateDocumentId("delete",t),this.dataRequest("delete","m",{delete:{id:t}})},mutate:function(t){return this.dataRequest("mutate","m",t instanceof a?t.serialize():t)},transaction:function(t){return new s(t,this)},dataRequest:function(t,e,n){var r=this,o="m"===e&&c;return this.client.emit("request",t,n).then(function(){var t=u.hasDataset(r.client.clientConfig);return r.client.request({method:"POST",uri:"/data/"+e+"/"+t,json:n,query:o})})},_create:function(t,e){var n=u.hasDataset(this.client.clientConfig),o=r({},e,i({},t,{$id:t.$id||n+":"}));return this.dataRequest(e,"m",o).then(function(t){return{transactionId:t.transactionId,documentId:t.docIds[0]}})}}),e.exports=o},{"../validators":13,"./patch":4,"./transaction":5,"xtend/mutable":24}],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}function o(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.documentId=t,this.operations=a({},e),this.client=n}function i(t){return function(){throw new Error(t+"() called on an uncommited patch, did you forget to call commit()?")}}var s=t("deep-assign"),a=t("xtend/mutable"),u=t("../validators").validateObject;a(o.prototype,{clone:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return new o(this.documentId,a({},this.operations,t),this.client)},merge:function(t){return u("merge",t),this.clone({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 u("replace",t),this.clone({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 a({id:this.documentId},this.operations)},toJSON:function(){return this.serialize()},commit:function(){if(this.client)return this.client.mutate({patch:this.serialize()});throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `data.mutate()` method")},reset:function(){return new o(this.documentId,{},this.client)},_assign:function(t,e){return u(t,e),this.clone(r({},t,a({},this.operations[t]||{},e)))},then:i("then"),catch:i("catch")}),e.exports=o},{"../validators":13,"deep-assign":15,"xtend/mutable":24}],5:[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 o(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],e=arguments[1];this.operations=t,this.dataClient=e}function i(t){return function(){throw new Error(t+"() called on an uncommited transaction, did you forget to call commit()?")}}var s=t("xtend/mutable"),a=t("./patch"),u=t("../validators");s(o.prototype,{clone:function(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0];return new o(this.operations.concat(t),this.dataClient)},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 u.validateDocumentId("delete",t),this._add({delete:{id:t}})},patch:function t(e,n){var r="function"==typeof n,o=e instanceof a;if(o)return this._add({patch:e.serialize()});if(r){var t=n(new a(e,{},this.dataClient&&this.dataClient.client));if(!(t instanceof a))throw new Error("function passed to `patch()` must return the patch");return this._add({patch:t.serialize()})}return this._add({patch:s({id:e},n)})},serialize:function(){return this.operations.slice()},toJSON:function(){return this.serialize()},commit:function(){if(this.dataClient)return this.dataClient.mutate(this.serialize());throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `data.mutate()` method")},reset:function(){return this.operations=[],this},_create:function(t,e){if(!t.$id&&!this.dataClient)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.');u.validateObject(e,t);var n=u.hasDataset(this.dataClient.client.clientConfig),o=r({},e,s({},t,{$id:t.$id||n+":"}));return this._add(o)},_add:function(t){return this.clone(t)},then:i("then"),catch:i("catch")}),e.exports=o},{"../validators":13,"./patch":4,"xtend/mutable":24}],6:[function(t,e,n){"use strict";function r(t){this.request=t.request.bind(t)}var o=t("xtend/mutable"),i=t("../validators");o(r.prototype,{create:function(t){return this._modify("PUT",t)},delete:function(t){return this._modify("DELETE",t)},_modify:function(t,e){return i.dataset(e),this.request({method:t,uri:"/datasets/"+e})}}),e.exports=r},{"../validators":13,"xtend/mutable":24}],7:[function(t,e,n){"use strict";function r(t){var e=function(e,n){return e.concat(o(n)+"="+o(t[n]))};return Object.keys(t).reduce(e,[]).join("&")}var o=function(t){return encodeURIComponent(t)};n.stringify=r},{}],8:[function(t,e,n){"use strict";function r(t){return"Server responded with HTTP "+t.statusCode+" "+(t.statusMessage||"")+", no description"}function o(t,e){var n=(e.headers["content-type"]||"").toLowerCase(),r=n.indexOf("application/json")!==-1;return r?JSON.stringify(t,null,2):t}var i=t("@sanity/request"),s=t("./queryString"),a="".indexOf("sanity")!==-1,u=function(){};e.exports=function(t,e){t.query&&(t.uri+="?"+s.stringify(t.query)),a&&(u("HTTP %s %s",t.method||"GET",t.uri),"POST"===t.method&&t.json&&u("Request body: %s",JSON.stringify(t.json,null,2)));var n=t.promise;return new n(function(e,n){i(t,function(t,i,s){if(t)return n(t);u("Response code: %s",i.statusCode),a&&s&&u("Response body: %s",o(s,i));var c=i.statusCode>=400;if(c&&s){var f=(s.errors?s.errors.map(function(t){return t.message}):[]).concat([s.error,s.message]).filter(Boolean).join("\n"),d=new Error(f||r(i));return d.responseBody=o(s,i),n(d)}return c?n(new Error(r(i))):e(s)})})}},{"./queryString":7,"@sanity/request":14}],9:[function(t,e,n){"use strict";var r="Sanity-Token",o="Sanity-Project-ID";n.getRequestOptions=function(t){var e={};return t.token&&(e[r]=t.token),!t.useProjectHostname&&t.projectId&&(e[o]=t.projectId),{headers:e,timeout:t.timeout||15e3,withCredentials:!0,json:!0}}},{}],10:[function(t,e,n){"use strict";function r(t){this.client=t}var o=t("xtend/mutable");o(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":24}],11:[function(t,e,n){"use strict";function r(){var t=arguments.length<=0||void 0===arguments[0]?v:arguments[0];this.config(t),this.data=new u(this),this.datasets=new c(this),this.projects=new f(this),this.users=new d(this),this.auth=new l(this),this.eventHandlers=g.reduce(function(t,e){return t[e]=[],t},{})}function o(t){return new r(t)}var i=t("xtend/mutable"),s=t("./data/patch"),a=t("./data/transaction"),u=t("./data/dataClient"),c=t("./datasets/datasetsClient"),f=t("./projects/projectsClient"),d=t("./users/usersClient"),l=t("./auth/authClient"),p=t("./http/request"),h=t("./http/requestOptions"),m=h.getRequestOptions,y=t("./config"),v=y.defaultConfig,w=y.initConfig,g=["request"],b=function(t,e){if(g.indexOf(t)===-1)throw new Error('Unknown event type "'+t+'"');if("function"!=typeof e)throw new Error("Event handler must be a function")};i(r.prototype,{config:function(t){return"undefined"==typeof t?this.clientConfig:(this.clientConfig=w(t,this.clientConfig||{}),this)},on:function(t,e){return b(t,e),this.eventHandlers[t].push(e),this},removeListener:function(t,e){b(t,e);var n=this.eventHandlers[t].indexOf(e);return n!==-1&&this.eventHandlers[t].splice(n,1),this},emit:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];var o=this.eventHandlers[t],i=this.clientConfig.promise;return o.length?i.all(o.map(function(t){return t.apply(void 0,n)})):i.resolve()},getUrl:function(t){return this.clientConfig.url+"/"+t.replace(/^\//,"")},request:function(t){return p(i({promise:this.clientConfig.promise},m(this.clientConfig),t,{uri:this.getUrl(t.uri)}))}}),o.Patch=s,o.Transaction=a,e.exports=o},{"./auth/authClient":1,"./config":2,"./data/dataClient":3,"./data/patch":4,"./data/transaction":5,"./datasets/datasetsClient":6,"./http/request":8,"./http/requestOptions":9,"./projects/projectsClient":10,"./users/usersClient":12,"xtend/mutable":24}],12:[function(t,e,n){"use strict";function r(t){this.client=t}var o=t("xtend/mutable");o(r.prototype,{getById:function(t){return this.client.request({uri:"/users/"+t})}}),e.exports=r},{"xtend/mutable":24}],13:[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?"symbol":typeof t};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.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||!/^[-\w]{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}},{}],14:[function(t,e,n){e.exports=t("xhr")},{xhr:22}],15:[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 o(t,e,n){var r=e[n];if(void 0!==r&&null!==r){if(a.call(t,n)&&(void 0===t[n]||null===t[n]))throw new TypeError("Cannot convert undefined or null to object ("+n+")");a.call(t,n)&&s(r)?t[n]=i(Object(t[n]),e[n]):t[n]=r}}function i(t,e){if(t===e)return t;e=Object(e);for(var n in e)a.call(e,n)&&o(t,e,n);if(Object.getOwnPropertySymbols)for(var r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)u.call(e,r[i])&&o(t,e,r[i]);return t}var s=t("is-obj"),a=Object.prototype.hasOwnProperty,u=Object.prototype.propertyIsEnumerable;e.exports=function(t){t=r(t);for(var e=1;e<arguments.length;e++)i(t,arguments[e]);return t}},{"is-obj":19}],16:[function(t,e,n){function r(t,e,n){if(!a(e))throw new TypeError("iterator must be a function");arguments.length<3&&(n=this),"[object Array]"===u.call(t)?o(t,e,n):"string"==typeof t?i(t,e,n):s(t,e,n)}function o(t,e,n){for(var r=0,o=t.length;r<o;r++)c.call(t,r)&&e.call(n,t[r],r,t)}function i(t,e,n){for(var r=0,o=t.length;r<o;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 a=t("is-function");e.exports=r;var u=Object.prototype.toString,c=Object.prototype.hasOwnProperty},{"is-function":18}],17:[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:{})},{}],18:[function(t,e,n){function r(t){var e=o.call(t);return"[object Function]"===e||"function"==typeof t&&"[object RegExp]"!==e||"undefined"!=typeof window&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)}e.exports=r;var o=Object.prototype.toString},{}],19:[function(t,e,n){"use strict";e.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}},{}],20:[function(t,e,n){var r=t("trim"),o=t("for-each"),i=function(t){return"[object Array]"===Object.prototype.toString.call(t)};e.exports=function(t){if(!t)return{};var e={};return o(r(t).split("\n"),function(t){var n=t.indexOf(":"),o=r(t.slice(0,n)).toLowerCase(),s=r(t.slice(n+1));"undefined"==typeof e[o]?e[o]=s:i(e[o])?e[o].push(s):e[o]=[e[o],s]}),e}},{"for-each":16,trim:21}],21:[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*$/,"")}},{}],22:[function(t,e,n){"use strict";function r(t,e){for(var n=0;n<t.length;n++)e(t[n])}function o(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function i(t,e,n){var r=t;return d(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=i(t,e,n),a(e)}function a(t){function e(){4===d.readyState&&i()}function n(){var t=void 0;if(t=d.response?d.response:d.responseText||u(d),j)try{t=JSON.parse(t)}catch(t){}return t}function r(t){return clearTimeout(m),t instanceof Error||(t=new Error(""+(t||"Unknown XMLHttpRequest Error"))),t.statusCode=0,c(t,f)}function i(){if(!h){var e;clearTimeout(m),e=t.useXDR&&void 0===d.status?200:1223===d.status?204:d.status;var r=f,o=null;return 0!==e?(r={body:n(),statusCode:e,method:v,headers:{},url:y,rawRequest:d},d.getAllResponseHeaders&&(r.headers=l(d.getAllResponseHeaders()))):o=new Error("Internal XMLHttpRequest Error"),c(o,r,r.body)}}if("undefined"==typeof t.callback)throw new Error("callback argument missing");var a=!1,c=function(e,n,r){a||(a=!0,t.callback(e,n,r))},f={body:void 0,headers:{},statusCode:0,method:v,url:y,rawRequest:d},d=t.xhr||null;d||(d=t.cors||t.useXDR?new s.XDomainRequest:new s.XMLHttpRequest);var p,h,m,y=d.url=t.uri||t.url,v=d.method=t.method||"GET",w=t.body||t.data||null,g=d.headers=t.headers||{},b=!!t.sync,j=!1;if("json"in t&&(j=!0,g.accept||g.Accept||(g.Accept="application/json"),"GET"!==v&&"HEAD"!==v&&(g["content-type"]||g["Content-Type"]||(g["Content-Type"]="application/json"),w=JSON.stringify(t.json))),d.onreadystatechange=e,d.onload=i,d.onerror=r,d.onprogress=function(){},d.ontimeout=r,d.open(v,y,!b,t.username,t.password),b||(d.withCredentials=!!t.withCredentials),!b&&t.timeout>0&&(m=setTimeout(function(){h=!0,d.abort("timeout");var t=new Error("XMLHttpRequest timeout");t.code="ETIMEDOUT",r(t)},t.timeout)),d.setRequestHeader)for(p in g)g.hasOwnProperty(p)&&d.setRequestHeader(p,g[p]);else if(t.headers&&!o(t.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in t&&(d.responseType=t.responseType),"beforeSend"in t&&"function"==typeof t.beforeSend&&t.beforeSend(d),d.send(w),d}function u(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"),d=t("is-function"),l=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=i(e,n,r),n.method=t.toUpperCase(),a(n)}})},{"global/window":17,"is-function":18,"parse-headers":20,xtend:23}],23:[function(t,e,n){function r(){for(var t={},e=0;e<arguments.length;e++){var n=arguments[e];for(var r in n)o.call(n,r)&&(t[r]=n[r])}return t}e.exports=r;var o=Object.prototype.hasOwnProperty},{}],24:[function(t,e,n){function r(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)o.call(n,r)&&(t[r]=n[r])}return t}e.exports=r;var o=Object.prototype.hasOwnProperty},{}]},{},[11])(11)}); | ||
!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 o(s,a){if(!n[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(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 o(n?n:t)},f,f.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(t,e,n){"use strict";function r(t){this.client=t}var o=t("xtend/mutable");o(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":25}],2:[function(t,e,n){"use strict";var r=t("xtend/mutable"),o=t("./validators"),i=n.defaultConfig={apiHost:"https://api.sanity.io",useProjectHostname:!0,promise:Promise};n.initConfig=function(t,e){var n=r({},i,e,t),s=n.useProjectHostname;if(!n.promise&&"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&&o.projectId(n.projectId),n.dataset&&o.dataset(n.dataset);var a=n.apiHost.split("://",2),u=a[0],c=a[1];return n.useProjectHostname?n.url=u+"://"+n.projectId+"."+c+"/v1":n.url=n.apiHost+"/v1",n}},{"./validators":14,"xtend/mutable":25}],3:[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 o(t){this.client=t}var i=t("xtend/mutable"),s=t("../validators"),a=t("./encodeQueryString"),u=t("./transaction"),c=t("./patch"),f={returnIds:!0},d=1948;i(o.prototype,{fetch:function(t,e){return this.dataRequest("fetch","q",{query:t,params:e}).then(function(t){return t.result||[]})},getDocument:function(t){return this.fetch("*[.$id == %id]",{id:t}).then(function(t){return t[0]})},create:function(t){return this._create(t,"create")},createIfNotExists:function(t){return this._create(t,"createIfNotExists")},createOrReplace:function(t){return this._create(t,"createOrReplace")},patch:function(t,e){return s.validateDocumentId("patch",t),new c(t,e,this)},delete:function(t){return s.validateDocumentId("delete",t),this.dataRequest("delete","m",{delete:{id:t}})},mutate:function(t){return this.dataRequest("mutate","m",t instanceof c?t.serialize():t)},transaction:function(t){return new u(t,this)},dataRequest:function(t,e,n){var r=this,o="m"===e,i=!o&&a(n),u=!o&&i.length<d,c=u?i:"";return this.client.emit("request",t,n).then(function(){var t=s.hasDataset(r.client.clientConfig);return r.client.request({method:u?"GET":"POST",uri:"/data/"+e+"/"+t+c,json:!!u||n,query:o&&f})})},_create:function(t,e){var n=s.hasDataset(this.client.clientConfig),o=r({},e,i({},t,{$id:t.$id||n+":"}));return this.dataRequest(e,"m",o).then(function(t){return{transactionId:t.transactionId,documentId:t.docIds[0]}})}}),e.exports=o},{"../validators":14,"./encodeQueryString":4,"./patch":5,"./transaction":6,"xtend/mutable":25}],4:[function(t,e,n){"use strict";var r=encodeURIComponent;e.exports=function(t){var e=t.query,n=t.params,o=void 0===n?{}:n;if(o.query)throw new Error('Parameter "query" is reserved, cannot be used as a parameter');return Object.keys(o).reduce(function(t,e){return t+"&"+r(e)+"="+r(JSON.stringify(o[e]))},"?query="+r(e))}},{}],5:[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 o(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=arguments.length<=2||void 0===arguments[2]?null:arguments[2];this.documentId=t,this.operations=a({},e),this.client=n}function i(t){return function(){throw new Error(t+"() called on an uncommited patch, did you forget to call commit()?")}}var s=t("deep-assign"),a=t("xtend/mutable"),u=t("../validators").validateObject;a(o.prototype,{clone:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return new o(this.documentId,a({},this.operations,t),this.client)},merge:function(t){return u("merge",t),this.clone({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 u("replace",t),this.clone({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 a({id:this.documentId},this.operations)},toJSON:function(){return this.serialize()},commit:function(){if(this.client)return this.client.mutate({patch:this.serialize()});throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `data.mutate()` method")},reset:function(){return new o(this.documentId,{},this.client)},_assign:function(t,e){return u(t,e),this.clone(r({},t,a({},this.operations[t]||{},e)))},then:i("then"),catch:i("catch")}),e.exports=o},{"../validators":14,"deep-assign":16,"xtend/mutable":25}],6:[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 o(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],e=arguments[1];this.operations=t,this.dataClient=e}function i(t){return function(){throw new Error(t+"() called on an uncommited transaction, did you forget to call commit()?")}}var s=t("xtend/mutable"),a=t("../validators"),u=t("./patch");s(o.prototype,{clone:function(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0];return new o(this.operations.concat(t),this.dataClient)},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 a.validateDocumentId("delete",t),this._add({delete:{id:t}})},patch:function t(e,n){var r="function"==typeof n,o=e instanceof u;if(o)return this._add({patch:e.serialize()});if(r){var t=n(new u(e,{},this.dataClient&&this.dataClient.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:s({id:e},n)})},serialize:function(){return this.operations.slice()},toJSON:function(){return this.serialize()},commit:function(){if(this.dataClient)return this.dataClient.mutate(this.serialize());throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `data.mutate()` method")},reset:function(){return this.operations=[],this},_create:function(t,e){if(!t.$id&&!this.dataClient)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.');a.validateObject(e,t);var n=a.hasDataset(this.dataClient.client.clientConfig),o=r({},e,s({},t,{$id:t.$id||n+":"}));return this._add(o)},_add:function(t){return this.clone(t)},then:i("then"),catch:i("catch")}),e.exports=o},{"../validators":14,"./patch":5,"xtend/mutable":25}],7:[function(t,e,n){"use strict";function r(t){this.request=t.request.bind(t)}var o=t("xtend/mutable"),i=t("../validators");o(r.prototype,{create:function(t){return this._modify("PUT",t)},delete:function(t){return this._modify("DELETE",t)},_modify:function(t,e){return i.dataset(e),this.request({method:t,uri:"/datasets/"+e})}}),e.exports=r},{"../validators":14,"xtend/mutable":25}],8:[function(t,e,n){"use strict";function r(t){var e=function(e,n){return e.concat(o(n)+"="+o(t[n]))};return Object.keys(t).reduce(e,[]).join("&")}var o=function(t){return encodeURIComponent(t)};n.stringify=r},{}],9:[function(t,e,n){"use strict";function r(t){return"Server responded with HTTP "+t.statusCode+" "+(t.statusMessage||"")+", no description"}function o(t,e){var n=(e.headers["content-type"]||"").toLowerCase(),r=n.indexOf("application/json")!==-1;return r?JSON.stringify(t,null,2):t}var i=t("@sanity/request"),s=t("./queryString"),a="".indexOf("sanity")!==-1,u=function(){};e.exports=function(t,e){t.query&&(t.uri+="?"+s.stringify(t.query)),a&&(u("HTTP %s %s",t.method||"GET",t.uri),"POST"===t.method&&t.json&&u("Request body: %s",JSON.stringify(t.json,null,2)));var n=t.promise;return new n(function(e,n){i(t,function(t,i,s){if(t)return n(t);u("Response code: %s",i.statusCode),a&&s&&u("Response body: %s",o(s,i));var c=i.statusCode>=400;if(c&&s){var f=(s.errors?s.errors.map(function(t){return t.message}):[]).concat([s.error,s.message]).filter(Boolean).join("\n"),d=new Error(f||r(i));return d.responseBody=o(s,i),n(d)}return c?n(new Error(r(i))):e(s)})})}},{"./queryString":8,"@sanity/request":15}],10:[function(t,e,n){"use strict";var r="Sanity-Token",o="Sanity-Project-ID";n.getRequestOptions=function(t){var e={};return t.token&&(e[r]=t.token),!t.useProjectHostname&&t.projectId&&(e[o]=t.projectId),{headers:e,timeout:t.timeout||15e3,withCredentials:!0,json:!0}}},{}],11:[function(t,e,n){"use strict";function r(t){this.client=t}var o=t("xtend/mutable");o(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":25}],12:[function(t,e,n){"use strict";function r(){var t=arguments.length<=0||void 0===arguments[0]?v:arguments[0];this.config(t),this.data=new u(this),this.datasets=new c(this),this.projects=new f(this),this.users=new d(this),this.auth=new l(this),this.eventHandlers=g.reduce(function(t,e){return t[e]=[],t},{})}function o(t){return new r(t)}var i=t("xtend/mutable"),s=t("./data/patch"),a=t("./data/transaction"),u=t("./data/dataClient"),c=t("./datasets/datasetsClient"),f=t("./projects/projectsClient"),d=t("./users/usersClient"),l=t("./auth/authClient"),p=t("./http/request"),h=t("./http/requestOptions"),m=h.getRequestOptions,y=t("./config"),v=y.defaultConfig,w=y.initConfig,g=["request"],b=function(t,e){if(g.indexOf(t)===-1)throw new Error('Unknown event type "'+t+'"');if("function"!=typeof e)throw new Error("Event handler must be a function")};i(r.prototype,{config:function(t){return"undefined"==typeof t?this.clientConfig:(this.clientConfig=w(t,this.clientConfig||{}),this)},on:function(t,e){return b(t,e),this.eventHandlers[t].push(e),this},removeListener:function(t,e){b(t,e);var n=this.eventHandlers[t].indexOf(e);return n!==-1&&this.eventHandlers[t].splice(n,1),this},emit:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];var o=this.eventHandlers[t],i=this.clientConfig.promise;return o.length?i.all(o.map(function(t){return t.apply(void 0,n)})):i.resolve()},getUrl:function(t){return this.clientConfig.url+"/"+t.replace(/^\//,"")},request:function(t){return p(i({promise:this.clientConfig.promise},m(this.clientConfig),t,{uri:this.getUrl(t.uri)}))}}),o.Patch=s,o.Transaction=a,e.exports=o},{"./auth/authClient":1,"./config":2,"./data/dataClient":3,"./data/patch":5,"./data/transaction":6,"./datasets/datasetsClient":7,"./http/request":9,"./http/requestOptions":10,"./projects/projectsClient":11,"./users/usersClient":13,"xtend/mutable":25}],13:[function(t,e,n){"use strict";function r(t){this.client=t}var o=t("xtend/mutable");o(r.prototype,{getById:function(t){return this.client.request({uri:"/users/"+t})}}),e.exports=r},{"xtend/mutable":25}],14:[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?"symbol":typeof t};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.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||!/^[-\w]{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}},{}],15:[function(t,e,n){e.exports=t("xhr")},{xhr:23}],16:[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 o(t,e,n){var r=e[n];if(void 0!==r&&null!==r){if(a.call(t,n)&&(void 0===t[n]||null===t[n]))throw new TypeError("Cannot convert undefined or null to object ("+n+")");a.call(t,n)&&s(r)?t[n]=i(Object(t[n]),e[n]):t[n]=r}}function i(t,e){if(t===e)return t;e=Object(e);for(var n in e)a.call(e,n)&&o(t,e,n);if(Object.getOwnPropertySymbols)for(var r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)u.call(e,r[i])&&o(t,e,r[i]);return t}var s=t("is-obj"),a=Object.prototype.hasOwnProperty,u=Object.prototype.propertyIsEnumerable;e.exports=function(t){t=r(t);for(var e=1;e<arguments.length;e++)i(t,arguments[e]);return t}},{"is-obj":20}],17:[function(t,e,n){function r(t,e,n){if(!a(e))throw new TypeError("iterator must be a function");arguments.length<3&&(n=this),"[object Array]"===u.call(t)?o(t,e,n):"string"==typeof t?i(t,e,n):s(t,e,n)}function o(t,e,n){for(var r=0,o=t.length;r<o;r++)c.call(t,r)&&e.call(n,t[r],r,t)}function i(t,e,n){for(var r=0,o=t.length;r<o;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 a=t("is-function");e.exports=r;var u=Object.prototype.toString,c=Object.prototype.hasOwnProperty},{"is-function":19}],18:[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:{})},{}],19:[function(t,e,n){function r(t){var e=o.call(t);return"[object Function]"===e||"function"==typeof t&&"[object RegExp]"!==e||"undefined"!=typeof window&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)}e.exports=r;var o=Object.prototype.toString},{}],20:[function(t,e,n){"use strict";e.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}},{}],21:[function(t,e,n){var r=t("trim"),o=t("for-each"),i=function(t){return"[object Array]"===Object.prototype.toString.call(t)};e.exports=function(t){if(!t)return{};var e={};return o(r(t).split("\n"),function(t){var n=t.indexOf(":"),o=r(t.slice(0,n)).toLowerCase(),s=r(t.slice(n+1));"undefined"==typeof e[o]?e[o]=s:i(e[o])?e[o].push(s):e[o]=[e[o],s]}),e}},{"for-each":17,trim:22}],22:[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*$/,"")}},{}],23:[function(t,e,n){"use strict";function r(t,e){for(var n=0;n<t.length;n++)e(t[n])}function o(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function i(t,e,n){var r=t;return d(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=i(t,e,n),a(e)}function a(t){function e(){4===d.readyState&&i()}function n(){var t=void 0;if(t=d.response?d.response:d.responseText||u(d),j)try{t=JSON.parse(t)}catch(t){}return t}function r(t){return clearTimeout(m),t instanceof Error||(t=new Error(""+(t||"Unknown XMLHttpRequest Error"))),t.statusCode=0,c(t,f)}function i(){if(!h){var e;clearTimeout(m),e=t.useXDR&&void 0===d.status?200:1223===d.status?204:d.status;var r=f,o=null;return 0!==e?(r={body:n(),statusCode:e,method:v,headers:{},url:y,rawRequest:d},d.getAllResponseHeaders&&(r.headers=l(d.getAllResponseHeaders()))):o=new Error("Internal XMLHttpRequest Error"),c(o,r,r.body)}}if("undefined"==typeof t.callback)throw new Error("callback argument missing");var a=!1,c=function(e,n,r){a||(a=!0,t.callback(e,n,r))},f={body:void 0,headers:{},statusCode:0,method:v,url:y,rawRequest:d},d=t.xhr||null;d||(d=t.cors||t.useXDR?new s.XDomainRequest:new s.XMLHttpRequest);var p,h,m,y=d.url=t.uri||t.url,v=d.method=t.method||"GET",w=t.body||t.data||null,g=d.headers=t.headers||{},b=!!t.sync,j=!1;if("json"in t&&(j=!0,g.accept||g.Accept||(g.Accept="application/json"),"GET"!==v&&"HEAD"!==v&&(g["content-type"]||g["Content-Type"]||(g["Content-Type"]="application/json"),w=JSON.stringify(t.json))),d.onreadystatechange=e,d.onload=i,d.onerror=r,d.onprogress=function(){},d.ontimeout=r,d.open(v,y,!b,t.username,t.password),b||(d.withCredentials=!!t.withCredentials),!b&&t.timeout>0&&(m=setTimeout(function(){h=!0,d.abort("timeout");var t=new Error("XMLHttpRequest timeout");t.code="ETIMEDOUT",r(t)},t.timeout)),d.setRequestHeader)for(p in g)g.hasOwnProperty(p)&&d.setRequestHeader(p,g[p]);else if(t.headers&&!o(t.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in t&&(d.responseType=t.responseType),"beforeSend"in t&&"function"==typeof t.beforeSend&&t.beforeSend(d),d.send(w),d}function u(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"),d=t("is-function"),l=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=i(e,n,r),n.method=t.toUpperCase(),a(n)}})},{"global/window":18,"is-function":19,"parse-headers":21,xtend:24}],24:[function(t,e,n){function r(){for(var t={},e=0;e<arguments.length;e++){var n=arguments[e];for(var r in n)o.call(n,r)&&(t[r]=n[r])}return t}e.exports=r;var o=Object.prototype.hasOwnProperty},{}],25:[function(t,e,n){function r(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)o.call(n,r)&&(t[r]=n[r])}return t}e.exports=r;var o=Object.prototype.hasOwnProperty},{}]},{},[12])(12)}); |
Sorry, the diff of this file is not supported yet
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
133625
36
1446