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

@fairandsmart/consents-ce

v2.0.10

Published

TypeScript mappings for the Fair&Smart's Right Consents Community features

Downloads

45

Readme

Fair&Smart Right Consents TypeScript support

This project implements TypeScript definitions and API helpers for the Fair&Smart Right Consents API. It's meant for use in Right Consents Front-end, but should be general enough to use in any project. The code is maintained and based on the Right Consents Back-end API resources and models, to be as close as possible to the true representation of the resources.

NPM/Node version

Known to work using node v14.21.3 (npm v6.14.18). Use NVM to force version if needed.

Install

npm i @fairandsmart/consents-ce

Interfaces and Enums

All the interface type definitions and enums are for type info only - everything will compile out. Only the API helpers produce real JavaScript output. You can import types from each service defined on the API:

import { ModelVersionDtoLight, ModelsResource } from '@fairandsmart/consents-ce/models';

API Helpers

In addition to the types, there are also simple helper functions for each API endpoint. They define the inputs and outputs to that endpoint, and will call a user-provided function with HTTP request info that you can then use to make an HTTP request. This pattern was used so the API helpers could provide full type information. These helpers are not a full API client - they assist in building one. An example:

import { RcHttpClientConfig } from '@fairandsmart/consents-ce';

function http(config: RcHttpClientConfig): Observable<ModelEntryDto> {
    // fill in the API key, handle OAuth, etc., then make an HTTP request using the config.
    return fromFetch(config.url, ...);
}

// Use either as an observable

ModelsResource.getEntry(entryId).subscribe((modelEntry: ModelEntryDto) => {
    ...  
});

// ... or a promise using the .toPromise method

const modelEntry: ModelEntryDto = await ModelsResource.getEntry(entryId).toPromise();

Note that the API Helpers all return Observables and not promises. Feel free to adapt the behavior as you see fit.

To setup the helpers properly, see the Initialization section below.

Initialization

Note: this is not required if you only want to use the library for type descriptions

If you wish to use the API helpers, you need to initialize the library in your project:

import { RightConsents } from '@fairandsmart/consents-ce';

RightConsents.init({
    apiRoot: 'http://localhost:4287',
    httpClient: myCustomHttpClient // see API Helpers for more details
})

You need to provide the endpoint at which the API is available, and a custom HttpClient to handle all the requests.

Imports

It is possible to import all services from @fairandsmart/consent-manager directly, but it's better to use the direct import:

// good
import { getEntry } from '@fairandsmart/consents-ce/models';
getEntry(...);

// works, but not as good. Use for disambiguity if needed
import { ModelsResources } from '@fairandsmart/consents-ce';
ModelsResources.getEntry(...);

Model Helpers

Some imports also contains helpers for parsing and interpreting the resources:

import { map } from 'rxjs';
import { ModelEntryDto, ModelEntryHelper, getEntry } from '@fairandsmart/consents-ce/models';

getEntry(modelId).pipe(
    map((entry: ModelEntryDto) => ModelEntryHelper.getActiveVersion(entry))
).subscribe((activeVersion) => {
    // ModelEntryHelper is an object with static methods to help you parse the entry. 
    // In this example, you can find the active version of a model
    ... 
});

Build

# build
npm run build
# pack for local import
npm run pack
# install local version in a different project
npm i {lib-repository}/lib/fairandsmart-consents-ce-{VERSION}.tgz

Contribute

  • Create a branch for your work (PRD-XXX)
  • Upgrade the version in the package-lib.json
  • Add your work
  • Run .build.sh and push
  • Create a new merge request