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

@shopify/theme-predictive-search

Package Overview
Dependencies
Maintainers
19
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/theme-predictive-search - npm Package Compare versions

Comparing version 4.0.2 to 4.1.0

43

__tests__/request.test.js

@@ -24,3 +24,3 @@ import xhrMock from "xhr-mock";

request("config=foo", "foo-200", spyOnSucess);
request("/search", "config=foo", "foo-200", spyOnSucess);

@@ -35,2 +35,21 @@ jest.runAllTimers();

it("valid with locale search route", () => {
const spyOnSucess = jest.fn();
xhrMock.get(/^(\/[a-z-]*)?\/search\/suggest\.json/g, (req, res) =>
res
.status(200)
.header("Content-Type", "application/json; charset=utf-8")
.body(JSON.stringify({ foo: "bar" }))
);
request('/pt-pt/search', "config=foo", "foo-200", spyOnSucess);
jest.runAllTimers();
expect(spyOnSucess).toHaveBeenNthCalledWith(1, {
query: "foo-200",
foo: "bar"
});
});
it("valid with Content-Type with uppercase characters", () => {

@@ -45,3 +64,3 @@ const spyOnSucess = jest.fn();

request("config=foo", "foo-200", spyOnSucess);
request("/search", "config=foo", "foo-200", spyOnSucess);

@@ -64,3 +83,3 @@ jest.runAllTimers();

request("config=foo", "foo-200-invalid", null, error => {
request("/search", "config=foo", "foo-200-invalid", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -85,3 +104,3 @@ expect(error.status).toBe(200);

request("config=foo", "foo-200-invalid", null, error => {
request("/search", "config=foo", "foo-200-invalid", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -103,3 +122,3 @@ expect(error.status).toBe(200);

request("config=foo", "foo-200-invalid", null, error => {
request("/search", "config=foo", "foo-200-invalid", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -127,3 +146,3 @@ expect(error.status).toBe(200);

request("config=foo", "foo-404", null, error => {
request("/search", "config=foo", "foo-404", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -154,3 +173,3 @@ expect(error.status).toBe(404);

request("config=foo", "foo-422", null, error => {
request("/search", "config=foo", "foo-422", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -175,3 +194,3 @@ expect(error.status).toBe(422);

request("config=foo", "foo-422-invalid", null, error => {
request("/search", "config=foo", "foo-422-invalid", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -203,3 +222,3 @@ expect(error.status).toBe(422);

request("config=foo", "foo-429", null, error => {
request("/search", "config=foo", "foo-429", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -225,3 +244,3 @@ expect(error.status).toBe(429);

request("config=foo", "foo-429-invalid", null, error => {
request("/search", "config=foo", "foo-429-invalid", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -252,3 +271,3 @@ expect(error.status).toBe(429);

request("config=foo", "foo-417", null, error => {
request("/search", "config=foo", "foo-417", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -270,3 +289,3 @@ expect(error.status).toBe(417);

request("config=foo", "foo-500", null, error => {
request("/search", "config=foo", "foo-500", null, error => {
expect(error).toBeInstanceOf(Error);

@@ -273,0 +292,0 @@ expect(error.status).toBe(500);

@@ -7,2 +7,3 @@ import xhrMock from "xhr-mock";

const defaultConfig = {
search_path: PredictiveSearch.SEARCH_PATH,
resources: {

@@ -9,0 +10,0 @@ type: [PredictiveSearch.TYPES.PRODUCT],

@@ -100,4 +100,5 @@ 'use strict';

function request(configParams, query, onSuccess, onError) {
function request(searchPath, configParams, query, onSuccess, onError) {
var xhr = new XMLHttpRequest();
var route = searchPath + '/suggest.json';

@@ -215,3 +216,3 @@ xhr.onreadystatechange = function () {

"get",
"/search/suggest.json?q=" + encodeURIComponent(query) + "&" + configParams
route + "?q=" + encodeURIComponent(query) + "&" + configParams
);

@@ -374,2 +375,4 @@

var configParameters = config;
this._retryAfter = null;

@@ -380,9 +383,19 @@ this._currentQuery = null;

this.cache = new Cache({ bucketSize: 40 });
this.configParams = objectToQueryParams(config);
this.searchPath = configParameters.search_path || "/search";
if(configParameters.search_path) {
delete configParameters['search_path'];
}
this.configParams = objectToQueryParams(configParameters);
}
PredictiveSearch.SEARCH_PATH = "/search";
PredictiveSearch.TYPES = {
PRODUCT: "product",
PAGE: "page",
ARTICLE: "article"
ARTICLE: "article",
COLLECTION: "collection"
};

@@ -428,2 +441,3 @@

requestDebounced(
this.searchPath,
this.configParams,

@@ -430,0 +444,0 @@ query,

@@ -103,4 +103,5 @@ this.Shopify = this.Shopify || {};

function request(configParams, query, onSuccess, onError) {
function request(searchPath, configParams, query, onSuccess, onError) {
var xhr = new XMLHttpRequest();
var route = searchPath + '/suggest.json';

@@ -218,3 +219,3 @@ xhr.onreadystatechange = function () {

"get",
"/search/suggest.json?q=" + encodeURIComponent(query) + "&" + configParams
route + "?q=" + encodeURIComponent(query) + "&" + configParams
);

@@ -377,2 +378,4 @@

var configParameters = config;
this._retryAfter = null;

@@ -383,9 +386,19 @@ this._currentQuery = null;

this.cache = new Cache({ bucketSize: 40 });
this.configParams = objectToQueryParams(config);
this.searchPath = configParameters.search_path || "/search";
if(configParameters.search_path) {
delete configParameters['search_path'];
}
this.configParams = objectToQueryParams(configParameters);
}
PredictiveSearch.SEARCH_PATH = "/search";
PredictiveSearch.TYPES = {
PRODUCT: "product",
PAGE: "page",
ARTICLE: "article"
ARTICLE: "article",
COLLECTION: "collection"
};

@@ -431,2 +444,3 @@

requestDebounced(
this.searchPath,
this.configParams,

@@ -433,0 +447,0 @@ query,

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

this.Shopify=this.Shopify||{},this.Shopify.theme=this.Shopify.theme||{},this.Shopify.theme.PredictiveSearch=function(){"use strict";function h(){var t=Error.call(this);return t.name="Server error",t.message="Something went wrong on the server",t.status=500,t}function p(t){var e=Error.call(this);return e.name="Not found",e.message="Not found",e.status=t,e}function f(){var t=Error.call(this);return t.name="Server error",t.message="Something went wrong on the server",t.status=500,t}function l(t){var e=Error.call(this);return e.name="Content-Type error",e.message="Content-Type was not provided or is of wrong type",e.status=t,e}function y(t){var e=Error.call(this);return e.name="JSON parse error",e.message="JSON syntax error",e.status=t,e}function d(t,e,r,s){var n=Error.call(this);return n.name=e,n.message=r,n.status=t,n.retryAfter=s,n}function v(t,e,r){var s=Error.call(this);return s.name=e,s.message=r,s.status=t,s}function g(t,e,r){var s=Error.call(this);return s.name=e,s.message=r,s.status=t,s}function e(t){this._store={},this._keys=[],t&&t.bucketSize?this.bucketSize=t.bucketSize:this.bucketSize=20}function r(){this.events={}}function s(t){this.eventName=t,this.callbacks=[]}function o(s,n){var i="";return n=n||null,Object.keys(s).forEach(function(t){var e,r=t+"=";switch(n&&(r=n+"["+t+"]"),e=s[t],Object.prototype.toString.call(e).slice(8,-1).toLowerCase()){case"object":i+=o(s[t],n?r:t);break;case"array":i+=r+"="+s[t].join(",")+"&";break;default:n&&(r+="="),i+=r+encodeURIComponent(s[t])+"&"}}),i}e.prototype.set=function(t,e){if(this.count()>=this.bucketSize){var r=this._keys.splice(0,1);this.delete(r)}return this._keys.push(t),this._store[t]=e,this._store},e.prototype.get=function(t){return this._store[t]},e.prototype.has=function(t){return Boolean(this._store[t])},e.prototype.count=function(){return Object.keys(this._store).length},e.prototype.delete=function(t){var e=Boolean(this._store[t]);return delete this._store[t],e&&!this._store[t]},r.prototype.on=function(t,e){var r=this.events[t];r||(r=new s(t),this.events[t]=r),r.registerCallback(e)},r.prototype.off=function(t,e){var r=this.events[t];r&&-1<r.callbacks.indexOf(e)&&(r.unregisterCallback(e),0===r.callbacks.length&&delete this.events[t])},r.prototype.dispatch=function(t,e){var r=this.events[t];r&&r.fire(e)},s.prototype.registerCallback=function(t){this.callbacks.push(t)},s.prototype.unregisterCallback=function(t){var e=this.callbacks.indexOf(t);-1<e&&this.callbacks.splice(e,1)},s.prototype.fire=function(e){this.callbacks.slice(0).forEach(function(t){t(e)})};var n,i,a,c=(n=function(t,o,a,c){var u=new XMLHttpRequest;u.onreadystatechange=function(){if(u.readyState!==XMLHttpRequest.DONE);else{var t=u.getResponseHeader("Content-Type");if(500<=u.status)return void c(new f);if(404===u.status)return void c(new p(u.status));if("string"!=typeof t||null===t.toLowerCase().match("application/json"))return void c(new l(u.status));if(417===u.status){try{var e=JSON.parse(u.responseText);c(new v(u.status,e.message,e.description))}catch(t){c(new y(u.status))}return}if(422===u.status){try{var r=JSON.parse(u.responseText);c(new g(u.status,r.message,r.description))}catch(t){c(new y(u.status))}return}if(429===u.status){try{var s=JSON.parse(u.responseText);c(new d(u.status,s.message,s.description,u.getResponseHeader("Retry-After")))}catch(t){c(new y(u.status))}return}if(200===u.status){try{var n=JSON.parse(u.responseText);n.query=o,a(n)}catch(t){c(new y(u.status))}return}try{var i=JSON.parse(u.responseText);c(new h(u.status,i.message,i.description))}catch(t){c(new y(u.status))}}},u.open("get","/search/suggest.json?q="+encodeURIComponent(o)+"&"+t),u.setRequestHeader("Content-Type","application/json"),u.send()},i=10,a=null,function(){var t=this,e=arguments;clearTimeout(a),a=setTimeout(function(){a=null,n.apply(t,e)},i||0)});function t(t){if(!t)throw new TypeError("No config object was specified");this._retryAfter=null,this._currentQuery=null,this.dispatcher=new r,this.cache=new e({bucketSize:40}),this.configParams=o(t)}function u(t){return"string"!=typeof t?null:t.trim().replace(" ","-").toLowerCase()}return t.TYPES={PRODUCT:"product",PAGE:"page",ARTICLE:"article"},t.FIELDS={AUTHOR:"author",BODY:"body",PRODUCT_TYPE:"product_type",TAG:"tag",TITLE:"title",VARIANTS_BARCODE:"variants.barcode",VARIANTS_SKU:"variants.sku",VARIANTS_TITLE:"variants.title",VENDOR:"vendor"},t.UNAVAILABLE_PRODUCTS={SHOW:"show",HIDE:"hide",LAST:"last"},t.prototype.query=function(t){try{!function(t){var e;if(null==t)throw(e=new TypeError("'query' is missing")).type="argument",e;if("string"!=typeof t)throw(e=new TypeError("'query' is not a string")).type="argument",e}(t)}catch(t){return void this.dispatcher.dispatch("error",t)}if(""===t)return this;this._currentQuery=u(t);var e=this.cache.get(this._currentQuery);return e?this.dispatcher.dispatch("success",e):c(this.configParams,t,function(t){this.cache.set(u(t.query),t),u(t.query)===this._currentQuery&&(this._retryAfter=null,this.dispatcher.dispatch("success",t))}.bind(this),function(t){t.retryAfter&&(this._retryAfter=t.retryAfter),this.dispatcher.dispatch("error",t)}.bind(this)),this},t.prototype.on=function(t,e){return this.dispatcher.on(t,e),this},t.prototype.off=function(t,e){return this.dispatcher.off(t,e),this},t}();
this.Shopify=this.Shopify||{},this.Shopify.theme=this.Shopify.theme||{},this.Shopify.theme.PredictiveSearch=function(){"use strict";function h(){var t=Error.call(this);return t.name="Server error",t.message="Something went wrong on the server",t.status=500,t}function p(t){var e=Error.call(this);return e.name="Not found",e.message="Not found",e.status=t,e}function f(){var t=Error.call(this);return t.name="Server error",t.message="Something went wrong on the server",t.status=500,t}function l(t){var e=Error.call(this);return e.name="Content-Type error",e.message="Content-Type was not provided or is of wrong type",e.status=t,e}function y(t){var e=Error.call(this);return e.name="JSON parse error",e.message="JSON syntax error",e.status=t,e}function d(t,e,r,s){var n=Error.call(this);return n.name=e,n.message=r,n.status=t,n.retryAfter=s,n}function v(t,e,r){var s=Error.call(this);return s.name=e,s.message=r,s.status=t,s}function g(t,e,r){var s=Error.call(this);return s.name=e,s.message=r,s.status=t,s}function r(t){this._store={},this._keys=[],t&&t.bucketSize?this.bucketSize=t.bucketSize:this.bucketSize=20}function s(){this.events={}}function n(t){this.eventName=t,this.callbacks=[]}function a(s,n){var i="";return n=n||null,Object.keys(s).forEach(function(t){var e,r=t+"=";switch(n&&(r=n+"["+t+"]"),e=s[t],Object.prototype.toString.call(e).slice(8,-1).toLowerCase()){case"object":i+=a(s[t],n?r:t);break;case"array":i+=r+"="+s[t].join(",")+"&";break;default:n&&(r+="="),i+=r+encodeURIComponent(s[t])+"&"}}),i}r.prototype.set=function(t,e){if(this.count()>=this.bucketSize){var r=this._keys.splice(0,1);this.delete(r)}return this._keys.push(t),this._store[t]=e,this._store},r.prototype.get=function(t){return this._store[t]},r.prototype.has=function(t){return Boolean(this._store[t])},r.prototype.count=function(){return Object.keys(this._store).length},r.prototype.delete=function(t){var e=Boolean(this._store[t]);return delete this._store[t],e&&!this._store[t]},s.prototype.on=function(t,e){var r=this.events[t];r||(r=new n(t),this.events[t]=r),r.registerCallback(e)},s.prototype.off=function(t,e){var r=this.events[t];r&&-1<r.callbacks.indexOf(e)&&(r.unregisterCallback(e),0===r.callbacks.length&&delete this.events[t])},s.prototype.dispatch=function(t,e){var r=this.events[t];r&&r.fire(e)},n.prototype.registerCallback=function(t){this.callbacks.push(t)},n.prototype.unregisterCallback=function(t){var e=this.callbacks.indexOf(t);-1<e&&this.callbacks.splice(e,1)},n.prototype.fire=function(e){this.callbacks.slice(0).forEach(function(t){t(e)})};var i,o,c,u=(i=function(t,e,a,o,c){var u=new XMLHttpRequest,r=t+"/suggest.json";u.onreadystatechange=function(){if(u.readyState!==XMLHttpRequest.DONE);else{var t=u.getResponseHeader("Content-Type");if(500<=u.status)return void c(new f);if(404===u.status)return void c(new p(u.status));if("string"!=typeof t||null===t.toLowerCase().match("application/json"))return void c(new l(u.status));if(417===u.status){try{var e=JSON.parse(u.responseText);c(new v(u.status,e.message,e.description))}catch(t){c(new y(u.status))}return}if(422===u.status){try{var r=JSON.parse(u.responseText);c(new g(u.status,r.message,r.description))}catch(t){c(new y(u.status))}return}if(429===u.status){try{var s=JSON.parse(u.responseText);c(new d(u.status,s.message,s.description,u.getResponseHeader("Retry-After")))}catch(t){c(new y(u.status))}return}if(200===u.status){try{var n=JSON.parse(u.responseText);n.query=a,o(n)}catch(t){c(new y(u.status))}return}try{var i=JSON.parse(u.responseText);c(new h(u.status,i.message,i.description))}catch(t){c(new y(u.status))}}},u.open("get",r+"?q="+encodeURIComponent(a)+"&"+e),u.setRequestHeader("Content-Type","application/json"),u.send()},o=10,c=null,function(){var t=this,e=arguments;clearTimeout(c),c=setTimeout(function(){c=null,i.apply(t,e)},o||0)});function t(t){if(!t)throw new TypeError("No config object was specified");var e=t;this._retryAfter=null,this._currentQuery=null,this.dispatcher=new s,this.cache=new r({bucketSize:40}),this.searchPath=e.search_path||"/search",e.search_path&&delete e.search_path,this.configParams=a(e)}function m(t){return"string"!=typeof t?null:t.trim().replace(" ","-").toLowerCase()}return t.SEARCH_PATH="/search",t.TYPES={PRODUCT:"product",PAGE:"page",ARTICLE:"article",COLLECTION:"collection"},t.FIELDS={AUTHOR:"author",BODY:"body",PRODUCT_TYPE:"product_type",TAG:"tag",TITLE:"title",VARIANTS_BARCODE:"variants.barcode",VARIANTS_SKU:"variants.sku",VARIANTS_TITLE:"variants.title",VENDOR:"vendor"},t.UNAVAILABLE_PRODUCTS={SHOW:"show",HIDE:"hide",LAST:"last"},t.prototype.query=function(t){try{!function(t){var e;if(null==t)throw(e=new TypeError("'query' is missing")).type="argument",e;if("string"!=typeof t)throw(e=new TypeError("'query' is not a string")).type="argument",e}(t)}catch(t){return void this.dispatcher.dispatch("error",t)}if(""===t)return this;this._currentQuery=m(t);var e=this.cache.get(this._currentQuery);return e?this.dispatcher.dispatch("success",e):u(this.searchPath,this.configParams,t,function(t){this.cache.set(m(t.query),t),m(t.query)===this._currentQuery&&(this._retryAfter=null,this.dispatcher.dispatch("success",t))}.bind(this),function(t){t.retryAfter&&(this._retryAfter=t.retryAfter),this.dispatcher.dispatch("error",t)}.bind(this)),this},t.prototype.on=function(t,e){return this.dispatcher.on(t,e),this},t.prototype.off=function(t,e){return this.dispatcher.off(t,e),this},t}();
{
"name": "@shopify/theme-predictive-search",
"version": "4.0.2",
"version": "4.1.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Shopify AJAX Predictive Search API",

@@ -12,2 +12,7 @@ ## Shopify Predictive Search JS API

<tr>
<td><code>search_path</code> (optional)</td>
<td>String</td>
<td>Search path to prepend the predictive search route in different locales (e.g. <code>/fr/search</code>). Default to <code>/search</code></td>
</tr>
<tr>
<td><code>resources</code> (required)</td>

@@ -20,3 +25,3 @@ <td>Object</td>

<td>Array</td>
<td>Specifies the type of results requested. Valid values: <code>product</code>, <code>page</code>, <code>article</code>.</td>
<td>Specifies the type of results requested. Valid values: <code>product</code>, <code>page</code>, <code>article</code>, <code>collection</code>.</td>
</tr>

@@ -55,2 +60,3 @@ <tr>

var predictiveSearch = new PredictiveSearch({
search_path: PredictiveSearch.SEARCH_PATH,
resources: {

@@ -57,0 +63,0 @@ type: [PredictiveSearch.TYPES.PRODUCT],

@@ -12,4 +12,5 @@ import {

export default function request(configParams, query, onSuccess, onError) {
export default function request(searchPath, configParams, query, onSuccess, onError) {
var xhr = new XMLHttpRequest();
var route = searchPath + '/suggest.json';

@@ -127,3 +128,3 @@ xhr.onreadystatechange = function () {

"get",
"/search/suggest.json?q=" + encodeURIComponent(query) + "&" + configParams
route + "?q=" + encodeURIComponent(query) + "&" + configParams
);

@@ -130,0 +131,0 @@

@@ -13,2 +13,4 @@ import { validateQuery } from "./validate";

var configParameters = config;
this._retryAfter = null;

@@ -19,9 +21,19 @@ this._currentQuery = null;

this.cache = new Cache({ bucketSize: 40 });
this.configParams = objectToQueryParams(config);
this.searchPath = configParameters.search_path || "/search";
if(configParameters.search_path) {
delete configParameters['search_path'];
}
this.configParams = objectToQueryParams(configParameters);
}
PredictiveSearch.SEARCH_PATH = "/search";
PredictiveSearch.TYPES = {
PRODUCT: "product",
PAGE: "page",
ARTICLE: "article"
ARTICLE: "article",
COLLECTION: "collection"
};

@@ -67,2 +79,3 @@

requestDebounced(
this.searchPath,
this.configParams,

@@ -69,0 +82,0 @@ query,

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