Giter Site home page Giter Site logo

lookback-legal's Introduction

Lookback Legal

A repository for terms, consents, and various legal things we show for users.

Consents

  • We store consent texts in Markdown (.md) files inside the consents directory.
  • Each directory name is treated as the name of the consent.
  • Each Markdown file inside of the directories is treated as a version of the consent. The name of the Markdown text file is irrelevant.
  • Each consent file must include YAML Front Matter. Front Matter is a way to embed metadata fields inside a text file. So each consent file should look like:
    ---
    date: 2018-05-08T14:06:00  # Required
    ---
    Your text here.

Adding a whole new consent

  1. Branch off into a new new git branch.
  2. Create a new directory in the consents directory. Give it a unique, camelCase name. This name will end up on the user object in the database, so make it easy to understand.
  3. Add a .md file in the newly created directory, with a front matter and body text. You must attach today's date formatted as an ISO string:
    ---
    date: 2018-05-08T14:06:00
    ---
    Your text here.
  4. Submit a PR on GitHub based on your branch. Ping relevant people for review.
  5. Once merged, updated relevant services which depends on this module.

Adding a new version of a consent

See steps 1) and 3-5) above.

Changing an existing consent

โš ๏ธ Never mutate an existing consent text! Add a new version instead.

API

Schema Definitions

interface Consent {
    version: string;
    name: string;
    createdAt: Date;
    text: string;
}
  • Versioning. The version property is a SHA hash of the text property, calculated at runtime.

The module expose the following APIs:

Default export

init(consentPath?: string): object

Call this function with no arguments to make it look for consents in a default directory. Returns an object with API functions:

findConsent(consentName, version?: string): Consent;

Returns a consent object for the given consentName. If no version string is passed, the latest consent version is returned. Might return null if no consent was found for the given version.

userHasConsented(user: object, consentName: string, version?: string): boolean;

Returns true if the given user has given consent for a consentName. A specific version string can be passed, otherwise the default is to check the latest available. False is returned if no consent exists for the given name.

Example Usage

This is a sample user document in a Mongo collection:

{
    // ...
    "consents": [
        {
            "name": "someConsent",
            "version": "hash...",
            "consentedAt": new Date(),
            "where": "signupForm",
            "path": "/signup"
        }
    ]
}
const { findConsent, userHasConsented } = require('lookback-legal')();

const consent = findConsent('someConsent');

console.log(userHasConsented(user, 'someConsent'));

Tests

npm test

lookback-legal's People

Contributors

brookback avatar johanbrook avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.