
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
csv-firestore
Advanced tools
csv-firestore, a NodeJS script meant to run in a privileged environment, will upload the contents of a CSV file into a Firestore collection. The uploaded data will be accessible to Firebase web clients or via the Firestore REST API, following the project's Firestore Rules definition.
For example, a CSV file containing the items:
server | region | element | name |
---|---|---|---|
asia | mondstat | electro | razor |
asia | liyue | cryo | ganyu |
america | liyue | geo | zhongli |
Will be stored in a Firestore collection playable_characters
, where each CSV row will be transformed into a Firestore document:
.
āāā playable_characters
ā āāā 082gt7UJHkFm8kcgXYRj
| āāāāāā server: asia
| āāāāāā region: mondstat
| āāāāāā element: electro
| āāāāāā name: razor
| |
ā āāā 0dTehs7Vq0wrmMLw0lwy
| āāāāāā server: asia
| āāāāāā region: liyue
| āāāāāā element: cryo
| āāāāāā name: ganyu
| |
ā |āā 1h4my1GwNPBcDeLhsLwZ
| āāāāāā server: asia
| āāāāāā region: liyue
| āāāāāā element: geo
| āāāāāā name: zhongli
...
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
The following dependencies are used for this project. Feel free to use other dependency versions as needed.
Recommended:
node: >= 18.20.6
npm: >= 10.8.2
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow write: if false;
allow read;
}
}
}
(See package.json for more information.)
[!IMPORTANT] firebase-admin v13.1.0 requires at least NodeJS v18+ to run.
git clone https://github.com/ciatph/csv-firestore.git
npm install --save csv-firestore
npm install
.env
file with reference to the .env.example
file. Encode your own Firebase project settings on the following variables:
FIREBASE_SERVICE_ACC
FIREBASE_PRIVATE_KEY
private_key
entry from the service account JSON filenpm start
to start the interactive session.node .\node_modules\csv-firestore\src\index.js
if installed via npm.Answer the questions appropriately when prompted:
Wait for the data upload to finish.
require('csv-firestore')
if it's installed using npm, or// examples/example.js
const path = require('path')
const CsvToFireStore = require('../src/lib/classes/csvtofirestore')
// Require as an npm package if installed using npm
// const { CsvToFireStore } = require('csv-firestore')
// Basic CsvToFireStore usage.
// Read CSV file as is and upload to a Firestore collection.
const main = async () => {
const handler = new CsvToFireStore(path.resolve(__dirname, 'example.csv'))
try {
await handler.readCSV()
} catch (err) {
console.log(err.message)
}
if (handler.data().length > 0) {
try {
await handler.firestoreUpload('my_firestore_collection')
console.log('Data uploaded.')
} catch (err) {
console.log(err.message)
}
}
}
main()
csv-firestore reads all CSV content as is and uploads it to Firestore. The following examples show how to customize csv-firestore's CSV content by overriding it's (extends) ParserCSV class.
// examples/example-parser.js
const path = require('path')
const CsvToFireStore = require('../src/lib/classes/csvtofirestore')
// Require as an npm package if installed using npm
// const { CsvToFireStore } = require('csv-firestore')
const main = async () => {
const handler = new CsvToFireStore(path.resolve(__dirname, 'example.csv'))
// Directly override CsvToFireStore's ParserCSV read() method
// and csv_rows[] {Object[]} array to include only the "name" column
// during Firestore upload
handler.read = (row) => {
handler.csv_rows.push({
name: row.name
})
}
try {
await handler.readCSV()
} catch (err) {
console.error(err.message)
}
try {
await handler.firestoreUpload('my_firestore_collection')
console.log('Data uploaded')
} catch (err) {
console.error(err.message)
}
}
main()
This method writes formatted CSV content to a new CSV file that can read by CsvToFireStore descibed on the Interactive Mode or NPM Package/Class usage methods.
// examples/example-writer.js
const path = require('path')
const CsvToFireStore = require('../src/lib/classes/csvtofirestore')
// Require as an npm package if installed using npm
// const { CsvToFireStore } = require('csv-firestore')
// MyCustomHandler extends CsvToFireStore and overrides its
// ParserCSV read() and end() methods
// to customize CSV output formatting other than CsvToFireStore's CSV read as is
class MyCustomHandler extends CsvToFireStore {
constructor(csvFilePath) {
super(csvFilePath)
this.character_names = []
}
read (row) {
// Read only the "name" column from the CSV
this.character_names.push({
name: row.name
})
}
end () {
console.log('end')
console.log(this.character_names)
}
}
// This example reads the sample CSV file, extracts its "name" column
// and writes it to a new CSV file "character_names.csv"
const main = async () => {
const parser = new MyCustomHandler(path.resolve(__dirname, 'example.csv'))
try {
await parser.readCSV()
parser.write(parser.character_names, 'character_names.csv')
} catch (err) {
console.error(err.message)
}
// Upload the custom CSV content to Firestore
try {
parser.firestoreUpload('my_firestore_collection', true, parser.character_names)
} catch (err) {
console.error(err.message)
}
}
main()
NOTE: We can also extend the ParserCSV class instead of CsvToFireStore for reading and writing CSV files. Note however that ParserCSV does not include methods for uploading data to Firestore.
const { ParserCSV } = require('csv-firestore')
if it's installed using npm, or./lib/classes/parsercsv
into a script if it's installed outside npm. See example usage below:The uploaded data will be available on Firestore. It will be accessible using various Firebase clients for web, (JS) Python, PHP, Go, and many more.
It can also be accessed from Firestore's REST API following the pattern below if public reads are allowed on the Firestore Rules.
https://firestore.googleapis.com/v1/projects/<PROJECT_ID_HERE>/databases/(default)/documents/<COLLECTION_NAME>?&key=<FIREBASE_CONFIG_API_KEY>
FAQs
Uploads CSV rows as documents to Firestore collections.
The npm package csv-firestore receives a total of 2,514 weekly downloads. As such, csv-firestore popularity was classified as popular.
We found that csv-firestore demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 0 open source maintainers 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
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.