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.3.0 to 1.4.0

lib/types/api/page/PageFolderListResponse.d.ts

9

CHANGELOG.md
## Version 1.3.0 (2023-03-20)
## Version 1.4.0 (2023-03-22)
* Implemented getPages method
## Version 1.3.0 (2023-03-20)
* Added getPreview page API method
* fix: removed nested isError property from FetchError
* Removed nested isError property from FetchError
## Version 1.2.7 (2023-03-14)

@@ -13,0 +14,0 @@

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

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

@@ -12,3 +13,8 @@ import { PageResponse } from "./PageResponse";

}) => Promise<SDKResponse<PagePreviewResponse>>;
getPages: (options?: {
path?: string;
depth?: number;
types?: "static";
}) => Promise<SDKResponse<PageFolderListResponse>>;
};
export { PageApi, PageResponse, PagePreviewResponse, PageViewData };
export { PageApi, PageResponse, PagePreviewResponse, PageViewData, PageFolderListResponse, };
{
"name": "@commercetools/frontend-sdk",
"version": "1.3.0",
"version": "1.4.0",
"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