
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
firestore-rest-parser
Advanced tools
Parse and use Firestore REST API JSON as a pure js object ✨
Parse and use Firestore REST API JSON as a pure js object ✨
Or convert js object to Firestore REST structure.
Turn this:
{
"data": {
"mapValue": {
"fields": {
"username": {
"stringValue": "user"
},
"isAdmin": {
"booleanValue": true
}
}
}
}
}
Into this:
{
"data": {
"username": "user",
"isAdmin": true
}
}
Or vice versa.
Using npm:
npm install firestore-rest-parser
Using yarn:
yarn add firestore-rest-parser
import { parse } from 'firestore-rest-parser'
const obj = {
name: 'resouce/name',
fields: {
permissions: {
arrayValue: {
values: [{ stringValue: 'createUsers' }],
},
},
contacts: {
mapValue: {
email: {
prop: {
stringValue: 'example@mail.com'
},
},
},
},
unreadMessages: {
integerValue: 5
}
},
createTime: '',
updateTime: '',
}
const data = parse(obj)
/*
console.log(data) => {
permissions: ['createUsers'],
contacts: { email: 'example@mail.com' },
unreadMessages: 5
}
*/
To parse Firestore REST structure use parse
function.
import { parse } from 'firestore-rest-parser'
const firestoreObject = {
fields: {
prop: { integerValue: 1 }
}
}
const data = parse(firestoreObject)
/*
console.log(data) => {
prop: 1
}
*/
To convert js object to Firestore REST structure use convert
function.
Note
Timestamp, Reference, Bytes, GeoPoint data types must be instances of type helper classes
import { convert } from 'firestore-rest-parser'
const data = {
username: 'user',
permissions: ['createUsers']
}
const res = convert(data)
/*
console.log(res) => {
username: {
stringValue: 'user'
},
permissions: {
arrayValue: {
values: [
{ stringValue: 'createUsers' }
]
}
}
}
*/
To store Date
or timestamp
value use Timestamp
helper. Provided time will be converted to ISO format.
import { convert, Timestamp } from 'firestore-rest-parser'
const data = {
date: new Timestamp(new Date()),
timestamp: new Timestamp(1641727129175)
}
convert(data)
To store Buffer
value use Bytes
helper. Provided buffer will be converted to base64 string.
import { convert, Bytes } from 'firestore-rest-parser'
const data = {
buff: new Bytes(Buffer.from('value'))
}
convert(data)
To store Reference
(path to element in db) value use Reference
helper.
import { convert, Reference } from 'firestore-rest-parser'
const data = {
prop: new Reference('path/to/doc')
}
convert(data)
To store GeoPoint
value use GeoPoint
helper.
import { convert, GeoPoint } from 'firestore-rest-parser'
const data = {
prop: new GeoPoint(0, 0)
}
convert(data)
convert
function creates only part (fields
) of the Firestore Rest object. To create full structure
(with name
, createTime
, updateTime
) use createRESTObject
function.
import { convert, createRESTObject } from 'firestore-rest-parser'
const data = {
username: 'user',
permissions: ['createUsers']
}
const res = createRESTObject(convert(data), 'users/userId')
/* console.log(res) => {
fields: { /.../ }
name: 'users/userId',
createTime: '',
updateTime: ''
*/ }
Javascript Type | Firestore Type | Type helper required |
---|---|---|
Null | Null | |
Boolean | Boolean | |
Number (int) | Integer | |
Number (float) | Double | |
Date or UTC timestamp | Timestamp | + |
String | String | |
Buffer (base64 string) | Bytes | + |
Reference (string path) | Reference | + |
GeoPoint | GeoPoint | + |
Array | Array | |
Object | Map |
FAQs
Parse and use Firestore REST API JSON as a pure js object ✨
The npm package firestore-rest-parser receives a total of 12 weekly downloads. As such, firestore-rest-parser popularity was classified as not popular.
We found that firestore-rest-parser demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.