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

@frontify/app-bridge-app

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frontify/app-bridge-app - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

18

dist/index.d.ts

@@ -39,2 +39,6 @@ import { CommandNameValidator } from '@frontify/app-bridge';

};
executeSecureRequest: {
payload: ExecuteSecureRequestPayload;
response: ExecuteSecureRequestResponse;
};
}>;

@@ -152,2 +156,14 @@

export declare type ExecuteSecureRequestPayload = {
endpoint: string;
requestParams: unknown;
};
export declare type ExecuteSecureRequestResponse = Response;
export declare const exeucteSecureRequest: (payload: ExecuteSecureRequestPayload) => {
name: string;
payload: ExecuteSecureRequestPayload;
};
export declare class FetchError extends Error {

@@ -246,3 +262,3 @@ constructor(topic: string);

export declare type PlatformAppApiMethod = PlatformAppApiMethodNameValidator<Pick<ApiMethodRegistry, 'getCurrentUser' | 'getAssetResourceInformation' | 'createAsset' | 'getSecureRequest' | 'getAccountId' | 'executeGraphQl'>>;
export declare type PlatformAppApiMethod = PlatformAppApiMethodNameValidator<Pick<ApiMethodRegistry, 'getCurrentUser' | 'getAssetResourceInformation' | 'createAsset' | 'getSecureRequest' | 'getAccountId' | 'executeGraphQl' | 'executeSecureRequest'>>;

@@ -249,0 +265,0 @@ declare type PlatformAppApiMethodNamePattern = {

246

dist/index.js

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

var S = Object.defineProperty;
var C = (s, t, e) => t in s ? S(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
var a = (s, t, e) => C(s, typeof t != "symbol" ? t + "" : t, e);
import { createElement as x } from "react";
import E from "react-dom";
class $ extends Error {
constructor(e, r, n) {
super(`Status code ${r} - ${e}`);
a(this, "code", 0);
a(this, "responseBody");
var C = Object.defineProperty;
var E = (e, t, s) => t in e ? C(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
var o = (e, t, s) => E(e, typeof t != "symbol" ? t + "" : t, s);
import { createElement as M } from "react";
import R from "react-dom";
class z extends Error {
constructor(s, r, n) {
super(`Status code ${r} - ${s}`);
o(this, "code", 0);
o(this, "responseBody");
this.name = "HttpClientError", this.code = r, this.responseBody = n;

@@ -19,3 +19,3 @@ }

}
class M extends Error {
class B extends Error {
constructor(t) {

@@ -30,3 +30,3 @@ super(`Call with topic ${t} failed.`), this.name = "FetchError";

}
class B extends Error {
class I extends Error {
constructor(t) {

@@ -36,12 +36,12 @@ super(`Validation failed. ${t}`), this.name = "ValidationError";

}
const I = () => ({ name: "openConnection" });
var l = /* @__PURE__ */ ((s) => (s.Init = "Init", s))(l || {});
const f = (s = 6) => Math.random().toString(20).substr(2, s);
function R(s, t, e, r) {
const P = () => ({ name: "openConnection" });
var l = /* @__PURE__ */ ((e) => (e.Init = "Init", e))(l || {});
const f = (e = 6) => Math.random().toString(20).substr(2, e);
function y(e, t, s, r) {
const n = window.top;
n == null || n.postMessage(
{
topic: s,
topic: e,
token: t,
data: e
data: s
},

@@ -51,35 +51,45 @@ (r == null ? void 0 : r.origin) || "*"

}
const b = 3 * 1e3;
function P(s, t, e) {
const S = 3 * 1e3;
function T(e, t, s) {
return new Promise((r, n) => {
const o = (u) => {
const i = u.data;
i.token === t && i.topic === s && i.success ? r(i.data || !0) : n(new M(s)), window.removeEventListener("message", o);
const a = (c) => {
const i = c.data;
i.token === t && i.topic === e && i.success ? r(i.data || !0) : n(new B(e)), window.removeEventListener("message", a);
};
window.addEventListener("message", o), setTimeout(() => {
n(new w(s));
}, (e == null ? void 0 : e.timeout) || b);
window.addEventListener("message", a), setTimeout(() => {
n(new w(e));
}, (s == null ? void 0 : s.timeout) || S);
});
}
class T {
class A {
constructor(t) {
a(this, "messageBucket", []);
this.port = t, this.port.onmessage = (e) => {
const { token: r } = e.data, n = this.messageBucket.findIndex((o) => o.token === r);
if (n > -1) {
const o = this.messageBucket.splice(n, 1)[0];
o && o.resolve(e.data.message);
o(this, "messageBucket", []);
this.port = t, this.port.onmessage = (s) => {
const { token: r } = s.data, n = this.messageBucket.find((a) => a.token === r);
if (n) {
if (this.hasParameterProperty(n.message) && n.message.parameter.name === "executeSecureRequest") {
const { status: a, statusText: c, headers: i, body: b } = s.data, x = new Response(b, {
status: a,
statusText: c,
headers: new Headers(i)
});
n.resolve(x);
}
n.resolve(s.data.message);
}
};
}
hasParameterProperty(t) {
return t && typeof t == "object" && "parameter" in t;
}
post(t) {
return new Promise((e, r) => {
return new Promise((s, r) => {
const n = f();
this.messageBucket.push({ message: t, resolve: e, token: n }), this.port.postMessage({ message: t, token: n }), setTimeout(() => {
this.messageBucket.push({ message: t, resolve: s, token: n }), this.port.postMessage({ message: t, token: n }), setTimeout(() => {
r(new w("operation"));
}, b * 10);
}, S * 10);
});
}
}
class y {
class _ {
post() {

@@ -89,25 +99,25 @@ throw new g('First use await platformApp.dispatch({ name: "openConnection" })');

}
const h = (s) => {
const t = (e) => {
const h = (e) => {
const t = (s) => {
const r = {};
for (const [n, o] of e)
r[n] = o;
for (const [n, a] of s)
r[n] = a;
return r;
};
try {
const e = new URL(s);
return t(e.searchParams.entries());
const s = new URL(e);
return t(s.searchParams.entries());
} catch {
throw new B(`"${s}" is not a valid url`);
throw new I(`"${e}" is not a valid url`);
}
};
class p {
class u {
constructor() {
a(this, "apiMessageBus", new y());
a(this, "statePort");
a(this, "initialized", !1);
a(this, "localContext");
a(this, "localState", { settings: {}, userState: {} });
a(this, "maxRetries", 5);
a(this, "subscribeMap", {
o(this, "apiMessageBus", new _());
o(this, "statePort");
o(this, "initialized", !1);
o(this, "localContext");
o(this, "localState", { settings: {}, userState: {} });
o(this, "maxRetries", 5);
o(this, "subscribeMap", {
"State.*": /* @__PURE__ */ new Map(),

@@ -142,20 +152,20 @@ "State.settings": /* @__PURE__ */ new Map(),

async dispatch(t) {
if (t.name === I().name) {
if (t.name === P().name) {
if (this.guardForInitialization())
return;
const e = f();
R(l.Init, e, {
const s = f();
y(l.Init, s, {
token: h(window.location.href).token,
appBridgeVersion: "v4"
}), await this.attemptSubscription(1, e);
}), await this.attemptSubscription(1, s);
}
}
async attemptSubscription(t, e) {
async attemptSubscription(t, s) {
try {
const { statePort: r, apiPort: n, context: o, state: u } = await P(l.Init, e);
this.apiMessageBus = new T(n), this.statePort = r, this.statePort.onmessage = (i) => {
const { statePort: r, apiPort: n, context: a, state: c } = await T(l.Init, s);
this.apiMessageBus = new A(n), this.statePort = r, this.statePort.onmessage = (i) => {
this.onStateChangeListener(i);
}, this.localContext = o, this.localState = u, this.initialized = !0, this.callSubscribedTopic("Context.connected", [!0, !1]), this.callSubscribedTopic("Context.*", [this.localContext, this.localContext]), this.callSubscribedTopic("State.*", [this.localState, this.localState]);
}, this.localContext = a, this.localState = c, this.initialized = !0, this.callSubscribedTopic("Context.connected", [!0, !1]), this.callSubscribedTopic("Context.*", [this.localContext, this.localContext]), this.callSubscribedTopic("State.*", [this.localState, this.localState]);
} catch {
t < this.maxRetries ? await this.attemptSubscription(t + 1, e) : console.error("Could not connect to the platform.");
t < this.maxRetries ? await this.attemptSubscription(t + 1, s) : console.error("Could not connect to the platform.");
}

@@ -173,6 +183,6 @@ }

get: () => this.localState,
set: (e) => {
set: (s) => {
this.statePort && this.statePort.postMessage({
message: {
parameter: { nextState: e }
parameter: { nextState: s }
},

@@ -182,9 +192,9 @@ token: "state"

},
subscribe: (e) => this.subscribe("State.*", e)
subscribe: (s) => this.subscribe("State.*", s)
} : {
get: () => this.localState[t],
set: (e) => {
set: (s) => {
this.statePort && this.statePort.postMessage({
message: {
parameter: { key: t, nextState: e }
parameter: { key: t, nextState: s }
},

@@ -194,52 +204,55 @@ token: "state"

},
subscribe: (e) => this.subscribe(`State.${t}`, e)
subscribe: (s) => this.subscribe(`State.${t}`, s)
};
}
subscribe(t, e) {
return t in this.subscribeMap || (this.subscribeMap[t] = /* @__PURE__ */ new Map()), this.subscribeMap[t].set(e, !0), () => {
this.subscribeMap[t].delete(e);
subscribe(t, s) {
return t in this.subscribeMap || (this.subscribeMap[t] = /* @__PURE__ */ new Map()), this.subscribeMap[t].set(s, !0), () => {
this.subscribeMap[t].delete(s);
};
}
callSubscribedTopic(t, e) {
callSubscribedTopic(t, s) {
const r = this.subscribeMap[t];
if (r && (r == null ? void 0 : r.size) !== void 0)
for (const [n] of r.entries())
n(...Array.isArray(e) ? e : [e]);
n(...Array.isArray(s) ? s : [s]);
}
onStateChangeListener(t) {
const { message: e, key: r } = t.data;
r ? this.callSubscribedTopic(`State.${r}`, [e[r], this.localState[r]]) : this.callSubscribedTopic("State.*", [e, this.localState]), this.localState = e;
const { message: s, key: r } = t.data;
r ? this.callSubscribedTopic(`State.${r}`, [s[r], this.localState[r]]) : this.callSubscribedTopic("State.*", [s, this.localState]), this.localState = s;
}
}
const v = (s) => ({
const L = (e) => ({
name: "createAsset",
payload: s
}), z = (s) => ({
payload: e
}), O = (e) => ({
name: "getAssetResourceInformation",
payload: s
}), L = (s) => ({ name: "getCurrentUser", payload: s }), O = (s) => ({
payload: e
}), U = (e) => ({ name: "getCurrentUser", payload: e }), q = (e) => ({
name: "getSecureRequest",
payload: s
}), U = (s) => ({
payload: e
}), F = (e) => ({
name: "executeGraphQl",
payload: s
}), F = () => {
const s = new p();
payload: e
}), V = (e) => ({
name: "executeSecureRequest",
payload: e
}), D = () => {
const e = new u();
return [
s.state("userState").get(),
s.state("userState").set
e.state("userState").get(),
e.state("userState").set
];
}, V = () => {
const s = new p();
return [s.state("settings").get(), s.state("settings").set];
}, q = () => new p().context().get();
var d, c = E;
}, H = () => {
const e = new u();
return [e.state("settings").get(), e.state("settings").set];
}, Q = () => new u().context().get();
var d, p = R;
if (process.env.NODE_ENV === "production")
d = c.createRoot, c.hydrateRoot;
d = p.createRoot, p.hydrateRoot;
else {
var m = c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
d = function(s, t) {
var m = p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
d = function(e, t) {
m.usingClientEntryPoint = !0;
try {
return c.createRoot(s, t);
return p.createRoot(e, t);
} finally {

@@ -250,8 +263,8 @@ m.usingClientEntryPoint = !1;

}
const D = (s) => {
const t = new p();
const G = (e) => {
const t = new u();
t.subscribe("Context.connected", () => {
const e = document.getElementById("root");
if (e)
d(e).render(x(s.app));
const s = document.getElementById("root");
if (s)
d(s).render(M(e.app));
else

@@ -262,22 +275,23 @@ throw new Error("Element with id 'root' not found");

export {
p as AppBridgePlatformApp,
M as FetchError,
$ as HttpClientError,
u as AppBridgePlatformApp,
B as FetchError,
z as HttpClientError,
g as InitializationError,
b as SUBSCRIBE_TIMEOUT,
S as SUBSCRIBE_TIMEOUT,
w as TimeoutReachedError,
B as ValidationError,
q as appContext,
V as appSettings,
F as appUserState,
v as createAsset,
U as executeGraphQl,
I as ValidationError,
Q as appContext,
H as appSettings,
D as appUserState,
L as createAsset,
F as executeGraphQl,
V as exeucteSecureRequest,
f as generateRandomString,
z as getAssetResourceInformation,
L as getCurrentUser,
O as getSecureRequest,
R as notify,
D as renderReactApp,
P as subscribe
O as getAssetResourceInformation,
U as getCurrentUser,
q as getSecureRequest,
y as notify,
G as renderReactApp,
T as subscribe
};
//# sourceMappingURL=index.js.map
{
"name": "@frontify/app-bridge-app",
"type": "module",
"version": "0.1.2",
"version": "0.1.3",
"description": "Package to establish communication between Frontify and apps",

@@ -49,4 +49,4 @@ "author": "Frontify Developers <developers@frontify.com>",

"vitest": "^1.6.0",
"@frontify/app-bridge": "^3.10.1",
"@frontify/platform-app": "^0.1.12"
"@frontify/platform-app": "^0.1.13",
"@frontify/app-bridge": "^3.11.0"
},

@@ -53,0 +53,0 @@ "scripts": {

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