Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.3 to 4.0.0

12

CHANGELOG.md

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

## 4.0.0
### BREAKING
- BREAKING: Passing a `token` _and_ `useCdn: true` will now use the API CDN for queries, where it previously used the uncached, "live" API.
## 3.0.3
### Fixed
- Fixed an issue where certain environments would throw an error when `credentials` was provided to `fetch` with the value of `undefined`
## 3.0.2

@@ -7,0 +19,0 @@

6

lib/browser.js

@@ -6,5 +6,9 @@ "use strict";

module.exports = function (cfg) {
return new Client(cfg, function (input, init) {
var fetcher = function fetcher(input, init) {
return fetch(input, init);
};
return new Client(cfg, {
fetch: fetcher
});
};

21

lib/client.js

@@ -8,3 +8,3 @@ "use strict";

function PicoSanity(config, fetcher) {
function PicoSanity(config, options) {
if (!(this instanceof PicoSanity)) {

@@ -15,3 +15,4 @@ return new PicoSanity(config);

this.clientConfig = config;
this.fetcher = fetcher;
this.fetcher = options.fetch;
this.headers = options.headers || {};
}

@@ -44,15 +45,19 @@

} : undefined;
var headers = Object.assign({}, auth, type);
var host = !cfg.useCdn || cfg.token || usePost ? apiHost : cdnHost;
var headers = Object.assign({}, this.headers, auth, type);
var host = cfg.useCdn ? cdnHost : apiHost;
var opts = {
headers: headers,
method: usePost ? 'POST' : 'GET',
body: usePost ? JSON.stringify({
method: usePost ? 'POST' : 'GET'
};
if (usePost) {
opts.body = JSON.stringify({
query: query,
params: params
}) : undefined
}; // Some environments (like CloudFlare Workers) don't support credentials
});
} // 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 :/
if (typeof window !== 'undefined') {

@@ -59,0 +64,0 @@ opts.credentials = cfg.withCredentials ? 'include' : 'omit';

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

var pkg = require('../package.json');
module.exports = function (cfg) {
return new Client(cfg, fetch);
return new Client(cfg, {
headers: {
'User-Agent': "".concat(pkg.name, "@").concat(pkg.version)
},
fetch: fetch
});
};
{
"name": "picosanity",
"version": "3.0.3",
"version": "4.0.0",
"description": "Tiny Sanity client alternative should you only need to do queries",

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

"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/preset-env": "^7.15.6",
"eslint": "^7.32.0",
"@babel/cli": "^7.17.3",
"@babel/preset-env": "^7.16.11",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-sanity": "^5.1.0",
"jest": "^27.2.1",
"prettier": "^2.4.1",
"jest": "^27.5.1",
"prettier": "^2.5.1",
"rimraf": "^3.0.0",
"webpack": "^5.53.0",
"webpack-cli": "^4.8.0"
"webpack": "^5.69.0",
"webpack-cli": "^4.9.2"
}
}
const Client = require('./client')
module.exports = function (cfg) {
return new Client(cfg, (input, init) => fetch(input, init))
const fetcher = (input, init) => fetch(input, init)
return new Client(cfg, {fetch: fetcher})
}

@@ -6,3 +6,3 @@ const enc = encodeURIComponent

function PicoSanity(config, fetcher) {
function PicoSanity(config, options) {
if (!(this instanceof PicoSanity)) {

@@ -13,3 +13,4 @@ return new PicoSanity(config)

this.clientConfig = config
this.fetcher = fetcher
this.fetcher = options.fetch
this.headers = options.headers || {}
}

@@ -47,11 +48,14 @@

const type = usePost ? {'content-type': 'application/json'} : undefined
const headers = Object.assign({}, auth, type)
const headers = Object.assign({}, this.headers, auth, type)
const host = !cfg.useCdn || cfg.token || usePost ? apiHost : cdnHost
const host = cfg.useCdn ? cdnHost : apiHost
const opts = {
headers,
method: usePost ? 'POST' : 'GET',
body: usePost ? JSON.stringify({query, params}) : undefined,
}
if (usePost) {
opts.body = JSON.stringify({query, params})
}
// Some environments (like CloudFlare Workers) don't support credentials

@@ -58,0 +62,0 @@ // in fetch() RequestInitDict, and there doesn't seem to be any easy way

const fetch = require('node-fetch')
const Client = require('./client')
const pkg = require('../package.json')
module.exports = function (cfg) {
return new Client(cfg, fetch)
return new Client(cfg, {
headers: {'User-Agent': `${pkg.name}@${pkg.version}`},
fetch,
})
}

@@ -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 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={headers:p,method:s?"POST":"GET",body:s?JSON.stringify({query:t,params:o}):void 0};"undefined"!=typeof window&&(h.credentials=i.withCredentials?"include":"omit");var 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){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)})()}));
!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,{fetch: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.fetch,this.headers=e.headers||{}}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,f=i.token?{Authorization:"Bearer ".concat(i.token)}:void 0,u=s?{"content-type":"application/json"}:void 0,p=Object.assign({},this.headers,f,u),h=i.useCdn?"apicdn.sanity.io":"api.sanity.io",d={headers:p,method:s?"POST":"GET"};s&&(d.body=JSON.stringify({query:t,params:o})),"undefined"!=typeof window&&(d.credentials=i.withCredentials?"include":"omit");var l="https://".concat(i.projectId,".").concat(h,"/").concat(c,"/data/query/").concat(i.dataset);return this.fetcher("".concat(l).concat(s?"":a),d).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