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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cap-user-info

v0.1.9

Published

CDS plugin: track created/modified user details on managed entities

Readme

cap-user-info

CDS plugin that adds user details on managed entities.

Install

npm install cap-user-info

Usage

The userinfo has the following properties by default that is added to the database

entity UserInfo {
        @UI.Hidden
    key ID         : UUID;

        @assert.unique: true  @title: 'Email Address'
        @Communication: {IsEmailAddress: true}
        Email      : String;

        GivenName  : String @title: 'Given Name';
        FamilyName : String @title: 'Family Name';
        FullName   : String = concat(
            GivenName, ' ', FamilyName
        );
}

Import it into your cds file.

using { UserTracked, UserInfo } from 'cap-user-info';

entity MyEntity : cuid, UserTracked {
  // your fields
}

The plugin auto-registers .after("CREATE" | "UPDATE") handlers on every application-service entity that includes the UserTracked aspect. Each handler UPSERTs the current user (req.user) into UserInfo. The associations _toCreatedUserInfo / _toModifiedUserInfo resolve via createdBy / modifiedBy.

The fields for createdBy and modifiedBy will automatically be shown as links with a quickview with the user details. alt text

How it works

UserTracked extends managed, so consuming entities automatically inherit createdBy / modifiedBy (and the corresponding timestamps):

It will add a quickview to the createdBy and modifiedBy to show the user details. The details are stored from the req.user upon changes to the entity. alt text

aspect UserTracked : managed { ... }

This means no extra managed declaration is required on the consuming entity — including UserTracked is enough.

Using the plugin for other purposes

Add a field to your entity and a association


using { UserTracked, UserInfo } from 'cap-user-info';

entity MyEntity : cuid, UserTracked {
  // The cds.on.insert is only to insert the userid automatically, otherwise handle it via code.
  Responsible: User @cds.on.insert: $user.id;,
  _toResponsibleUser: association to one UserInfo on _toResponsibleUser.ID = $self.Responsible
}

Then the quickview will automatically be active alt text

Extending the quickview

You can extend the UserInfo to add more data into the quickview by adding to the fieldgroup in a cds file.

  // Change the quickview
extend cap.userinfo.UserInfo with
  @UI.FieldGroup: {Data: [
    // Leave the original properties
    {
      $Type: 'UI.DataField',
      Value: GivenName
    },
    {
      $Type: 'UI.DataField',
      Value: FamilyName
    },
    {
      $Type: 'UI.DataField',
      Value: Email
    },
    // your new field
    {
      $Type: 'UI.DataField',
      Value: Department
    }, 
  ]}

  //Change the 
  @UI.HeaderInfo     : {
    ImageUrl    : '',
    TypeImageUrl: 'sap-icon://employee',
    Title       : {
        Value: FullName,
    },
    TypeName    : '',
}
  {
    // your new field iin the entity
    Department : String @title                        : 'Department';
  }

Then register your event handler to populate the data. It's important this piece of code isn't added within your srv.init method. It needs to be in the root context.

cds.on("served", () => {
  const { db } = cds.services;
  const { UserInfo } = cds.entities("cap.userinfo");

  //Register the handler for the Upsert
  db.before("UPSERT", UserInfo, async (req) => {
    //Change the data
    req.data.Department = "Admin";
  });
});

Configuration

Configure the plugin in your package.json under cds.requires.cap-user-info:

{
  "cds": {
    "requires": {
      "cap-user-info": {
        "TextProperty": "FullName"
      }
    }
  }
}

| Option | Default | Description | |---|---|---| | TextProperty | FullName | The UserInfo property used for @Common.Text on user fields and as the primary display column in the value help. Can be set to any field on UserInfo, e.g. Email. |

Internationalisation (i18n)

The plugin ships with default English labels in _i18n/i18n.properties. To override or add translations, add a properties file for your locale in your app's _i18n folder (or wherever cds.i18n.folders points):

# _i18n/i18n_de.properties
cap.userinfo.Email=E-Mail-Adresse
cap.userinfo.GivenName=Vorname
cap.userinfo.FamilyName=Nachname
cap.userinfo.FullName=Vollständiger Name
cap.userinfo.Name=Name
cap.userinfo.ContactDetails=Kontaktdaten

The following keys are used by the plugin:

| Key | Default (English) | |---|---| | cap.userinfo.Email | Email Address | | cap.userinfo.GivenName | Given Name | | cap.userinfo.FamilyName | Family Name | | cap.userinfo.FullName | Full Name | | cap.userinfo.Name | Name | | cap.userinfo.ContactDetails | Contact Details |