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

skynet-mysky-utils

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skynet-mysky-utils - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

dist/paths.d.ts

12

CHANGELOG.md
# Changelog
## [0.2.0]
### Added
- Path helpers: `getPathDomain`, `getParentPath`, `sanitizePath`
- String helper: `trimSuffix`
- Permissions helpers: `permCategoryToString`, `permTypeToString`
### Removed
- Storage listener helpers
## [0.1.2]

@@ -4,0 +16,0 @@

7

dist/index.d.ts

@@ -1,6 +0,7 @@

export { Permission, PermCategory, PermType, PermDiscoverable, PermHidden, PermLegacySkyID, PermRead, PermWrite } from "./permissions";
export { getPathDomain, getParentPath, sanitizePath } from "./paths";
export { Permission, PermCategory, PermType, permCategoryToString, permTypeToString, PermDiscoverable, PermHidden, PermLegacySkyID, PermRead, PermWrite, } from "./permissions";
export { defaultWindowTimeout, emitStorageEvent, listenForStorageEvent, monitorOtherListener, PromiseController, } from "./storage_listener";
export type { CustomListenerOptions, ListenForStorageEventResponse, MonitorOtherListenerResponse, } from "./storage_listener";
export { createFullScreenIframe, createIframe, ensureUrl } from "./utils";
export { dispatchedErrorEvent, errorWindowClosed, monitorWindowError } from "./window-listener";
export { createFullScreenIframe, createIframe, ensureUrl, trimSuffix, } from "./utils";
export { dispatchedErrorEvent, errorWindowClosed, monitorWindowError, } from "./window-listener";
import { Permission } from "./permissions";

@@ -7,0 +8,0 @@ export declare const defaultHandshakeMaxAttempts = 150;

@@ -10,3 +10,7 @@ "use strict";

exports.__esModule = true;
exports.defaultHandshakeAttemptsInterval = exports.defaultHandshakeMaxAttempts = exports.monitorWindowError = exports.errorWindowClosed = exports.dispatchedErrorEvent = exports.ensureUrl = exports.createIframe = exports.createFullScreenIframe = exports.PromiseController = exports.monitorOtherListener = exports.listenForStorageEvent = exports.emitStorageEvent = exports.defaultWindowTimeout = exports.PermWrite = exports.PermRead = exports.PermLegacySkyID = exports.PermHidden = exports.PermDiscoverable = exports.PermType = exports.PermCategory = exports.Permission = void 0;
exports.defaultHandshakeAttemptsInterval = exports.defaultHandshakeMaxAttempts = exports.monitorWindowError = exports.errorWindowClosed = exports.dispatchedErrorEvent = exports.trimSuffix = exports.ensureUrl = exports.createIframe = exports.createFullScreenIframe = exports.PromiseController = exports.monitorOtherListener = exports.listenForStorageEvent = exports.emitStorageEvent = exports.defaultWindowTimeout = exports.PermWrite = exports.PermRead = exports.PermLegacySkyID = exports.PermHidden = exports.PermDiscoverable = exports.permTypeToString = exports.permCategoryToString = exports.PermType = exports.PermCategory = exports.Permission = exports.sanitizePath = exports.getParentPath = exports.getPathDomain = void 0;
var paths_1 = require("./paths");
__createBinding(exports, paths_1, "getPathDomain");
__createBinding(exports, paths_1, "getParentPath");
__createBinding(exports, paths_1, "sanitizePath");
var permissions_1 = require("./permissions");

@@ -16,2 +20,4 @@ __createBinding(exports, permissions_1, "Permission");

__createBinding(exports, permissions_1, "PermType");
__createBinding(exports, permissions_1, "permCategoryToString");
__createBinding(exports, permissions_1, "permTypeToString");
// Constants

@@ -33,2 +39,3 @@ __createBinding(exports, permissions_1, "PermDiscoverable");

__createBinding(exports, utils_1, "ensureUrl");
__createBinding(exports, utils_1, "trimSuffix");
var window_listener_1 = require("./window-listener");

@@ -35,0 +42,0 @@ __createBinding(exports, window_listener_1, "dispatchedErrorEvent");

