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

certlogic-js

v1.2.2

Published

Implementation of CertLogic in TypeScript

Downloads

174

Readme

CertLogic

CertLogic is a standard for expressing logic, such as the kind you find in business/validation rules, in plain JSON format. It is a specified subset of JsonLogic, extended with necessary custom operations - e.g. for working with dates. It's part of the efforts surrounding the Digital COVID Certificate, and as such serves as the basis for defining interchangeable validation rules on top of the DCC.

This NPM package consists of an implementation of CertLogic in JavaScript(/TypeScript) which is compatible with version 1.3.2 of the specification.

API

This NPM package exposes the following top-level features:

  • CertLogicExpression, CertLogicOperation, TimeUnit: TypeScript types to capture CertLogic expressions (for generic, respectively operation expressions), and units of time, respectively. The first two of these types are backed by type guard functions named isCertLogicExpression, and isCertLogicOperation, respectively.
  • evaluate: a function that takes a CertLogic expression, and a data context, and evaluates that expression with the given data context. Note that the function will throw an Error if it encounters any problem, rather than returning some default value.
  • implementationVersion: a string constant containing the current implementation version (taken from the package.json).
  • specificationVersion: a string constant containing the latest version of the specification that this CertLogic implementation is compatible with.
  • isInt: a function to determine whether a given value represents an integer.

It also exposes a sub package certlogic-js/validation for validation, which has the following features:

  • ValidationError: a TypeScript type for reporting validation errors on (sub) expressions.
  • validateFormat: a function that validates CertLogic expressions purely based on the CertLogic format, without regarding types.
  • validate: a function that validates CertLogic expressions, and returns any violations as validation errors. Currently, this is effectively an alias for validateFormat, but that might change in the future.
  • dataAccesses: a function that computes all data accesses that may be performed by the given CertLogic expression, through contained var operations.
  • dataAccessesWithContext: a variant of the dataAccesses function that provides a list of the contexts the reported data accesses happen in. Typically, such a context is the "ambient", innermost, encompassing CertLogic expression. As an example: for the expression { "extractFromUVCI": [ { "var": "ci" }, 1 ] }, the only data access that happens pertains to ci, and its context is this entire expression.

These features can be imported using import { ... } from "certlogic-js/dist/validation. (Unfortunately, for now you need to add the /dist fragment to the import path. This will be fixed later on.)

(Formerly, this sub package was the certlogic-validation NPM package.)

Finally, it also exposes a sub package certlogic-js/misc which contains additional features/conveniences:

  • desugar: a function to "desugar" "extended CertLogic expression" to proper CertLogic expressions. At the moment, this only pertains to an additional or expression, which is desugared using De Morgan's laws. Note that no specification is provided for the "extended CertLogic expressions".
  • asCompactText: a function to render a CertLogic expression in a compact, textual notation - certainly more compact than the JSON format. Note that this notation isn't specified (at this time).

Note that documentation is...sparse outside of the CertLogic specification, and the overall documentation around CertLogic and DCC business/validation rules. In particular, code-level documentation is largely absent. On the other hand: the TypeScript source code is likely easy enough to understand.

Commandline

This NPM package exposes three CLI commands: certlogic-run, certlogic-validate, and desugar-cli. These can be used as follows:

$ npx certlogic-run <path of JSON file containing CertLogic expression> <path of JSON file containing the data context>
$ npx certlogic-validate <path of JSON file containing CertLogic expression>
$ npx certlogic-desugar < <path of JSON file containing extended CertLogic expression>

or as

$ ./node_modules/.bin/certlogic-run <path of JSON file containing CertLogic expression> <path of JSON file containing the data context>
$ ./node_modules/.bin/certlogic-validate <path of JSON file containing CertLogic expression>
$ ./node_modules/.bin/certlogic-desugar < <path of JSON file containing extended CertLogic expression>

(respectively).

inside any NPM package that has certlogic-js installed as dependency. Note that for certlogic-desugar, the "sugared" expression in input on stdin, and the desugared expression is output on stdout.

Development

Transpiling the TypeScript source to JavaScript can be done by running any of the following:

$ tsc
$ npm run build

The transpiled source is located in dist/.

Checking for circular dependencies in the transpiled source can be done as follows:

$ [npx ] npx dpdm dist/ --circular --exit-code circular:1
$ npm run check-deps

(The latter command also transpiles the source.) This command should exit with error code 1 in case of a circular dependency in the transpiled source.

Unit tests can be executed by running any of the following:

$ [npx ] mocha --recursive dist/test
$ npm test

(The latter command also transpiles the source.)

Some of the unit tests rely on the test suite, which must be present on the relative path ../specification/.

Licensing

Copyright (c) 2021 Meinte Boersma (as working for the Dutch Ministry of Health, Science, and Sports, and on behalf of/in support of the European Health Network), and all other contributors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.

You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the LICENSE for the specific language governing permissions and limitations under the License.