@todesktop/client-util
Advanced tools
Comparing version 1.0.0-alpha1 to 1.0.0-alpha2
106
index.d.ts
/** | ||
* Barebones EventEmitter implementation for API namespaces. | ||
*/ | ||
import type { BrowserWindow, WebContents } from "@todesktop/client-electron-types"; | ||
/** | ||
@@ -18,1 +19,106 @@ * Setup the ability to register an event handler for the given `eventMappings`. | ||
}>(eventMappings: E) => (event: "*" | keyof E, callback: (...any: any[]) => void) => void; | ||
export declare type MethodFunc = (...args: any[]) => unknown; | ||
declare type MethodsOnly<O, N extends keyof O> = Pick<O, N>; | ||
declare type PropsOnly<O, N extends keyof O> = Pick<O, N>; | ||
declare type _BrowserWindowMethodWhitelist = MethodsOnly<BrowserWindow, "show" | "isMinimized" | "setAspectRatio">; | ||
declare type _BrowserWindowPropWhitelist = PropsOnly<BrowserWindow, "id">; | ||
declare type _BrowserWindow = _BrowserWindowMethodWhitelist & _BrowserWindowPropWhitelist; | ||
declare type _WebContentsMethodWhitelist = MethodsOnly<WebContents, "getZoomLevel" | "setZoomLevel" | "getZoomFactor" | "setZoomFactor">; | ||
declare type _WebContentsPropWhitelist = PropsOnly<WebContents, "id">; | ||
declare type _WebContents = _WebContentsMethodWhitelist & _WebContentsPropWhitelist; | ||
export interface NamespacesV1 { | ||
_BrowserWindow: _BrowserWindow; | ||
_WebContents: _WebContents; | ||
} | ||
/** | ||
* @internal | ||
* @privateRemarks | ||
* Options to set when invoking a remote request. | ||
*/ | ||
export interface InvokeCommand<NS, M, Func extends MethodFunc> { | ||
/** | ||
* The namespace containing the method you wish to invoke. | ||
*/ | ||
namespace: NS; | ||
/** | ||
* The method you wish to invoke on the given namespace. | ||
*/ | ||
method: M; | ||
/** | ||
* Optional argument to specify an identifier this method call should | ||
* act on. | ||
*/ | ||
id?: unknown; | ||
/** | ||
* Any arguments required by the method. | ||
*/ | ||
args: Parameters<Func>; | ||
} | ||
/** | ||
* @internal | ||
* @privateRemarks | ||
* The payload to be executed/processed by the backend. | ||
* Currently, this is simply a single command. | ||
*/ | ||
export interface InvokePayload<NS, M, Func extends MethodFunc> { | ||
/** | ||
* The command to execute. | ||
*/ | ||
command: InvokeCommand<NS, M, Func>; | ||
} | ||
/** | ||
* @internal | ||
* @privateRemarks | ||
* Metadata that may optionally be processed by the backend to determine | ||
* behaviour. | ||
* This is used to provide additional context, potentially to correct incorrect | ||
* behaviour identified in the future. | ||
*/ | ||
export interface InvokeMetadata { | ||
/** | ||
* Information relating to the package invoking a remote method. | ||
*/ | ||
package: { | ||
/** | ||
* The name of the package invoking a remote method. | ||
*/ | ||
name: string; | ||
/** | ||
* The version of the package invoking a remote method. | ||
*/ | ||
version: string; | ||
}; | ||
/** | ||
* Information relating to the `invoke()` interface currently being used | ||
*/ | ||
invoke: { | ||
/** | ||
* Specifies the version of `invoke()` to be used. | ||
*/ | ||
version: string; | ||
}; | ||
} | ||
export interface InvokeOptions<NS, M, Func extends MethodFunc> { | ||
metadata: { | ||
package: { | ||
name: string; | ||
version: string; | ||
}; | ||
invoke: { | ||
version: string; | ||
}; | ||
}; | ||
payload: InvokePayload<NS, M, Func>; | ||
} | ||
/** | ||
* Method to interact with ToDesktop's messaging API. | ||
* | ||
* @privateRemarks | ||
* Use this API to invoke exposed methods from wthin the renderer. | ||
* It provides additional type safety, and a standard interface for mapping | ||
* calls to the global `todesktop.invoke()` function. | ||
* | ||
* @internal | ||
*/ | ||
export declare function _createInvokeWithMetadata(name: string, version: string): <NS extends NamespacesV1 = NamespacesV1, NSName extends keyof NS = keyof NS, MethodName extends keyof NS[NSName] = keyof NS[NSName], Func extends MethodFunc = NS[NSName][MethodName]>(command: InvokeCommand<NSName, MethodName, Func>) => Promise<ReturnType<Func>>; | ||
export {}; |
24
index.js
@@ -27,1 +27,25 @@ /** | ||
}; | ||
/** | ||
* Method to interact with ToDesktop's messaging API. | ||
* | ||
* @privateRemarks | ||
* Use this API to invoke exposed methods from wthin the renderer. | ||
* It provides additional type safety, and a standard interface for mapping | ||
* calls to the global `todesktop.invoke()` function. | ||
* | ||
* @internal | ||
*/ | ||
export function _createInvokeWithMetadata(name, version) { | ||
return function _invoke(command) { | ||
const options = { | ||
metadata: { | ||
package: { name, version }, | ||
invoke: { version: "1.0.0" }, | ||
}, | ||
payload: { | ||
command, | ||
}, | ||
}; | ||
return window["todesktop"]["invoke"](options); | ||
}; | ||
} |
{ | ||
"name": "@todesktop/client-util", | ||
"version": "1.0.0-alpha1", | ||
"version": "1.0.0-alpha2", | ||
"description": "Utility functions for ToDesktop client libraries", | ||
@@ -22,5 +22,7 @@ "main": "index.js", | ||
"agadoo": "^2.0.0", | ||
"electron": "^12.0.12", | ||
"typescript": "^4.3.4" | ||
}, | ||
"dependencies": { | ||
"@todesktop/client-electron-types": "^12.0.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11482
2
5
182
1
2
+ Added@todesktop/client-electron-types@12.0.0(transitive)