🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

ifapi

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ifapi - npm Package Compare versions

Comparing version
2.0.1
to
2.0.2
+0
-1
legacy-version.d.ts
export declare function legacyVersionExpose(apiHandlers: Record<string, Function>, originVertify?: (origin: string) => boolean): () => void;
export declare function excute<T>(frameID: string, actionName: string, ...params: any): Promise<T>;

@@ -7,16 +7,2 @@ /*

}
function uuid() {
const s = [];
const hexDigits = "0123456789abcdef";
for (let i = 0; i < 36; i++) {
const f = Math.floor(Math.random() * 0x10);
s[i] = hexDigits.substring(f, f + 1);
}
s[14] = "4";
const s19 = s[19];
const i = (s19 & 0x3) | 0x8;
s[19] = hexDigits.substring(i, i + 1);
s[8] = s[13] = s[18] = s[23] = "-";
return s.join("");
}
// 兼容老版本的 ifapi,不建议使用。 暴露API接口供业务系统调用

@@ -33,2 +19,4 @@ export function legacyVersionExpose(apiHandlers, originVertify) {

}
if (!data || !data.id || !data.actionName || data.eventType === "IFAPI_CALL_METHOD_REQUEST")
return;
const id = data.id;

@@ -39,6 +27,2 @@ if (originVertify && !originVertify(e.origin)) {

}
if (!data.actionName) {
response(id, null, "Missing actionName field");
return;
}
const handler = apiHandlers[data.actionName];

@@ -61,39 +45,1 @@ if (!handler) {

}
// 兼容老版本的 ifapi,不建议使用
export function excute(frameID, actionName, ...params) {
return new Promise((resolve, reject) => {
var _a;
const frame = window.frames[frameID];
if (!frame) {
reject(`iframe not found: ${frameID}`);
return;
}
const id = uuid();
function listener(e) {
window.removeEventListener("message", listener);
let resp = {};
try {
resp = JSON.parse(e.data);
}
catch (e) {
window.console.error(e);
return;
}
if (!resp.id || resp.id !== id)
return;
if (resp.error) {
reject(resp.error);
return;
}
let data = resp.data;
try {
data = JSON.parse(resp.data);
}
catch (e) { }
resolve(data);
}
window.addEventListener("message", listener);
const requestData = { id, actionName, params };
(_a = frame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(JSON.stringify(requestData), frame.src);
});
}

@@ -8,17 +8,2 @@ /*

function uuid(): string {
const s: string[] = [];
const hexDigits = "0123456789abcdef";
for (let i = 0; i < 36; i++) {
const f = Math.floor(Math.random() * 0x10);
s[i] = hexDigits.substring(f, f + 1);
}
s[14] = "4";
const s19: any = s[19];
const i = (s19 & 0x3) | 0x8;
s[19] = hexDigits.substring(i, i + 1);
s[8] = s[13] = s[18] = s[23] = "-";
return s.join("");
}
// 兼容老版本的 ifapi,不建议使用。 暴露API接口供业务系统调用

@@ -34,2 +19,3 @@ export function legacyVersionExpose(apiHandlers: Record<string, Function>, originVertify?: (origin: string) => boolean) {

}
if (!data || !data.id || !data.actionName || data.eventType === "IFAPI_CALL_METHOD_REQUEST") return;
const id = data.id;

@@ -40,7 +26,2 @@ if (originVertify && !originVertify(e.origin)) {

}
if (!data.actionName) {
response(id, null, "Missing actionName field");
return;
}
const handler = apiHandlers[data.actionName];

@@ -63,36 +44,1 @@ if (!handler) {

}
// 兼容老版本的 ifapi,不建议使用
export function excute<T>(frameID: string, actionName: string, ...params: any): Promise<T> {
return new Promise((resolve, reject) => {
const frame: HTMLIFrameElement = (window.frames as any)[frameID];
if (!frame) {
reject(`iframe not found: ${frameID}`);
return;
}
const id = uuid();
function listener(e: any) {
window.removeEventListener("message", listener);
let resp: any = {};
try {
resp = JSON.parse(e.data);
} catch (e) {
window.console.error(e);
return;
}
if (!resp.id || resp.id !== id) return;
if (resp.error) {
reject(resp.error);
return;
}
let data: any = resp.data;
try {
data = JSON.parse(resp.data);
} catch (e) {}
resolve(data);
}
window.addEventListener("message", listener);
const requestData = { id, actionName, params };
frame.contentWindow?.postMessage(JSON.stringify(requestData), frame.src);
});
}
+1
-1
export * from "./legacy-version.js";
export declare function expose(apiHandlers: Record<string, Function>, originVertify?: (origin: string) => boolean): () => void;
export declare function callMethodResponseListener(e: any): void;
export declare function excuteMethod<T>(frameID: string, actionName: string, ...params: any): Promise<T>;
export declare function excute<T>(frameID: string, actionName: string, ...params: any): Promise<T>;
export declare function emitEvent(eventName: string, params: any): void;
export declare function addIframeEventListener(eventName: string, handler: (params: any) => void): () => void;

@@ -44,3 +44,3 @@ export * from "./legacy-version.js";

}
if (!data || !data.id || data.eventType !== EventType.callMethodRequest)
if (!data || !data.id || data.eventType !== EventType.callMethodRequest || !data.actionName)
return;

@@ -52,6 +52,2 @@ const id = data.id;

}
if (!data.actionName) {
response(id, null, "Missing actionName field");
return;
}
const handler = apiHandlers[data.actionName];

@@ -98,3 +94,3 @@ if (!handler) {

window.addEventListener("message", callMethodResponseListener);
export function excuteMethod(frameID, actionName, ...params) {
export function excute(frameID, actionName, ...params) {
return new Promise((resolve, reject) => {

@@ -101,0 +97,0 @@ var _a;

@@ -66,3 +66,3 @@ export * from "./legacy-version.js";

}
if (!data || !data.id || data.eventType !== EventType.callMethodRequest) return;
if (!data || !data.id || data.eventType !== EventType.callMethodRequest || !data.actionName) return;
const id = data.id;

@@ -74,7 +74,2 @@ if (originVertify && !originVertify(e.origin)) {

if (!data.actionName) {
response(id, null, "Missing actionName field");
return;
}
const handler = apiHandlers[data.actionName];

@@ -122,3 +117,3 @@ if (!handler) {

export function excuteMethod<T>(frameID: string, actionName: string, ...params: any): Promise<T> {
export function excute<T>(frameID: string, actionName: string, ...params: any): Promise<T> {
return new Promise((resolve, reject) => {

@@ -125,0 +120,0 @@ const frame: HTMLIFrameElement = (window.frames as any)[frameID];

{
"name": "ifapi",
"version": "2.0.1",
"version": "2.0.2",
"type": "module",

@@ -5,0 +5,0 @@ "main": "main.js",