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

framebus

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

framebus - npm Package Compare versions

Comparing version 5.2.0 to 5.2.1

dist/lib/index.d.ts

4

CHANGELOG.md

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

# 5.2.1
- Fix circular dependency issue ([Issue #97](https://github.com/braintree/framebus/issues/97))
# 5.2.0

@@ -2,0 +6,0 @@

10

dist/framebus.d.ts

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

import type { FramebusSubscriberArg, FramebusOnHandler, FramebusReplyHandler } from "./lib/types";
declare type VerifyDomainMethod = (domain: string) => boolean;
declare type IFrameOrWindowList = Array<HTMLIFrameElement | Window>;
declare type FramebusOptions = {
import type { FramebusSubscriberArg, FramebusOnHandler, FramebusReplyHandler } from "./lib";
type VerifyDomainMethod = (domain: string) => boolean;
type IFrameOrWindowList = Array<HTMLIFrameElement | Window>;
type FramebusOptions = {
channel?: string;

@@ -21,3 +21,3 @@ origin?: string;

static Promise: PromiseConstructor;
static setPromise(PromiseGlobal: typeof Framebus["Promise"]): void;
static setPromise(PromiseGlobal: (typeof Framebus)["Promise"]): void;
static target(options?: FramebusOptions): Framebus;

@@ -24,0 +24,0 @@ addTargetFrame(frame: Window | HTMLIFrameElement): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Framebus = void 0;
var is_not_string_1 = require("./lib/is-not-string");
var subscription_args_invalid_1 = require("./lib/subscription-args-invalid");
var broadcast_1 = require("./lib/broadcast");
var package_payload_1 = require("./lib/package-payload");
var send_message_1 = require("./lib/send-message");
var constants_1 = require("./lib/constants");
var lib_1 = require("./lib");
var DefaultPromise = (typeof window !== "undefined" &&

@@ -53,3 +48,3 @@ window.Promise);

}
constants_1.childWindows.push(childWindow);
lib_1.childWindows.push(childWindow);
return true;

@@ -66,6 +61,6 @@ };

eventName = this.namespaceEvent(eventName);
if ((0, is_not_string_1.isntString)(eventName)) {
if ((0, lib_1.isntString)(eventName)) {
return false;
}
if ((0, is_not_string_1.isntString)(origin)) {
if ((0, lib_1.isntString)(origin)) {
return false;

@@ -77,3 +72,3 @@ }

}
var payload = (0, package_payload_1.packagePayload)(eventName, origin, data, reply);
var payload = (0, lib_1.packagePayload)(eventName, origin, data, reply);
if (!payload) {

@@ -84,7 +79,7 @@ return false;

this.targetFramesAsWindows().forEach(function (frame) {
(0, send_message_1.sendMessage)(frame, payload, origin);
(0, lib_1.sendMessage)(frame, payload, origin);
});
}
else {
(0, broadcast_1.broadcast)(payload, {
(0, lib_1.broadcast)(payload, {
origin: origin,

@@ -116,3 +111,3 @@ frame: window.top || window.self,

eventName = this.namespaceEvent(eventName);
if ((0, subscription_args_invalid_1.subscriptionArgsInvalid)(eventName, handler, origin)) {
if ((0, lib_1.subscriptionArgsInvalid)(eventName, handler, origin)) {
return false;

@@ -144,5 +139,5 @@ }

});
constants_1.subscribers[origin] = constants_1.subscribers[origin] || {};
constants_1.subscribers[origin][eventName] = constants_1.subscribers[origin][eventName] || [];
constants_1.subscribers[origin][eventName].push(handler);
lib_1.subscribers[origin] = lib_1.subscribers[origin] || {};
lib_1.subscribers[origin][eventName] = lib_1.subscribers[origin][eventName] || [];
lib_1.subscribers[origin][eventName].push(handler);
return true;

@@ -165,6 +160,6 @@ };

var origin = this.origin;
if ((0, subscription_args_invalid_1.subscriptionArgsInvalid)(eventName, handler, origin)) {
if ((0, lib_1.subscriptionArgsInvalid)(eventName, handler, origin)) {
return false;
}
var subscriberList = constants_1.subscribers[origin] && constants_1.subscribers[origin][eventName];
var subscriberList = lib_1.subscribers[origin] && lib_1.subscribers[origin][eventName];
if (!subscriberList) {

@@ -171,0 +166,0 @@ return false;

"use strict";
var attach_1 = require("./lib/attach");
var lib_1 = require("./lib");
var framebus_1 = require("./framebus");
(0, attach_1.attach)();
(0, lib_1.attach)();
module.exports = framebus_1.Framebus;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.detach = exports.attach = void 0;
var message_1 = require("./message");
var _1 = require("./");
var isAttached = false;

@@ -11,3 +11,3 @@ function attach() {

isAttached = true;
window.addEventListener("message", message_1.onmessage, false);
window.addEventListener("message", _1.onMessage, false);
}

@@ -18,5 +18,5 @@ exports.attach = attach;

isAttached = false;
window.removeEventListener("message", message_1.onmessage, false);
window.removeEventListener("message", _1.onMessage, false);
}
exports.detach = detach;
// endRemoveIf(production)
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.broadcastToChildWindows = void 0;
var broadcast_1 = require("./broadcast");
var constants_1 = require("./constants");
var _1 = require("./");
function broadcastToChildWindows(payload, origin, source) {
for (var i = constants_1.childWindows.length - 1; i >= 0; i--) {
var childWindow = constants_1.childWindows[i];
for (var i = _1.childWindows.length - 1; i >= 0; i--) {
var childWindow = _1.childWindows[i];
if (childWindow.closed) {
constants_1.childWindows.splice(i, 1);
_1.childWindows.splice(i, 1);
}
else if (source !== childWindow) {
(0, broadcast_1.broadcast)(payload, {
(0, _1.broadcast)(payload, {
origin: origin,

@@ -15,0 +14,0 @@ frame: childWindow.top,

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

declare type BroadcastOptions = {
type BroadcastOptions = {
origin: string;

@@ -3,0 +3,0 @@ frame: Window;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.broadcast = void 0;
var has_opener_1 = require("./has-opener");
var _1 = require("./");
function broadcast(payload, options) {

@@ -11,3 +11,3 @@ var i = 0;

frame.postMessage(payload, origin);
if ((0, has_opener_1.hasOpener)(frame) && frame.opener.top !== window.top) {
if ((0, _1.hasOpener)(frame) && frame.opener.top !== window.top) {
broadcast(payload, {

@@ -14,0 +14,0 @@ origin: origin,

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

import type { FramebusSubscriber } from "./types";
import type { FramebusSubscriber } from "./";
export declare const prefix = "/*framebus*/";
export declare const childWindows: Window[];
export declare const subscribers: FramebusSubscriber;

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

import type { FramebusSubscriberArg, FramebusSubscribeHandler } from "./types";
import type { FramebusSubscriberArg, FramebusSubscribeHandler } from "./";
export declare function dispatch(origin: string, event: string, data?: FramebusSubscriberArg, reply?: FramebusSubscribeHandler, e?: MessageEvent): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dispatch = void 0;
var constants_1 = require("./constants");
var _1 = require("./");
function dispatch(origin, event, data, reply, e) {
if (!constants_1.subscribers[origin]) {
if (!_1.subscribers[origin]) {
return;
}
if (!constants_1.subscribers[origin][event]) {
if (!_1.subscribers[origin][event]) {
return;

@@ -19,6 +19,6 @@ }

}
for (var i = 0; i < constants_1.subscribers[origin][event].length; i++) {
constants_1.subscribers[origin][event][i].apply(e, args);
for (var i = 0; i < _1.subscribers[origin][event].length; i++) {
_1.subscribers[origin][event][i].apply(e, args);
}
}
exports.dispatch = dispatch;

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

export declare function onmessage(e: MessageEvent): void;
export declare function onMessage(e: MessageEvent): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.onmessage = void 0;
var is_not_string_1 = require("./is-not-string");
var unpack_payload_1 = require("./unpack-payload");
var dispatch_1 = require("./dispatch");
var broadcast_to_child_windows_1 = require("./broadcast-to-child-windows");
function onmessage(e) {
if ((0, is_not_string_1.isntString)(e.data)) {
exports.onMessage = void 0;
var _1 = require("./");
function onMessage(e) {
if ((0, _1.isntString)(e.data)) {
return;
}
var payload = (0, unpack_payload_1.unpackPayload)(e);
var payload = (0, _1.unpackPayload)(e);
if (!payload) {

@@ -18,6 +15,6 @@ return;

var reply = payload.reply;
(0, dispatch_1.dispatch)("*", payload.event, data, reply, e);
(0, dispatch_1.dispatch)(e.origin, payload.event, data, reply, e);
(0, broadcast_to_child_windows_1.broadcastToChildWindows)(e.data, payload.origin, e.source);
(0, _1.dispatch)("*", payload.event, data, reply, e);
(0, _1.dispatch)(e.origin, payload.event, data, reply, e);
(0, _1.broadcastToChildWindows)(e.data, payload.origin, e.source);
}
exports.onmessage = onmessage;
exports.onMessage = onMessage;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.packagePayload = void 0;
var subscribe_replier_1 = require("./subscribe-replier");
var constants_1 = require("./constants");
var _1 = require("./");
function packagePayload(event, origin, data, reply) {

@@ -13,7 +12,7 @@ var packaged;

if (typeof reply === "function") {
payload.reply = (0, subscribe_replier_1.subscribeReplier)(reply, origin);
payload.reply = (0, _1.subscribeReplier)(reply, origin);
}
payload.eventData = data;
try {
packaged = constants_1.prefix + JSON.stringify(payload);
packaged = _1.prefix + JSON.stringify(payload);
}

@@ -20,0 +19,0 @@ catch (e) {

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

import type { FramebusSubscribeHandler } from "./types";
import type { FramebusSubscribeHandler } from "./";
export declare function subscribeReplier(fn: FramebusSubscribeHandler, origin: string): string;

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

import type { FramebusOnHandler } from "./types";
import type { FramebusOnHandler } from "./";
export declare function subscriptionArgsInvalid(event: string, fn: FramebusOnHandler, origin: string): boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.subscriptionArgsInvalid = void 0;
var is_not_string_1 = require("./is-not-string");
var _1 = require("./");
function subscriptionArgsInvalid(event, fn, origin) {
if ((0, is_not_string_1.isntString)(event)) {
if ((0, _1.isntString)(event)) {
return true;

@@ -12,4 +12,4 @@ }

}
return (0, is_not_string_1.isntString)(origin);
return (0, _1.isntString)(origin);
}
exports.subscriptionArgsInvalid = subscriptionArgsInvalid;

@@ -6,4 +6,4 @@ declare global {

}
declare type ReplyFunction = (...args: unknown[]) => void;
export declare type FramebusPayload = {
type ReplyFunction = (...args: unknown[]) => void;
export type FramebusPayload = {
data?: string;

@@ -15,8 +15,8 @@ event: string;

};
export declare type FramebusSubscriberArg = Record<string, unknown>;
export declare type FramebusSubscribeHandler = (data?: FramebusSubscriberArg | FramebusSubscribeHandler, reply?: FramebusSubscribeHandler) => void;
declare type FramebusSubscription = Record<string, FramebusSubscribeHandler[]>;
export declare type FramebusSubscriber = Record<string, FramebusSubscription>;
export declare type FramebusReplyHandler = (data: unknown) => void;
export declare type FramebusOnHandler = (data: FramebusSubscriberArg, reply: FramebusReplyHandler) => void;
export type FramebusSubscriberArg = Record<string, unknown>;
export type FramebusSubscribeHandler = (data?: FramebusSubscriberArg | FramebusSubscribeHandler, reply?: FramebusSubscribeHandler) => void;
type FramebusSubscription = Record<string, FramebusSubscribeHandler[]>;
export type FramebusSubscriber = Record<string, FramebusSubscription>;
export type FramebusReplyHandler = (data: unknown) => void;
export type FramebusOnHandler = (data: FramebusSubscriberArg, reply: FramebusReplyHandler) => void;
export {};

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

import type { FramebusPayload } from "./types";
import type { FramebusPayload } from "./";
export declare function unpackPayload(e: MessageEvent): FramebusPayload | false;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unpackPayload = void 0;
var constants_1 = require("./constants");
var package_payload_1 = require("./package-payload");
var _1 = require("./");
function unpackPayload(e) {
var payload;
if (e.data.slice(0, constants_1.prefix.length) !== constants_1.prefix) {
if (e.data.slice(0, _1.prefix.length) !== _1.prefix) {
return false;
}
try {
payload = JSON.parse(e.data.slice(constants_1.prefix.length));
payload = JSON.parse(e.data.slice(_1.prefix.length));
}

@@ -25,3 +24,3 @@ catch (err) {

}
var replyPayload = (0, package_payload_1.packagePayload)(replyEvent_1, replyOrigin_1, replyData);
var replyPayload = (0, _1.packagePayload)(replyEvent_1, replyOrigin_1, replyData);
if (!replyPayload) {

@@ -28,0 +27,0 @@ return;

@@ -9,3 +9,3 @@ {

"homepage": "https://github.com/braintree/framebus",
"version": "5.2.0",
"version": "5.2.1",
"main": "dist/index.js",

@@ -34,3 +34,3 @@ "files": [

"devDependencies": {
"@types/jest": "^29.2.0",
"@types/jest": "^29.4.0",
"@wdio/cli": "^7.25.2",

@@ -43,6 +43,6 @@ "@wdio/local-runner": "^7.25.2",

"browserify": "^17.0.0",
"chromedriver": "^106.0.1",
"chromedriver": "^114.0.2",
"del": "^6.0.0",
"ejs": "^3.1.8",
"eslint": "^8.25.0",
"eslint": "^8.35.0",
"eslint-config-braintree": "6.0.0-typescript-prep-rc.2",

@@ -56,12 +56,12 @@ "express": "^4.18.2",

"gulp-uglify": "^3.0.2",
"jest": "^29.2.1",
"jest-environment-jsdom": "^29.2.1",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"morgan": "^1.10.0",
"prettier": "^2.7.1",
"ts-jest": "^29.0.3",
"prettier": "^2.8.4",
"ts-jest": "^29.0.5",
"tsify": "^5.0.4",
"typescript": "^4.8.4",
"typescript": "^4.9.5",
"vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0",
"wdio-chromedriver-service": "^8.0.0"
"wdio-chromedriver-service": "^8.1.1"
},

@@ -68,0 +68,0 @@ "jest": {

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