@@ -28,2 +28,4 @@ export declare class Permission {

}
export declare function permCategoryToString(category: PermCategory): string;
export declare function permTypeToString(permType: PermType): string;
//# sourceMappingURL=permissions.d.ts.map
"use strict";
exports.__esModule = true;
exports.PermType = exports.PermWrite = exports.PermRead = exports.PermCategory = exports.PermLegacySkyID = exports.PermHidden = exports.PermDiscoverable = exports.Permission = void 0;
exports.permTypeToString = exports.permCategoryToString = exports.PermType = exports.PermWrite = exports.PermRead = exports.PermCategory = exports.PermLegacySkyID = exports.PermHidden = exports.PermDiscoverable = exports.Permission = void 0;
var Permission = /** @class */ (function () {

@@ -20,3 +20,2 @@ function Permission(requestor, path, category, permType) {

exports.Permission = Permission;
;
// Define category constants for non-TS users.

@@ -46,2 +45,29 @@ exports.PermDiscoverable = 1;

})(PermType = exports.PermType || (exports.PermType = {}));
function permCategoryToString(category) {
if (category === PermCategory.Discoverable) {
return "Discoverable";
}
else if (category === PermCategory.Hidden) {
return "Hidden";
}
else if (category === PermCategory.LegacySkyID) {
return "LegacySkyID";
}
else {
throw new Error("Invalid permission category " + category);
}
}
exports.permCategoryToString = permCategoryToString;
function permTypeToString(permType) {
if (permType === PermType.Read) {
return "Read";
}
else if (permType === PermType.Write) {
return "Write";
}
else {
throw new Error("Invalid permission type " + permType);
}
}
exports.permTypeToString = permTypeToString;
//# sourceMappingURL=permissions.js.map

@@ -10,2 +10,11 @@ /**

export declare function ensureUrl(url: string): string;
/**
* Removes a suffix from the end of the string.
*
* @param str - The string to process.
* @param suffix - The suffix to remove.
* @param [limit] - Maximum amount of times to trim. No limit by default.
* @returns - The processed string.
*/
export declare function trimSuffix(str: string, suffix: string, limit?: number): string;
//# sourceMappingURL=utils.d.ts.map
"use strict";
exports.__esModule = true;
exports.ensureUrl = exports.createFullScreenIframe = exports.createIframe = void 0;
exports.trimSuffix = exports.ensureUrl = exports.createFullScreenIframe = exports.createIframe = void 0;
/**

@@ -54,2 +54,23 @@ * Creates an invisible iframe with the given src and adds it to the page.

exports.ensureUrl = ensureUrl;
/**
* Removes a suffix from the end of the string.
*
* @param str - The string to process.
* @param suffix - The suffix to remove.
* @param [limit] - Maximum amount of times to trim. No limit by default.
* @returns - The processed string.
*/
function trimSuffix(str, suffix, limit) {
while (str.endsWith(suffix)) {
if (limit !== undefined && limit <= 0) {
break;
}
str = str.substring(0, str.length - suffix.length);
if (limit) {
limit -= 1;
}
}
return str;
}
exports.trimSuffix = trimSuffix;
function ensurePrefix(s, prefix) {

@@ -56,0 +77,0 @@ if (!s.startsWith(prefix)) {

{
"name": "skynet-mysky-utils",
"version": "0.1.2",
"version": "0.2.0",
"description": "Skynet common MySky utilities",

@@ -8,2 +8,3 @@ "main": "dist/index.js",

"build": "rimraf dist && tsc --project tsconfig.build.json",
"lint": "npm run lint:tsc && npm run lint:eslint",
"lint:eslint": "eslint --ext .ts src",

@@ -10,0 +11,0 @@ "lint:tsc": "tsc",

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

export { getPathDomain, getParentPath, sanitizePath } from "./paths";
export {

@@ -5,2 +6,4 @@ Permission,

PermType,
permCategoryToString,
permTypeToString,
// Constants

@@ -11,18 +14,15 @@ PermDiscoverable,

PermRead,
PermWrite
PermWrite,
} from "./permissions";
export {
defaultWindowTimeout,
emitStorageEvent,
listenForStorageEvent,
monitorOtherListener,
PromiseController,
} from "./storage_listener";
export type {
CustomListenerOptions,
ListenForStorageEventResponse,
MonitorOtherListenerResponse,
} from "./storage_listener";
export { createFullScreenIframe, createIframe, ensureUrl } from "./utils";
export { dispatchedErrorEvent, errorWindowClosed, monitorWindowError } from "./window-listener";
createFullScreenIframe,
createIframe,
ensureUrl,
trimSuffix,
} from "./utils";
export {
dispatchedErrorEvent,
errorWindowClosed,
monitorWindowError,
} from "./window-listener";

@@ -35,4 +35,4 @@ import { Permission } from "./permissions";

export type CheckPermissionsResponse = {
grantedPermissions: Permission[],
failedPermissions: Permission[],
}
grantedPermissions: Permission[];
failedPermissions: Permission[];
};

@@ -5,5 +5,9 @@ import { Permission, PermHidden, PermWrite } from "./index";

it("Should reject invalid enum values", () => {
expect(() => new Permission("test", "test", PermWrite, PermWrite)).toThrowError("Invalid 'category' enum value 5");
expect(() => new Permission("test", "test", PermHidden, PermHidden)).toThrowError("Invalid 'permType' enum value 2");
expect(
() => new Permission("test", "test", PermWrite, PermWrite)
).toThrowError("Invalid 'category' enum value 5");
expect(
() => new Permission("test", "test", PermHidden, PermHidden)
).toThrowError("Invalid 'permType' enum value 2");
});
});

@@ -6,3 +6,3 @@ export class Permission {

public category: PermCategory,
public permType: PermType,
public permType: PermType
) {

@@ -16,3 +16,3 @@ if (typeof category !== "number" || !(category in PermCategory)) {

}
};
}

@@ -44,1 +44,37 @@ // Define category constants for non-TS users.

}
/**
* Converts the given permission category to a human-readable string.
*
* @param category - The given category.
* @returns - The string.
* @throws - Will throw if the category is not valid.
*/
export function permCategoryToString(category: PermCategory): string {
if (category === PermCategory.Discoverable) {
return "Discoverable";
} else if (category === PermCategory.Hidden) {
return "Hidden";
} else if (category === PermCategory.LegacySkyID) {
return "LegacySkyID";
} else {
throw new Error(`Invalid permission category ${category}`);
}
}
/**
* Converts the given permission type to a human-readable string.
*
* @param permType - The given type.
* @returns - The string.
* @throws - Will throw if the type is not valid.
*/
export function permTypeToString(permType: PermType): string {
if (permType === PermType.Read) {
return "Read";
} else if (permType === PermType.Write) {
return "Write";
} else {
throw new Error(`Invalid permission type ${permType}`);
}
}

@@ -24,3 +24,6 @@ /**

*/
export function createFullScreenIframe(srcUrl: string, name: string): HTMLIFrameElement {
export function createFullScreenIframe(
srcUrl: string,
name: string
): HTMLIFrameElement {
srcUrl = ensureUrl(srcUrl);

@@ -59,2 +62,27 @@

/**
* Removes a suffix from the end of the string.
*
* @param str - The string to process.
* @param suffix - The suffix to remove.
* @param [limit] - Maximum amount of times to trim. No limit by default.
* @returns - The processed string.
*/
export function trimSuffix(
str: string,
suffix: string,
limit?: number
): string {
while (str.endsWith(suffix)) {
if (limit !== undefined && limit <= 0) {
break;
}
str = str.substring(0, str.length - suffix.length);
if (limit) {
limit -= 1;
}
}
return str;
}
function ensurePrefix(s: string, prefix: string): string {

@@ -61,0 +89,0 @@ if (!s.startsWith(prefix)) {

@@ -1,10 +0,17 @@

import { PromiseController } from "./storage_listener";
export const errorWindowClosed = "window-closed";
export const dispatchedErrorEvent = "catchError";
export class PromiseController {
cleanup() {
// Empty until implemented in monitorWindowError.
}
}
/**
* Checks if there has been an error from the window on an interval.
*/
export function monitorWindowError(): { promise: Promise<void>; controller: PromiseController } {
export function monitorWindowError(): {
promise: Promise<void>;
controller: PromiseController;
} {
const controller = new PromiseController();

@@ -11,0 +18,0 @@ const abortController = new AbortController();

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

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