
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
A simple library to generate TypeScript definition files as well as Firestore rules based on a JSON Schema definition.
✨ A simple library to generate TypeScript definition files as well as Firestore rules based on a JSON Schema definition.
string
, number
, integer
, boolean
, array
, object
)read
, get, list
, write
,create
, update
, delete
)create
and update
operations based on the JSON Schema file objectnpm install fbschema
npx fbschema
The CLI will:
1️⃣ Take the current working directory and look for JSON Schema files in the fbschema
subdirectory 📂
2️⃣ Generate TypeScript interfaces in a types/fbschema
subdirectory ✍️
3️⃣ Generate Firestore rules in firestore.rules
🔒
4️⃣ Show detailed progress logs 📜
import fbschema from 'fbschema';
// ✅ Basic usage
await fbschema();
// 📂 With custom working directory
await fbschema('./your-project');
// 📢 With logging options
await fbschema('./your-project', {
emitLogs: true, // Enable logging
});
By default, the tool expects the following structure:
your-project/
├── fbschema/ # 📁 Your JSON Schema directory
│ └── *.json # 📜 Your JSON Schema files
├── types/
│ └── fbschema/ # 🏗 Generated TypeScript interfaces
│ ├── index.ts # 📌 Main entry point for the generated types
│ └── *.ts # 🔧 Generated TypeScript files
└── firestore.rules # 🔒 Generated Firestore security rules
The library generates Firestore security rules based on your JSON Schema definitions. Here's an example of how to define rules in your schema:
{
"title": "User",
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 2,
"maxLength": 50
},
"age": {
"type": "integer",
"minimum": 0,
"maximum": 120
},
"role": {
"type": "string",
"enum": ["admin", "user", "guest"]
}
},
"required": ["name", "age"],
"fbschema": {
"read": "request.auth != null",
"write": "request.auth != null && request.auth.token.admin == true",
"create": "request.auth != null",
"update": "request.auth != null && request.auth.uid == resource.data.userId"
}
}
This will generate rules that:
[!NOTE] The
fbschema
property is a custom extension to the JSON Schema specification. It's not part of the standard JSON Schema but is used by this library to define Firestore-specific security rules. All other properties in the schema follow the standard JSON Schema specification.Each rule in
fbschema
is a string containing any valid Firestore security rule expression. You can write any condition you want, and it will be directly inserted into the generated rules. If a rule is not specified, it defaults tofalse
for security.The following rules are supported:
read
: Controls read access to the collection (combines get and list)get
: Controls access to individual document readslist
: Controls access to collection querieswrite
: Controls write access to the collection (combines create, update, and delete)create
: Controls document creationupdate
: Controls document updatesdelete
: Controls document deletionNote that
read
andwrite
are convenience rules that can be used to control multiple operations at once. If you specify bothread
andget
/list
, the more specific rule takes precedence. The same applies towrite
andcreate
/update
/delete
.
🛠 All code should pass tests and be well documented. Also, check out the Commit Message Guidelines before submitting your PR.
📜 MIT
FAQs
A simple library to generate TypeScript definition files as well as Firestore rules based on a JSON Schema definition.
The npm package fbschema receives a total of 7 weekly downloads. As such, fbschema popularity was classified as not popular.
We found that fbschema demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.