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

@commercetools/frontend-sdk

Package Overview
Dependencies
Maintainers
2
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools/frontend-sdk - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

lib/helpers/queryStringHelpers.d.ts

6

CHANGELOG.md
## Version 1.2.1 (2023-02-28)
* Added support for arrays in action queries
## Version 1.2.0 (2023-02-28)

@@ -3,0 +9,0 @@

4

lib/index.js

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

"use strict";var w=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var S=(r,e)=>{for(var t in e)w(r,t,{get:e[t],enumerable:!0})},A=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of R(e))!F.call(r,o)&&o!==t&&w(r,o,{get:()=>e[o],enumerable:!(n=I(e,o))||n.enumerable});return r};var k=r=>A(w({},"__esModule",{value:!0}),r);var H={};S(H,{ActionError:()=>p,Event:()=>d,Extension:()=>f,FetchError:()=>a,PageError:()=>u,SDK:()=>g,rememberMeCookie:()=>m});module.exports=k(H);var x="__rememberMe",m={get:function(){return!!(typeof window<"u"&&window.localStorage.getItem(x))},set:function(r){typeof window<"u"&&(r&&window.localStorage.setItem(x,"1"),this.remove())},remove:function(){typeof window<"u"&&window.localStorage.removeItem(x)}};var f=class{sdk;constructor(e){this.sdk=e}};function h(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)r[n]=t[n]}return r}var L={read:function(r){return r[0]==='"'&&(r=r.slice(1,-1)),r.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(r){return encodeURIComponent(r).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function C(r,e){function t(o,s,i){if(!(typeof document>"u")){i=h({},e,i),typeof i.expires=="number"&&(i.expires=new Date(Date.now()+i.expires*864e5)),i.expires&&(i.expires=i.expires.toUTCString()),o=encodeURIComponent(o).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var l in i)!i[l]||(c+="; "+l,i[l]!==!0&&(c+="="+i[l].split(";")[0]));return document.cookie=o+"="+r.write(s,o)+c}}function n(o){if(!(typeof document>"u"||arguments.length&&!o)){for(var s=document.cookie?document.cookie.split("; "):[],i={},c=0;c<s.length;c++){var l=s[c].split("="),D=l.slice(1).join("=");try{var y=decodeURIComponent(l[0]);if(i[y]=r.read(D,y),o===y)break}catch{}}return o?i[o]:i}}return Object.create({set:t,get:n,remove:function(o,s){t(o,"",h({},s,{expires:-1}))},withAttributes:function(o){return C(this.converter,h({},this.attributes,o))},withConverter:function(o){return C(h({},this.converter,o),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(r)}})}var T=C(L,{path:"/"}),N=T;var a=class extends Error{constructor(e){super(),this.isError=!0,typeof e=="string"?this.message=e:Object.keys(e).forEach(t=>{this[t]=e[t]})}isError;message};var b=N.withAttributes({path:"/"}),P=async(r,e={})=>{let t=b.get("frontastic-session");e.headers={"Content-Type":"application/json",Accept:"application/json","X-Frontastic-Access-Token":process.env.NEXT_PUBLIC_EXT_BUILD_ID??"APIKEY",...e.headers||{},...t?{"Frontastic-Session":t}:{}};let n=await fetch(r,e);if(typeof window<"u"&&n.ok&&n.headers.has("Frontastic-Session")){let s=m.get(),i;s&&(i=new Date(Date.now()+7776e6)),b.set("frontastic-session",n.headers.get("Frontastic-Session"),{expires:i})}if(n.ok)return n.json();let o;try{o=await n.clone().json()}catch{o=await n.text()}return new a(o)};var v=class{#r=[];#e=!1;#t=!1;add(e){return new Promise((t,n)=>{this.#r.push({promise:e,resolve:t,reject:n}),this.#n()})}stop(){this.#t=!0}restart(){this.#t=!1,this.#n()}#n(){if(this.#e||this.#t)return;let e=this.#r.shift();if(!!e)try{this.#e=!0,e.promise().then(t=>this.#o(()=>e.resolve(t))).catch(t=>this.#o(()=>e.reject(t)))}catch(t){this.#o(()=>e.reject(t))}}#o(e){this.#e=!1,e(),this.#n()}};var d=class{eventName;data;isDefaultPrevented;isCancelled;isPropagationStopped;constructor(e){this.eventName=e.eventName,this.data=e.data,this.isCancelled=!1,this.isDefaultPrevented=!1,this.isPropagationStopped=!1}preventDefault(){this.isDefaultPrevented=!0}cancel(){this.isCancelled=!0}stopPropagation(){this.isPropagationStopped=!0}};var E=class{eventHandlers;constructor(){this.eventHandlers={}}getEventHandlers(e){let t=this.eventHandlers[e];return t===void 0&&(t=[],this.eventHandlers[e]=t),t}on(e,t){this.getEventHandlers(e).push(t)}offForEvent(e){this.eventHandlers[e]=[]}off(e,t){let n=this.getEventHandlers(e);n.splice(n.indexOf(t),1)}clearAllHandlers(){this.eventHandlers={}}trigger(e){for(let t of this.getEventHandlers(e.eventName))t(e)}};var p=class extends a{constructor(e,t){super(t),this.actionName=e}actionName};var u=class extends a{constructor(e,t){super(t),this.path=e}path};var g=class extends E{#r;#e;#t;#n;#o;#s;set endpoint(e){this.#e=e}get endpoint(){return this.#e}set locale(e){typeof e=="string"?this.#t=new Intl.Locale(e):this.#t=e}get locale(){return this.#t}get APILocale(){let e=this.locale.baseName.slice(0,5).replace("-","_");return this.#o?`${e}@${this.currency}`:e}set currency(e){this.#n=e}get currency(){return this.#n}constructor(){super(),this.#r=!1,this.#s=new v}#c(){if(!this.#r)throw new Error(`The SDK has not been configured.
Please call .configure before you call any other methods.`)}#i=e=>e.split("//").reduce((t,n)=>n==="http:"||n==="https:"?n+="/":`${t}/${n}`,"");configure(e){this.endpoint=e.endpoint,this.locale=new Intl.Locale(e.locale),this.currency=e.currency,this.#o=e.useCurrencyInLocale??!1,this.#r=!0}#a(e){this.trigger(new d({eventName:"errorCaught",data:{error:e}}))}async callAction(e){this.#c(),e.payload=e.payload??{};let t="";e.query&&(t=Object.keys(e.query).reduce((o,s)=>e.query[s]?o+`${s}=${e.query[s]}&`:o,"?").slice(0,t.length-1));let n;try{n=await this.#s.add(()=>P(this.#i(`${this.#e}/frontastic/action/${e.actionName}${t}`),{method:"POST",body:JSON.stringify(e.payload),headers:{"Frontastic-Locale":this.APILocale}}))}catch(o){let s=new a(o);return this.#a(new p(e.actionName,s)),{isError:!0,error:s}}return{isError:!1,data:n}}page={getPage:async e=>{let t={method:"POST",headers:{"Frontastic-Path":e.path,"Frontastic-Locale":this.APILocale}},n;try{n=await P(this.#i(`${this.#e}/frontastic/page`),t)}catch(o){let s=new a(o);return this.#a(new u(e.path,s)),{isError:!0,error:s}}return{isError:!1,data:n}}}};
"use strict";var w=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var F=(r,e)=>{for(var t in e)w(r,t,{get:e[t],enumerable:!0})},T=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of A(e))!R.call(r,o)&&o!==t&&w(r,o,{get:()=>e[o],enumerable:!(n=S(e,o))||n.enumerable});return r};var k=r=>T(w({},"__esModule",{value:!0}),r);var j={};F(j,{ActionError:()=>d,Event:()=>l,Extension:()=>f,FetchError:()=>a,PageError:()=>u,SDK:()=>g,rememberMeCookie:()=>m});module.exports=k(j);var x="__rememberMe",m={get:function(){return!!(typeof window<"u"&&window.localStorage.getItem(x))},set:function(r){typeof window<"u"&&(r&&window.localStorage.setItem(x,"1"),this.remove())},remove:function(){typeof window<"u"&&window.localStorage.removeItem(x)}};var f=class{sdk;constructor(e){this.sdk=e}};function h(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)r[n]=t[n]}return r}var L={read:function(r){return r[0]==='"'&&(r=r.slice(1,-1)),r.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(r){return encodeURIComponent(r).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function C(r,e){function t(o,i,s){if(!(typeof document>"u")){s=h({},e,s),typeof s.expires=="number"&&(s.expires=new Date(Date.now()+s.expires*864e5)),s.expires&&(s.expires=s.expires.toUTCString()),o=encodeURIComponent(o).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var p in s)!s[p]||(c+="; "+p,s[p]!==!0&&(c+="="+s[p].split(";")[0]));return document.cookie=o+"="+r.write(i,o)+c}}function n(o){if(!(typeof document>"u"||arguments.length&&!o)){for(var i=document.cookie?document.cookie.split("; "):[],s={},c=0;c<i.length;c++){var p=i[c].split("="),b=p.slice(1).join("=");try{var y=decodeURIComponent(p[0]);if(s[y]=r.read(b,y),o===y)break}catch{}}return o?s[o]:s}}return Object.create({set:t,get:n,remove:function(o,i){t(o,"",h({},i,{expires:-1}))},withAttributes:function(o){return C(this.converter,h({},this.attributes,o))},withConverter:function(o){return C(h({},this.converter,o),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(r)}})}var H=C(L,{path:"/"}),N=H;var a=class extends Error{constructor(e){super(),this.isError=!0,typeof e=="string"?this.message=e:Object.keys(e).forEach(t=>{this[t]=e[t]})}isError;message};var D=N.withAttributes({path:"/"}),P=async(r,e={})=>{let t=D.get("frontastic-session");e.headers={"Content-Type":"application/json",Accept:"application/json","X-Frontastic-Access-Token":process.env.NEXT_PUBLIC_EXT_BUILD_ID??"APIKEY",...e.headers||{},...t?{"Frontastic-Session":t}:{}};let n=await fetch(r,e);if(typeof window<"u"&&n.ok&&n.headers.has("Frontastic-Session")){let i=m.get(),s;i&&(s=new Date(Date.now()+7776e6)),D.set("frontastic-session",n.headers.get("Frontastic-Session"),{expires:s})}if(n.ok)return n.json();let o;try{o=await n.clone().json()}catch{o=await n.text()}return new a(o)};var v=class{#r=[];#e=!1;#t=!1;add(e){return new Promise((t,n)=>{this.#r.push({promise:e,resolve:t,reject:n}),this.#n()})}stop(){this.#t=!0}restart(){this.#t=!1,this.#n()}#n(){if(this.#e||this.#t)return;let e=this.#r.shift();if(!!e)try{this.#e=!0,e.promise().then(t=>this.#o(()=>e.resolve(t))).catch(t=>this.#o(()=>e.reject(t)))}catch(t){this.#o(()=>e.reject(t))}}#o(e){this.#e=!1,e(),this.#n()}};var l=class{eventName;data;isDefaultPrevented;isCancelled;isPropagationStopped;constructor(e){this.eventName=e.eventName,this.data=e.data,this.isCancelled=!1,this.isDefaultPrevented=!1,this.isPropagationStopped=!1}preventDefault(){this.isDefaultPrevented=!0}cancel(){this.isCancelled=!0}stopPropagation(){this.isPropagationStopped=!0}};var E=class{eventHandlers;constructor(){this.eventHandlers={}}getEventHandlers(e){let t=this.eventHandlers[e];return t===void 0&&(t=[],this.eventHandlers[e]=t),t}on(e,t){this.getEventHandlers(e).push(t)}offForEvent(e){this.eventHandlers[e]=[]}off(e,t){let n=this.getEventHandlers(e);n.splice(n.indexOf(t),1)}clearAllHandlers(){this.eventHandlers={}}trigger(e){for(let t of this.getEventHandlers(e.eventName))t(e)}};var d=class extends a{constructor(e,t){super(t),this.actionName=e}actionName};var u=class extends a{constructor(e,t){super(t),this.path=e}path};var I=function(r){let e=new URLSearchParams;return Object.keys(r).forEach(t=>{r[t]!==void 0&&e.set(t,r[t].toString())}),`?${e.toString()}`};var g=class extends E{#r;#e;#t;#n;#o;#s;set endpoint(e){this.#e=e}get endpoint(){return this.#e}set locale(e){typeof e=="string"?this.#t=new Intl.Locale(e):this.#t=e}get locale(){return this.#t}get APILocale(){let e=this.locale.baseName.slice(0,5).replace("-","_");return this.#o?`${e}@${this.currency}`:e}set currency(e){this.#n=e}get currency(){return this.#n}constructor(){super(),this.#r=!1,this.#s=new v}#c(){if(!this.#r)throw new Error(`The SDK has not been configured.
Please call .configure before you call any other methods.`)}#i=e=>e.split("//").reduce((t,n)=>n==="http:"||n==="https:"?n+="/":`${t}/${n}`,"");configure(e){this.endpoint=e.endpoint,this.locale=new Intl.Locale(e.locale),this.currency=e.currency,this.#o=e.useCurrencyInLocale??!1,this.#r=!0}#a(e){this.trigger(new l({eventName:"errorCaught",data:{error:e}}))}async callAction(e){this.#c(),e.payload=e.payload??{};let t=e.query?I(e.query):"",n;try{n=await this.#s.add(()=>P(this.#i(`${this.#e}/frontastic/action/${e.actionName}${t}`),{method:"POST",body:JSON.stringify(e.payload),headers:{"Frontastic-Locale":this.APILocale}}))}catch(o){let i=new a(o);return this.#a(new d(e.actionName,i)),{isError:!0,error:i}}return{isError:!1,data:n}}page={getPage:async e=>{let t={method:"POST",headers:{"Frontastic-Path":e.path,"Frontastic-Locale":this.APILocale}},n;try{n=await P(this.#i(`${this.#e}/frontastic/page`),t)}catch(o){let i=new a(o);return this.#a(new u(e.path,i)),{isError:!0,error:i}}return{isError:!1,data:n}}}};
/*! js-cookie v3.0.1 | MIT */
import { EventManager } from "./EventManager";
import { SDKResponse, Currency, StandardEvents, Events } from "./types";
import { PageApi } from "../types/api/page";
import { AcceptedQueryTypes } from "../types/Query";
export declare class SDK<ExtensionEvents extends Events> extends EventManager<StandardEvents & ExtensionEvents> {

@@ -23,7 +24,5 @@ #private;

payload?: unknown;
query?: {
[key: string]: string | number | boolean;
};
query?: AcceptedQueryTypes;
}): Promise<SDKResponse<ReturnData>>;
page: PageApi;
}
{
"name": "@commercetools/frontend-sdk",
"version": "1.2.0",
"version": "1.2.1",
"license": "UNLICENSED",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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