Socket
Socket
Sign inDemoInstall

picosanity

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

picosanity - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

6

CHANGELOG.md

@@ -5,2 +5,8 @@ # Change Log

## 3.0.2
### Changed
- Implicitly add support for CloudFlare Workers and other non-browser, non-node environments by not referencing `window`, not passing `credentials` option to `fetch()`
## 3.0.1

@@ -7,0 +13,0 @@

2

lib/browser.js

@@ -7,4 +7,4 @@ "use strict";

return new Client(cfg, function (input, init) {
return window.fetch(input, init);
return fetch(input, init);
});
};

@@ -42,6 +42,15 @@ "use strict";

} : undefined;
var headers = Object.assign({}, auth, type);
var headers = Object.assign({}, auth, type); // Some environments (like CloudFlare Workers) don't support credentials
// in fetch() RequestInitDict, and there doesn't seem to be any easy way
// to check of it, so for now we'll make do with a window check :/
var credentials;
if (typeof window !== 'undefined') {
credentials = cfg.withCredentials ? 'include' : 'omit';
}
var host = !cfg.useCdn || cfg.token || usePost ? apiHost : cdnHost;
var opts = {
credentials: cfg.withCredentials ? 'include' : 'omit',
credentials: credentials,
headers: headers,

@@ -48,0 +57,0 @@ method: usePost ? 'POST' : 'GET',

{
"name": "picosanity",
"version": "3.0.1",
"version": "3.0.2",
"description": "Tiny Sanity client alternative should you only need to do queries",

@@ -39,13 +39,13 @@ "main": "lib/index.js",

"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"eslint": "^7.0.0",
"eslint-config-prettier": "^7.0.0",
"eslint-config-sanity": "^5.0.0",
"jest": "^26.0.0",
"prettier": "^2.0.0",
"@babel/cli": "^7.15.7",
"@babel/preset-env": "^7.15.6",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-sanity": "^5.1.0",
"jest": "^27.2.1",
"prettier": "^2.4.1",
"rimraf": "^3.0.0",
"webpack": "^5.0.0",
"webpack-cli": "^4.0.0"
"webpack": "^5.53.0",
"webpack-cli": "^4.8.0"
}
}
const Client = require('./client')
module.exports = function (cfg) {
return new Client(cfg, (input, init) => window.fetch(input, init))
return new Client(cfg, (input, init) => fetch(input, init))
}

@@ -47,5 +47,13 @@ const enc = encodeURIComponent

