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

vamtiger-user-registry

v0.0.12

Published

A user registry custom element

Downloads

6

Readme

vamtiger-user-registry

A webcomponent for viewing, adding and deleting users from a generalised registry.

Installation

<script src="https://cdn.jsdelivr.net/npm/vamtiger-user-registry@latest/build/vamtiger-user-registry.js">

Usage

<vamtiger-user-registry>
    data-get-users-url="/api/get-users"
    data-get-user-url="/api/get-user"
    data-add-new-user-url="/api/add-new-user"
    data-delete-user-url="/api/delete-user"
</vamtiger-user-registry>

|Attribute|Method|Description| |---------|------|-----------| |data-get-users-url|GET|Enpoint returning a paginted list of users|GET |data-get-user-url|GET|Endpoint returning a single user record| |data-add-new-user-url|POST|Enpoint for adding a new user record| |data-delete-user-url|DELETE|Enpoint for removing a user record|

data-get-users-url

An endpoint returning a paginated list of users.

interface IGetUsersResponse extends IResponseBase {
    data: {
        users: {
            next_page_url: string;
            data: IUser[]
        }
    }
}

interface IResponseBase {
    result: 'successful' | 'failed' | 'error';
    message: string;
}

interface IUser {
    id: number;
    name: string;
    surname: string;
    email: string;
    position: string;
}

data-get-user-url

An endpoint return a user record.

interface IGetUserSuccessResponse extends IResponseBase {
    result: 'successful',
    message: 'retrieved user(s)',
    data: {
        user: IUser
    }
}

interface IGetUserFailedResponse extends IResponseBase {
    result: "failed",
    message: "retrieved user(s) failed",
    data: {
        user: number;
    }
}

data-add-new-user-url

An enpoint for creating a new user record.

interface IAddNewUserSuccessRequestBody extends IUser{}

interface IAddNewUserSuccessResponse extends IResponseBase {
    result: 'successful';
    message: 'added new user',
    data: {
        user: number
    }
}

interface IAddNewUserFailedResponse extends IResponseBase {
    result: 'failed';
    message: 'failed to add new user',
    data: {
        [key: string]: {
            error: string;
            errorDescription?: string;
        }[]
    }
}

data-delete-user-url

An endpoint for removing a user record. e.g.some/url/${user_id}

interface IDeleteUserResponse extends IResponseBase {
    data: {
        user: number;
        delete: number;
    }
}

Test Mode

The custom element can also be rendered in test mode to toggle layout markers.

<vamtiger-user-registry>
    data-test-mode
</vamtiger-user-registry>

Demo

Angular Compatibility

Custom elements integrate fairly easily with Angular. To enable support, update app.module.ts:

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
    ...,
    schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
});

Create a placeholder component:

ng generate component vamtiger-user-registry

Define the required url properties for the newly created component, vamtiger-user-registry.component.ts:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-vamtiger-user-registry',
  templateUrl: './vamtiger-user-registry.component.html',
  styleUrls: ['./vamtiger-user-registry.component.css']
})
export class VamtigerUserRegistryComponent implements OnInit {
  getUsersUrl = 'api/get-users';
  getUserUrl = 'api/get-user';
  addNewUserUrl = 'api/add-new-user';
  deleteUserUrl = 'api/delete-user';
  headerImageurl = 'https://some/heade/image/url';

  constructor() { }

  ngOnInit(): void {
  }

}

Reference vamtiger-user-registry in the component template (i.e. vamtiger-user-registry.component.html):

<vamtiger-user-registry
[attr.data-get-users-url]="getUsersUrl"
[attr.data-get-user-url]="getUserUrl"
[attr.add-new-user-url]="addNewUserUrl"
[attr.delete-user-url]="deleteUserUrl"
[slot]=""
>
    <img slot="header-image" [src]="headerImageurl">
    <div slot="header-caption">
        Vamtiger User Registry Angular
    </div>
</vamtiger-user-registry>

React Compatibility

Custom Elements can also be used with React:

class VamtigerUserRegistryReact extends React.Component {
    readonly vamtigerUserRegistry: React.RefObject<VamtigerUserRegistry>;

    constructor(props: any) {
        super(props);

        this.vamtigerUserRegistry = React.createRef();

        this.state = {
            data: {
                'data-test-mode': true,
                'data-get-users-url': '/api/get-users'
                'data-get-user-url': '/api/get-user',
                'add-new-user-url': '/api/add-new-user',
                'delete-user-url': '/api/delete-user'
            },
            headerImageUrl: 'https://some/heade/image/url'
        }
    }

    render() {
        const { data, headerImageurl } = this.state;

        return (
            <vamtiger-user-registry
                ref={this.vamtigerUserRegistry}
                {...data}
            >
                <img slot="header-image" src={headerImageurl}>
            </vamtiger-user-registry>
        );
    }
}

const container = document.createElement('div');
container.id = 'vamtiger-user-registry-react';
document.body.appendChild(container);

ReactDOM.render(
    <VamtigerUserRegistryReact />,
    container
);

Example Backend API

|Langauage|Framework|Repository| |-|-|-| |PHP|Laravel|vamtiger-user-registry-laravel| |Python|Django|vamtiger-user-registry-django|