New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

frug

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

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'

  • 0.1.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by1000%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 19 Sep 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc