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

@shopware-ag/admin-extension-sdk

Package Overview
Dependencies
Maintainers
6
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopware-ag/admin-extension-sdk - npm Package Compare versions

Comparing version 0.0.28 to 0.0.29

2

cdn/index.js

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

var ce=Object.defineProperty;var R=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var v=(o,r,s)=>r in o?ce(o,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[r]=s,b=(o,r)=>{for(var s in r||(r={}))de.call(r,s)&&v(o,s,r[s]);if(R)for(var s of R(r))ue.call(r,s)&&v(o,s,r[s]);return o};(function(o,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis!="undefined"?globalThis:o||self,r(o.sw={}))})(this,function(o){var z;"use strict";function r(){return String(Date.now().toString(36)+Math.random().toString(36).substr(2))}function s(e,t){for(let i in e){const n=e[i];t.apply(this,[e,i,n]),y(n)&&s(n,t)}}function y(e){return e!==null&&typeof e=="object"}function w(){return new URLSearchParams(window.location.search).get("location-id")}function x(){const e=window.location;return new URL(e.pathname,e.origin).toString()}function E(e){P(e)}function H(e){T(e)}const m={};let M=!1;function j(){M||(M=!0,h("__function__",async({args:e,id:t})=>await Promise.resolve(m[t](...e))))}function P(e){s(e,(t,i,n)=>{if(typeof n=="function"){const a=r();m[a]=n,t[i]={__type__:"__function__",id:a},j()}})}function T(e){s(e,(t,i,n)=>{if(y(n)&&n.__type__&&n.__type__==="__function__"&&typeof n.id=="string"){const a=n.id;t[i]=(...d)=>_("__function__",{args:d,id:a})}})}const S=new Set;function _(e,t,i){const n=r(),a=t!=null?t:{},d={_type:e,_data:a,_callbackId:n};E(d);const u=JSON.stringify(d);let l=!1;const p=3e3;return new Promise((se,ae)=>{const D=function(O){if(typeof O.data!="string")return;let f;try{f=JSON.parse(O.data)}catch{return}!A(f)||f._callbackId===n&&(!f.hasOwnProperty("_response")||(window.removeEventListener("message",D),l||(l=!0,se(f._response))))};window.addEventListener("message",D),window.parent.__Cypress__?i?i.postMessage(u,window.parent.origin):window.postMessage(u,window.parent.origin):i?i.postMessage(u,window.parent.origin):window.parent.postMessage(u,window.parent.origin),setTimeout(()=>{l||ae("Send timeout expired. It could be possible that no handler for the postMessage request exists or that the handler freezed.")},p)})}function h(e,t){const i=async function(n){var p;if(typeof n.data!="string")return;let a;try{a=JSON.parse(n.data)}catch{return}if(!N(a)||a._type!==e)return;H(a);const d=await Promise.resolve(t(a._data,{_event_:n})),u={_callbackId:a._callbackId,_type:a._type,_response:d!=null?d:null},l=JSON.stringify(u);n.source?n.source.postMessage(l,{targetOrigin:(p=n.source.origin)!=null?p:"*"}):window.postMessage(l,window.origin)};return window.addEventListener("message",i),()=>window.removeEventListener("message",i)}function k(e,t){return h(e,t)}function c(e,t){return i=>_(e,b(b({},t),i))}function L(e){return t=>k(e,t)}(async()=>{h("__registerWindow__",(e,t)=>{t._event_.source?S.add(t._event_.source):S.add(window)}),await _("__registerWindow__",{})})().catch(e=>console.error(e));function N(e){const t=e;return!!t._type&&!!t._data&&!!t._callbackId}function A(e){const t=e;return!!t._type&&!!t.hasOwnProperty("_response")&&!!t._callbackId}const C=c("windowRedirect"),U=c("windowReload",{});var J=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",redirect:C,reload:U});const $=c("notificationDispatch");var q=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",dispatch:$});const W=c("contextLanguage",{}),B=L("contextLanguage"),F=c("contextEnvironment",{}),G=c("contextLocale",{}),K=L("contextLocale"),Q=c("contextCurrency",{});var X=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",getLanguage:W,subscribeLanguage:B,getEnvironment:F,getLocale:G,subscribeLocale:K,getCurrency:Q});const Y=c("uiComponentSectionRenderer",{src:(z=x())!=null?z:void 0});var Z=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",add:Y});const V=e=>w()===e,ee=()=>window!==window.parent,I=e=>{if(e)return _("locationUpdateHeight",{height:e,locationId:w()});const t=document.documentElement.offsetHeight;return _("locationUpdateHeight",{height:t,locationId:w()})};let g=null;const te=()=>{g=new ResizeObserver(()=>{I()}),g.observe(document.body)},ne=()=>{g&&(g.unobserve(document.body),g.disconnect())},oe="sw-main-hidden";var re=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",is:V,isIframe:ee,updateHeight:I,startAutoResizer:te,stopAutoResizer:ne,MAIN_HIDDEN:oe});const ie={componentSection:Z};o.context=X,o.location=re,o.notification=q,o.ui=ie,o.window=J,Object.defineProperty(o,"__esModule",{value:!0}),o[Symbol.toStringTag]="Module"});
var ue=Object.defineProperty;var v=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var E=(o,r,i)=>r in o?ue(o,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[r]=i,m=(o,r)=>{for(var i in r||(r={}))le.call(r,i)&&E(o,i,r[i]);if(v)for(var i of v(r))_e.call(r,i)&&E(o,i,r[i]);return o};(function(o,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis!="undefined"?globalThis:o||self,r(o.sw={}))})(this,function(o){var z;"use strict";function r(){return String(Date.now().toString(36)+Math.random().toString(36).substr(2))}function i(e,t){for(let s in e){const n=e[s];t.apply(this,[e,s,n]),y(n)&&i(n,t)}}function y(e){return e!==null&&typeof e=="object"}function h(){return new URLSearchParams(window.location.search).get("location-id")}function x(){const e=window.location;return new URL(e.pathname,e.origin).toString()}function H(e){T(e)}function j(e){k(e)}const S={};let M=!1;function P(){M||(M=!0,b("__function__",async({args:e,id:t})=>await Promise.resolve(S[t](...e))))}function T(e){i(e,(t,s,n)=>{if(typeof n=="function"){const a=r();S[a]=n,t[s]={__type__:"__function__",id:a},P()}})}function k(e){i(e,(t,s,n)=>{if(y(n)&&n.__type__&&n.__type__==="__function__"&&typeof n.id=="string"){const a=n.id;t[s]=(...d)=>l("__function__",{args:d,id:a})}})}const L=new Set;function l(e,t,s){const n=r(),a=t!=null?t:{},d={_type:e,_data:a,_callbackId:n};H(d);const f=JSON.stringify(d);let u=!1;const p=3e3;return new Promise((ae,ce)=>{const D=function(O){if(typeof O.data!="string")return;let g;try{g=JSON.parse(O.data)}catch{return}!C(g)||g._callbackId===n&&(!g.hasOwnProperty("_response")||(window.removeEventListener("message",D),u||(u=!0,ae(g._response))))};window.addEventListener("message",D);let w=!0;try{w=!window.parent.origin}catch{}const de=!w&&window.parent.__CYPRESS__?window:window.parent;s?s.postMessage(f,w?document.referrer:window.parent.origin):de.postMessage(f,w?document.referrer:window.parent.origin),setTimeout(()=>{u||ce("Send timeout expired. It could be possible that no handler for the postMessage request exists or that the handler freezed.")},p)})}function b(e,t){const s=async function(n){var p;if(typeof n.data!="string")return;let a;try{a=JSON.parse(n.data)}catch{return}if(!A(a)||a._type!==e)return;j(a);const d=await Promise.resolve(t(a._data,{_event_:n})),f={_callbackId:a._callbackId,_type:a._type,_response:d!=null?d:null},u=JSON.stringify(f);n.source?n.source.postMessage(u,{targetOrigin:(p=n.origin)!=null?p:"*"}):window.postMessage(u,window.origin)};return window.addEventListener("message",s),()=>window.removeEventListener("message",s)}function N(e,t){return b(e,t)}function c(e,t){return s=>l(e,m(m({},t),s))}function I(e){return t=>N(e,t)}(async()=>{b("__registerWindow__",(e,t)=>{t._event_.source?L.add(t._event_.source):L.add(window)}),await l("__registerWindow__",{})})().catch(e=>console.error(e));function A(e){const t=e;return!!t._type&&!!t._data&&!!t._callbackId}function C(e){const t=e;return!!t._type&&!!t.hasOwnProperty("_response")&&!!t._callbackId}const U=c("windowRedirect"),W=c("windowReload",{});var J=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",redirect:U,reload:W});const $=c("notificationDispatch");var q=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",dispatch:$});const Y=c("contextLanguage",{}),B=I("contextLanguage"),F=c("contextEnvironment",{}),G=c("contextLocale",{}),K=I("contextLocale"),Q=c("contextCurrency",{});var X=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",getLanguage:Y,subscribeLanguage:B,getEnvironment:F,getLocale:G,subscribeLocale:K,getCurrency:Q});const Z=c("uiComponentSectionRenderer",{src:(z=x())!=null?z:void 0});var V=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",add:Z});const ee=e=>h()===e,te=()=>window!==window.parent,R=e=>{if(e)return l("locationUpdateHeight",{height:e,locationId:h()});const t=document.documentElement.offsetHeight;return l("locationUpdateHeight",{height:t,locationId:h()})};let _=null;const ne=()=>{_=new ResizeObserver(()=>{R()}),_.observe(document.body)},oe=()=>{_&&(_.unobserve(document.body),_.disconnect())},re="sw-main-hidden";var ie=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",is:ee,isIframe:te,updateHeight:R,startAutoResizer:ne,stopAutoResizer:oe,MAIN_HIDDEN:re});const se={componentSection:V};o.context=X,o.location=ie,o.notification=q,o.ui=se,o.window=J,Object.defineProperty(o,"__esModule",{value:!0}),o[Symbol.toStringTag]="Module"});

@@ -31,7 +31,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

export function send(type, data, targetWindow) {
// generate a unique callback ID. This here is only for simple demonstration purposes
// Generate a unique callback ID. This here is only for simple demonstration purposes
const callbackId = generateUniqueId();
// set fallback data when no data is defined
// Set fallback data when no data is defined
const sendData = data !== null && data !== void 0 ? data : {};
// generate the message with the callbackId
// Generate the message with the callbackId
const messageData = {

@@ -42,7 +42,7 @@ _type: type,

};
// replace methods etc. so that they are working in JSON format
// Replace methods etc. so that they are working in JSON format
serializeMessageData(messageData);
// convert message data to string for message sending
// Convert message data to string for message sending
const message = JSON.stringify(messageData);
// set value if send was resolved
// Set value if send was resolved
let isResolved = false;

@@ -56,3 +56,3 @@ const timeoutMs = 3000;

let shopwareResponseData;
// try to parse the json file
// Try to parse the json file
try {

@@ -62,23 +62,23 @@ shopwareResponseData = JSON.parse(event.data);

catch (_a) {
// fail silently when message is not a valid json file
// Fail silently when message is not a valid json file
return;
}
// check if messageData is valid
// Check if messageData is valid
if (!isMessageResponseData(shopwareResponseData)) {
return;
}
// only execute when callbackId matches
// Only execute when callbackId matches
if (shopwareResponseData._callbackId !== callbackId) {
return;
}
// only execute if response value exists
// Only execute if response value exists
if (!shopwareResponseData.hasOwnProperty('_response')) {
return;
}
// remove event so that in only execute once
// Remove event so that in only execute once
window.removeEventListener('message', callbackHandler);
// only return the data if the request is not timed out
// Only return the data if the request is not timed out
if (!isResolved) {
isResolved = true;
// return the data
// Return the data
resolve(shopwareResponseData._response);

@@ -88,16 +88,17 @@ }

window.addEventListener('message', callbackHandler);
// @ts-expect-error - Cypress tests run inside iframe. Therefore same level communication is not possible
if (window.parent.__Cypress__) {
targetWindow
? targetWindow.postMessage(message, window.parent.origin)
: window.postMessage(message, window.parent.origin);
let corsRestriction = true;
try {
corsRestriction = !window.parent.origin;
}
else {
targetWindow
? targetWindow.postMessage(message, window.parent.origin)
: window.parent.postMessage(message, window.parent.origin);
catch (_a) {
// Silent catch to prevent cross origin frame exception
}
// send timeout when noone sends data back or handler freezes
// @ts-expect-error - Cypress tests run inside iframe. Therefore same level communication is not possible
const parentWindow = !corsRestriction && window.parent.__CYPRESS__ ? window : window.parent;
targetWindow
? targetWindow.postMessage(message, corsRestriction ? document.referrer : window.parent.origin)
: parentWindow.postMessage(message, corsRestriction ? document.referrer : window.parent.origin);
// Send timeout when noone sends data back or handler freezes
setTimeout(() => {
// only runs when is not resolved
// Only runs when is not resolved
if (isResolved) {

@@ -124,3 +125,3 @@ return;

let shopwareMessageData;
// try to parse the json file
// Try to parse the json file
try {

@@ -130,14 +131,14 @@ shopwareMessageData = JSON.parse(event.data);

catch (_b) {
// fail silently when message is not a valid json file
// Fail silently when message is not a valid json file
return;
}
// check if messageData is valid
// Check if messageData is valid
if (!isMessageData(shopwareMessageData)) {
return;
}
// check if messageData type matches the type argument
// Check if messageData type matches the type argument
if (shopwareMessageData._type !== type) {
return;
}
// deserialize methods etc. so that they are callable in JS
// Deserialize methods etc. so that they are callable in JS
deserializeMessageData(shopwareMessageData);

@@ -152,11 +153,10 @@ const responseValue = yield Promise.resolve(method(shopwareMessageData._data, { _event_: event }));

if (event.source) {
// if event source exists then send it back to original source
// If event source exists then send it back to original source
event.source.postMessage(stringifiedResponseMessage, {
// @ts-expect-error - event.source.origin is not correctly defined in TS
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
targetOrigin: (_a = event.source.origin) !== null && _a !== void 0 ? _a : '*',
targetOrigin: (_a = event.origin) !== null && _a !== void 0 ? _a : '*',
});
}
else {
// if no event source exists then it should send to same window
// If no event source exists then it should send to same window
window.postMessage(stringifiedResponseMessage, window.origin);

@@ -166,5 +166,5 @@ }

};
// start listening directly
// Start listening directly
window.addEventListener('message', handleListener);
// return a cancel method
// Return a cancel method
return () => window.removeEventListener('message', handleListener);

@@ -216,3 +216,3 @@ }

(() => __awaiter(void 0, void 0, void 0, function* () {
// handle registrations at current window
// Handle registrations at current window
handle('__registerWindow__', (_, additionalOptions) => {

@@ -226,3 +226,3 @@ if (additionalOptions._event_.source) {

});
// register at parent window
// Register at parent window
yield send('__registerWindow__', {});

@@ -236,3 +236,3 @@ }))().catch((e) => console.error(e));

/**
* check if the data is valid message data
* Check if the data is valid message data
*/

@@ -239,0 +239,0 @@ function isMessageData(eventData) {

@@ -17,3 +17,3 @@ import { send } from '../channel';

}
// if no height is defined then send the current document height
// If no height is defined then send the current document height
const currentHeight = document.documentElement.offsetHeight;

@@ -27,7 +27,7 @@ return send('locationUpdateHeight', {

export const startAutoResizer = () => {
// create an Observer instance
// Create an Observer instance
resizeObserver = new ResizeObserver(() => {
void updateHeight();
});
// start observing a DOM node
// Start observing a DOM node
resizeObserver.observe(document.body);

@@ -34,0 +34,0 @@ };

{
"name": "@shopware-ag/admin-extension-sdk",
"version": "0.0.28",
"version": "0.0.29",
"repository": "git://github.com/shopware/admin-extension-sdk.git",

@@ -5,0 +5,0 @@ "description": "The SDK for App iframes to communicate with the Shopware Adminstration",

@@ -43,7 +43,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

function send(type, data, targetWindow) {
// generate a unique callback ID. This here is only for simple demonstration purposes
// Generate a unique callback ID. This here is only for simple demonstration purposes
const callbackId = (0, utils_1.generateUniqueId)();
// set fallback data when no data is defined
// Set fallback data when no data is defined
const sendData = data !== null && data !== void 0 ? data : {};
// generate the message with the callbackId
// Generate the message with the callbackId
const messageData = {

@@ -54,7 +54,7 @@ _type: type,

};
// replace methods etc. so that they are working in JSON format
// Replace methods etc. so that they are working in JSON format
(0, function_serializer_1.serializeMessageData)(messageData);
// convert message data to string for message sending
// Convert message data to string for message sending
const message = JSON.stringify(messageData);
// set value if send was resolved
// Set value if send was resolved
let isResolved = false;

@@ -68,3 +68,3 @@ const timeoutMs = 3000;

let shopwareResponseData;
// try to parse the json file
// Try to parse the json file
try {

@@ -74,23 +74,23 @@ shopwareResponseData = JSON.parse(event.data);

catch (_a) {
// fail silently when message is not a valid json file
// Fail silently when message is not a valid json file
return;
}
// check if messageData is valid
// Check if messageData is valid
if (!isMessageResponseData(shopwareResponseData)) {
return;
}
// only execute when callbackId matches
// Only execute when callbackId matches
if (shopwareResponseData._callbackId !== callbackId) {
return;
}
// only execute if response value exists
// Only execute if response value exists
if (!shopwareResponseData.hasOwnProperty('_response')) {
return;
}
// remove event so that in only execute once
// Remove event so that in only execute once
window.removeEventListener('message', callbackHandler);
// only return the data if the request is not timed out
// Only return the data if the request is not timed out
if (!isResolved) {
isResolved = true;
// return the data
// Return the data
resolve(shopwareResponseData._response);

@@ -100,16 +100,17 @@ }

window.addEventListener('message', callbackHandler);
// @ts-expect-error - Cypress tests run inside iframe. Therefore same level communication is not possible
if (window.parent.__Cypress__) {
targetWindow
? targetWindow.postMessage(message, window.parent.origin)
: window.postMessage(message, window.parent.origin);
let corsRestriction = true;
try {
corsRestriction = !window.parent.origin;
}
else {
targetWindow
? targetWindow.postMessage(message, window.parent.origin)
: window.parent.postMessage(message, window.parent.origin);
catch (_a) {
// Silent catch to prevent cross origin frame exception
}
// send timeout when noone sends data back or handler freezes
// @ts-expect-error - Cypress tests run inside iframe. Therefore same level communication is not possible
const parentWindow = !corsRestriction && window.parent.__CYPRESS__ ? window : window.parent;
targetWindow
? targetWindow.postMessage(message, corsRestriction ? document.referrer : window.parent.origin)
: parentWindow.postMessage(message, corsRestriction ? document.referrer : window.parent.origin);
// Send timeout when noone sends data back or handler freezes
setTimeout(() => {
// only runs when is not resolved
// Only runs when is not resolved
if (isResolved) {

@@ -137,3 +138,3 @@ return;

let shopwareMessageData;
// try to parse the json file
// Try to parse the json file
try {

@@ -143,14 +144,14 @@ shopwareMessageData = JSON.parse(event.data);

catch (_b) {
// fail silently when message is not a valid json file
// Fail silently when message is not a valid json file
return;
}
// check if messageData is valid
// Check if messageData is valid
if (!isMessageData(shopwareMessageData)) {
return;
}
// check if messageData type matches the type argument
// Check if messageData type matches the type argument
if (shopwareMessageData._type !== type) {
return;
}
// deserialize methods etc. so that they are callable in JS
// Deserialize methods etc. so that they are callable in JS
(0, function_serializer_1.deserializeMessageData)(shopwareMessageData);

@@ -165,11 +166,10 @@ const responseValue = yield Promise.resolve(method(shopwareMessageData._data, { _event_: event }));

if (event.source) {
// if event source exists then send it back to original source
// If event source exists then send it back to original source
event.source.postMessage(stringifiedResponseMessage, {
// @ts-expect-error - event.source.origin is not correctly defined in TS
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
targetOrigin: (_a = event.source.origin) !== null && _a !== void 0 ? _a : '*',
targetOrigin: (_a = event.origin) !== null && _a !== void 0 ? _a : '*',
});
}
else {
// if no event source exists then it should send to same window
// If no event source exists then it should send to same window
window.postMessage(stringifiedResponseMessage, window.origin);

@@ -179,5 +179,5 @@ }

};
// start listening directly
// Start listening directly
window.addEventListener('message', handleListener);
// return a cancel method
// Return a cancel method
return () => window.removeEventListener('message', handleListener);

@@ -235,3 +235,3 @@ }

(() => __awaiter(void 0, void 0, void 0, function* () {
// handle registrations at current window
// Handle registrations at current window
handle('__registerWindow__', (_, additionalOptions) => {

@@ -245,3 +245,3 @@ if (additionalOptions._event_.source) {

});
// register at parent window
// Register at parent window
yield send('__registerWindow__', {});

@@ -255,3 +255,3 @@ }))().catch((e) => console.error(e));

/**
* check if the data is valid message data
* Check if the data is valid message data
*/

@@ -258,0 +258,0 @@ function isMessageData(eventData) {

@@ -31,3 +31,3 @@ (function (factory) {

}
// if no height is defined then send the current document height
// If no height is defined then send the current document height
const currentHeight = document.documentElement.offsetHeight;

@@ -42,7 +42,7 @@ return (0, channel_1.send)('locationUpdateHeight', {

const startAutoResizer = () => {
// create an Observer instance
// Create an Observer instance
resizeObserver = new ResizeObserver(() => {
void (0, exports.updateHeight)();
});
// start observing a DOM node
// Start observing a DOM node
resizeObserver.observe(document.body);

@@ -49,0 +49,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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