npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

identity-admin

v1.27.5

Published

[![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)

Downloads

229

Readme

Identity Admin Dashboard

Build Status

How to install

npm i identity-admin

Features

  • Creating Dashboard with minimal Ui for mongoose models.
  • Provide DashboardController for custom routing and middlewares.
  • Provide multiple dashboard instances with diffrent routes.

Create new unAuthenticated Dashboard:

  • Create new instance from Dashboard.
  • Provide Resources array of resources file.
  • Build the instance after mongoose setup by passing app instance to the build function.
const dashboard: Dashboard = new Dashboard({ resources:[ <Resource: IResourceFile> ]);
dashboard.build(app);

To create new Authenticated Dashboard:

  • Create new instance from Dashboard.
  • Provide Resources array of resources file.
  • Provide authenticate function which take AdminCredentials as parameter and return a promise of boolean or user data.
  • Provide cookiesConfiguration (cookie name and cookie secret).
  • Build the instance after mongoose setup by passing app instance to the build function.
const dashboard = new Dashboard({
        resources: [ UserResource ],
        cookiesConfiguration: {
            cookiesSecret: "cokieieSecret",
            cookieName: "connect.sid"
        },
        authenticate: async (credentials: AdminCredentials) => {
            const user = await Admin.findOne({ email: credentials.email });
            if (user) {
                const matched = await bcrypt.compare(credentials.password, user.encryptedPassword);
                if (matched) {
                    return user;
                }
            }
            return false;
        }
    })
dashboard.build(app);

To create new CustomRoutes Dashboard:

This method require to implement your own view and new react app

  • Create new controller class with invirsify-express-utils notaitions and extend ActionController.
  • Create new controller class with invirsify-express-utils notaitions and extend ResourceController.
  • Create new controller class with invirsify-express-utils notaitions and extend DashboardController.
  • Provide resource file and repository in super constructor.
  • Following class will create new route /v1/contries ***Now you can pass any auth middlewares you want
@controller('/v1/actions', defaultHeaders)
export default class ActionsController extends ActionController{

  constructor(
      @inject(TYPES.IResources) private resources: IResourceFile[]) {
      super(resources);
  }
}
@controller('/v1/resources', defaultHeaders)
export default class ResourcesController extends ResourceController{

  constructor(
      @inject(TYPES.IResources) private resources: IResourceFile[]) {
      super(resources);
  }
}
@controller('/v1/contries', defaultHeaders)
export default class CountryController extends DashboardController{

  constructor(
      @inject(TYPES.ICountryRepository) private countryRepository: CountryRepository,
      @inject(TYPES.ICountryResource) private countryResource: IResourceFile  ) {

      super(CountryResource, countryRepository);
  }
}

Documentaion:

    Dashboard(dashBoardConfig: DashboardConfig);
    build(app: Application): void;

Dashboard:

Dashboard constructor to create new instance from idntity-admin.

  • dashBoardConfig:
{
  resources: IResourceFile[]; // Array of resources files.
  rootPath?: string; // optional root path default to  /dashboard
  localesOptions?: i18n.ConfigurationOptions; // locales options for custom dashboard
  cookiesConfiguration: CookieConfiguration; // cookies configuration in case of authenticated dashboard
  authenticate?: AuthenticateMiddleWare; // authenticate function used to login the admin.
}
  • IResourceFile For resource file example check IResourceFile

  • CookieConfiguration

{
  cookiesSecret: string; // cookie secret to handle sessions
  cookieName: string; // cookie name as appeared in browser
}

Admin Notifications:

To add admin notifications in your project you should add the following

  • Enable the admin notifications in the configuration file of the dashboard.

Configuration.ts

import { IConfiguartionFile } from "identity-admin/lib/types/IConfigurationFile";

export const configuration: IConfiguartionFile = {
    textFieldSize: 'small',
    defaultRowsPerPage: 50,
    adminNotifications: true // enable admin notifications
}
  • Add these lines for the admin notification repository in the inversify container.

RepositoryTypes.ts

IAdminNotificationRepository: Symbol.for('IAdminNotificationRepository')

RepositoryInversify.ts

container.bind<IAdminNotificationRepository>(TYPES.IAdminNotificationRepository).to(AdminNotificationRepository);
  • Create new dashboard controller for the admin notifications CRUD operations and another controller for the notifications services.

AdminNotificationController.ts

import { controller } from "inversify-express-utils";
import { defaultHeaders, isSessionAuth } from "@pbb/middlewares/isAuth";
import DashboardController from "identity-admin/lib/controllers/DashboardController";
import { inject } from "inversify";
import TYPES from "@pbb/container/types";
import AdminNotificationRepository from "identity-admin/lib/repositories/AdminNotificationRepository";
import { modelConfigurations } from "@pbb/settings";
import AdminNotificationsResource from "identity-admin/lib/resources/AdminNotificationsResource";

@controller("/v1/admin/adminNotifications", isSessionAuth, defaultHeaders) // admin can be changed according to your base route
export default class DashboardAdminNotificationController extends DashboardController {
  constructor(
    @inject(TYPES.IAdminNotificationRepository)
    private adminNotificationRepository: AdminNotificationRepository
  ) {
    super(
      AdminNotificationsResource,
      adminNotificationRepository,
      undefined,
      modelConfigurations
    );
  }
}

DashboardNotifications.ts

import { defaultHeaders, isSessionAuth } from "@pbb/middlewares/isAuth";
import { controller } from "inversify-express-utils";

import NotificationController from "identity-admin/lib/controllers/AdminNotificationController";

@controller("/v1/admin/notifications", isSessionAuth, defaultHeaders) // You can change the base route as your need.
export default class DashboardNotificationController extends NotificationController {
  constructor() {
    super();
  }
}

  • Import these 2 controllers in the index file of the controllers folder.

    index.ts

import './AdminNotificationController'
import './DashboardNotifications';
  • Add the resource file of the admin notifications in your index file of the resources folder.

    index.ts

// other imports
import AdminNotificationsResource from 'identity-admin/lib/resources/AdminNotificationsResource'

....

const resources: IResourceFile[] = [
    // other resources
    ...
    AdminNotificationsResource,
    ...
];

Add new notification:

To add a new notification just call the AdminNotificationCreation class as below


import {
  AdminNotificationCreation,
  NotificationNavigationType,
} from "identity-admin/lib/helpers/AdminNotifications/AdminNotificationCreation";

const record = await AdminNotificationCreation.insert({
      title: "Notification title",
      navigateTo: NotificationNavigationType.LIST,
      type: "Any notification type",
      modelName: ModelNames.User,
    });
  • In case you choose NotificationNavigationType.LIST then you should provide a model name to be navigated to
  • In case you choose NotificationNavigationType.SHOW then you should provide a model name to be navigated to and the relatedId of the record to be shown
  • In case you choose NotificationNavigationType.EXTERNAL_LINK then you should provide the external link

The Frontend code:

  • Add the notification provider just before the router.

    app.tsx

import { NotificationsContextProvider } from 'identity-admin-ui';

<NotificationsContextProvider notificationsUrl="notifications">
  <Router />
</NotificationsContextProvider>;
  • Add the notification icon in the dashboard header.

    DashboardHeader.tsx

  const showNotifications = resources?.appConfigurations?.adminNotifications;

{showNotifications && <NotificationPopover />} // Add it just above the account popover
<AccountPopover userType={userType} />