Socket
Socket
Sign inDemoInstall

frug

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    frug

A node app which converts JSON BD schemas into Firebase Firestore Rules. FKA 'firebase-rule-generator'


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
42.9 kB
Created
Weekly downloads
 

Readme

Source

FRuG: firebase Rule Generator

An app which converts JSON DB schemas into Firebase Firestore Rules.

  • FRuG: firebase Rule Generator

Install

$ npm install -g frug

Global Usage Example

$ frug ./schema.json ./destination.js

Sample Input

{
  "users": {
    "__frug": {
      "comments": ["You can add comments to stuff"]
    },
    "uid": {
      "uid": {
        "type": "string",
        "path_value": "uid"
      },
      "given_name": "",
      "favorite_color": {
        "type": "string",
        "regex": "(?i)^#\\d{3,6}$",
        "__frug": {
          "comments": ["Can even be made-up colors"]
        }
      }
    }
  }
}

schema reference

Sample Output

rules_version = "2";
service cloud.firestore {
  match /databases/{database}/documents {
    function signedIn() {
      return request.auth.uid != null;
    }
    function inData() {
      return request.resource.data;
    }
    // You can add comments to stuff
    match /users/{uid} {
      function isUsers(data) {
        return data.uid is string && data.uid == uid &&
          data.given_name is string &&
          // Can even be made-up colors
          data.favorite_color is string && data.favorite_color.matches('(?i)^#\\d{3,6}$') && data.favorite_color == undefined;
      }
      allow read: if false;
      allow write: if isUsers(request.resource.data);
    }
  }
}

Project-level Usage Example

Sample Project

const { build } = require("frug");

const schema = {
  "users": {
    "__frug": {
      "comments": ["You can add comments to stuff"]
    },
    "uid": {
      "uid": {
        "type": "string",
        "path_value": "uid"
      },
      "given_name": "",
      "favorite_color": {
        "type": "string",
        "regex": "(?i)^#\\d{3,6}$",
        "__frug": {
          "comments": ["Can even be made-up colors"]
        }
      }
    }
  }
};

const output = build(schema);

console.log(output);

Output

$ node ./index.js

> rules_version = "2";
service cloud.firestore {
  match /databases/{database}/documents {
    function signedIn() {
      return request.auth.uid != null;
    }
    function inData() {
      return request.resource.data;
    }
    // You can add comments to stuff
    match /users/{uid} {
      function isUsers(data) {
        return data.uid is string && data.uid == uid &&
          data.given_name is string &&
          // Can even be made-up colors
          data.favorite_color is string && data.favorite_color.matches('(?i)^#\\d{3,6}$') && data.favorite_color == undefined;
      }
      allow read: if false;
      allow write: if isUsers(request.resource.data);
    }
  }
}

Roadmap

MVP:
  description:
    Builds collection-level data validation functions
  details:
    Missing-Details:
      - bytes
      - latlang/geo
      - reference path
    __frug-metadata:
      ...

PMVP:
  description:
    Builds query rules based on meta fields in schema,
    using data validation and role-based authentication.
  details:
    - Namespace usage (math, etc)
    - Preexisting-data checks

Keywords

FAQs

Last updated on 19 Sep 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc