@metamask-previews/notification-controller
Advanced tools
Comparing version 4.0.2-preview.e5c396b to 4.0.2-preview.eb2135e
@@ -1,18 +0,7 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./NotificationController"), exports); | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkDR374FE2js = require('./chunk-DR374FE2.js'); | ||
exports.NotificationController = _chunkDR374FE2js.NotificationController; | ||
//# sourceMappingURL=index.js.map |
@@ -1,95 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NotificationController = void 0; | ||
const base_controller_1 = require("@metamask/base-controller"); | ||
const utils_1 = require("@metamask/utils"); | ||
const nanoid_1 = require("nanoid"); | ||
const name = 'NotificationController'; | ||
const metadata = { | ||
notifications: { persist: true, anonymous: false }, | ||
}; | ||
const defaultState = { | ||
notifications: {}, | ||
}; | ||
/** | ||
* Controller that handles storing notifications and showing them to the user | ||
*/ | ||
class NotificationController extends base_controller_1.BaseController { | ||
/** | ||
* Creates a NotificationController instance. | ||
* | ||
* @param options - Constructor options. | ||
* @param options.messenger - A reference to the messaging system. | ||
* @param options.state - Initial state to set on this controller. | ||
*/ | ||
constructor({ messenger, state, }) { | ||
super({ | ||
name, | ||
metadata, | ||
messenger, | ||
state: Object.assign(Object.assign({}, defaultState), state), | ||
}); | ||
this.messagingSystem.registerActionHandler(`${name}:show`, (origin, message) => this.show(origin, message)); | ||
this.messagingSystem.registerActionHandler(`${name}:dismiss`, (ids) => this.dismiss(ids)); | ||
this.messagingSystem.registerActionHandler(`${name}:markRead`, (ids) => this.markRead(ids)); | ||
this.messagingSystem.registerActionHandler(`${name}:clear`, () => this.clear()); | ||
} | ||
/** | ||
* Shows a notification. | ||
* | ||
* @param origin - The origin trying to send a notification | ||
* @param message - A message to show on the notification | ||
*/ | ||
show(origin, message) { | ||
const id = (0, nanoid_1.nanoid)(); | ||
const notification = { | ||
id, | ||
origin, | ||
createdDate: Date.now(), | ||
readDate: null, | ||
message, | ||
}; | ||
this.update((state) => { | ||
state.notifications[id] = notification; | ||
}); | ||
} | ||
/** | ||
* Dimisses a list of notifications. | ||
* | ||
* @param ids - A list of notification IDs | ||
*/ | ||
dismiss(ids) { | ||
this.update((state) => { | ||
for (const id of ids) { | ||
if ((0, utils_1.hasProperty)(state.notifications, id)) { | ||
delete state.notifications[id]; | ||
} | ||
} | ||
}); | ||
} | ||
/** | ||
* Marks a list of notifications as read. | ||
* | ||
* @param ids - A list of notification IDs | ||
*/ | ||
markRead(ids) { | ||
this.update((state) => { | ||
for (const id of ids) { | ||
if ((0, utils_1.hasProperty)(state.notifications, id)) { | ||
state.notifications[id].readDate = Date.now(); | ||
} | ||
} | ||
}); | ||
} | ||
/** | ||
* Clears the state of the controller, removing all notifications. | ||
* | ||
*/ | ||
clear() { | ||
this.update(() => { | ||
return Object.assign({}, defaultState); | ||
}); | ||
} | ||
} | ||
exports.NotificationController = NotificationController; | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkDR374FE2js = require('./chunk-DR374FE2.js'); | ||
exports.NotificationController = _chunkDR374FE2js.NotificationController; | ||
//# sourceMappingURL=NotificationController.js.map |
{ | ||
"name": "@metamask-previews/notification-controller", | ||
"version": "4.0.2-preview.e5c396b", | ||
"version": "4.0.2-preview.eb2135e", | ||
"description": "Manages display of notifications within MetaMask", | ||
@@ -18,2 +18,11 @@ "keywords": [ | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js", | ||
"types": "./dist/types/index.d.ts" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./dist/index.js", | ||
@@ -25,2 +34,3 @@ "types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean", | ||
"build:docs": "typedoc", | ||
@@ -27,0 +37,0 @@ "changelog:update": "../../scripts/update-changelog.sh @metamask/notification-controller", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
79497
21
315
1