// Some environments (like CloudFlare Workers) don't support credentials
// in fetch() RequestInitDict, and there doesn't seem to be any easy way
// to check of it, so for now we'll make do with a window check :/
let credentials
if (typeof window !== 'undefined') {
credentials = cfg.withCredentials ? 'include' : 'omit'
}
const host = !cfg.useCdn || cfg.token || usePost ? apiHost : cdnHost
const opts = {
credentials: cfg.withCredentials ? 'include' : 'omit',
credentials,
headers,

@@ -52,0 +60,0 @@ method: usePost ? 'POST' : 'GET',

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

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.PicoSanity=e():t.PicoSanity=e()}(self,(function(){return(()=>{"use strict";var t={693:(t,e,n)=>{var o=n(26);t.exports=function(t){return new o(t,(function(t,e){return window.fetch(t,e)}))}},26:t=>{var e=encodeURIComponent,n={}.hasOwnProperty;function o(t,e){if(!(this instanceof o))return new o(t);this.clientConfig=t,this.fetcher=e}function r(t){if(!(t.headers.get("content-type")||"").includes("json"))throw i(t);return t.json().then((function(e){if(t.status<400)return e.result;throw i(t,e)}))}function i(t,e){var n=t.url,o=t.statusText;return e&&e.error&&e.error.description&&(n=e.error.description,o=e.error.type||o),new Error("HTTP ".concat(t.status," ").concat(o,": ").concat(n))}["clone","create","createIfNotExists","createOrReplace","delete","listen","mutate","patch","transaction"].forEach((function(t){o.prototype[t]=function(t){return function(){throw new Error('Method "'.concat(t,'" not implemented, use @sanity/client'))}}(t)})),o.prototype.config=function(t){return t?(this.clientConfig=Object.assign({},this.clientConfig,t),this):this.clientConfig},o.prototype.fetch=function(t,o){var i=this.clientConfig,c=i.apiVersion?"v".concat(i.apiVersion.replace(/^v/,"")):"v1",a=function(t,o){var r="?query=".concat(e(t));if(!o)return r;for(var i in o)n.call(o,i)&&(r+="&".concat(e("$".concat(i)),"=").concat(e(JSON.stringify(o[i]))));return r}(t,o),s=a.length>11264,u=i.token?{Authorization:"Bearer ".concat(i.token)}:void 0,f=s?{"content-type":"application/json"}:void 0,p=Object.assign({},u,f),d=!i.useCdn||i.token||s?"api.sanity.io":"apicdn.sanity.io",h={credentials:i.withCredentials?"include":"omit",headers:p,method:s?"POST":"GET",body:s?JSON.stringify({query:t,params:o}):void 0},l="https://".concat(i.projectId,".").concat(d,"/").concat(c,"/data/query/").concat(i.dataset);return this.fetcher("".concat(l).concat(s?"":a),h).then(r)},t.exports=o}},e={};return function n(o){if(e[o])return e[o].exports;var r=e[o]={exports:{}};return t[o](r,r.exports,n),r.exports}(693)})()}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.PicoSanity=e():t.PicoSanity=e()}(self,(function(){return(()=>{"use strict";var t={693:(t,e,n)=>{var o=n(26);t.exports=function(t){return new o(t,(function(t,e){return fetch(t,e)}))}},26:t=>{var e=encodeURIComponent,n={}.hasOwnProperty;function o(t,e){if(!(this instanceof o))return new o(t);this.clientConfig=t,this.fetcher=e}function r(t){if(!(t.headers.get("content-type")||"").includes("json"))throw i(t);return t.json().then((function(e){if(t.status<400)return e.result;throw i(t,e)}))}function i(t,e){var n=t.url,o=t.statusText;return e&&e.error&&e.error.description&&(n=e.error.description,o=e.error.type||o),new Error("HTTP ".concat(t.status," ").concat(o,": ").concat(n))}["clone","create","createIfNotExists","createOrReplace","delete","listen","mutate","patch","transaction"].forEach((function(t){o.prototype[t]=function(t){return function(){throw new Error('Method "'.concat(t,'" not implemented, use @sanity/client'))}}(t)})),o.prototype.config=function(t){return t?(this.clientConfig=Object.assign({},this.clientConfig,t),this):this.clientConfig},o.prototype.fetch=function(t,o){var i,c=this.clientConfig,a=c.apiVersion?"v".concat(c.apiVersion.replace(/^v/,"")):"v1",s=function(t,o){var r="?query=".concat(e(t));if(!o)return r;for(var i in o)n.call(o,i)&&(r+="&".concat(e("$".concat(i)),"=").concat(e(JSON.stringify(o[i]))));return r}(t,o),u=s.length>11264,f=c.token?{Authorization:"Bearer ".concat(c.token)}:void 0,p=u?{"content-type":"application/json"}:void 0,d=Object.assign({},f,p);"undefined"!=typeof window&&(i=c.withCredentials?"include":"omit");var h=!c.useCdn||c.token||u?"api.sanity.io":"apicdn.sanity.io",l={credentials:i,headers:d,method:u?"POST":"GET",body:u?JSON.stringify({query:t,params:o}):void 0},y="https://".concat(c.projectId,".").concat(h,"/").concat(a,"/data/query/").concat(c.dataset);return this.fetcher("".concat(y).concat(u?"":s),l).then(r)},t.exports=o}},e={};return function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}(693)})()}));
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc