{"_id":"@crapougnax/firestore-export-import","_rev":"1-e9877353f9fe4c0eb4ccf1e47347061b","name":"@crapougnax/firestore-export-import","dist-tags":{"latest":"0.3.0"},"versions":{"0.3.0":{"name":"@crapougnax/firestore-export-import","version":"0.3.0","description":"NPM package for backup and restore Firebase Firestore","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"mocha --timeout 60000 --exit -r ts-node/register test/**/*.spec.ts","build":"tsc --skipLibCheck && npm run minify","minify":"jsmin -o dist/index.js dist/index.js && jsmin -o dist/import.js dist/import.js && jsmin -o dist/export.js dist/export.js"},"repository":{"type":"git","url":"git+https://github.com/dalenguyen/firestore-backup-restore.git"},"keywords":["firebase","firestore","backup","restore","import","export"],"author":{"name":"Dale Nguyen","email":"dungnq@itbox4vn.com","url":"http://dalenguyen.me"},"license":"ISC","bugs":{"url":"https://github.com/dalenguyen/firestore-backup-restore/issues"},"homepage":"https://github.com/dalenguyen/firestore-backup-restore#readme","devDependencies":{"@types/chai":"^4.2.2","@types/mocha":"^5.2.7","@types/node":"^10.14.18","chai":"^4.2.0","jsmin":"^1.0.1","mocha":"^5.2.0","request":"^2.88.0","request-promise":"^4.2.4","ts-node":"^8.3.0","typescript":"^2.9.2"},"dependencies":{"@firebase/testing":"^0.13.4","firebase":"^7.1.0","firebase-admin":"^8.5.0"},"engines":{"node":">=7.6.0"},"gitHead":"3f1dc5abb7dc347ca6fc6b2096796fea73033b26","_id":"@crapougnax/firestore-export-import@0.3.0","_nodeVersion":"10.15.0","_npmVersion":"6.11.2","dist":{"integrity":"sha512-heJ7sPu0UBoua2+3GSz/Bvn/wQrsF7GXsVHzXpImORBmVv9Xq7UkqjcpR4MN1Ez1g04N/kqLP6y7RlZGNUMbKg==","shasum":"3a9b22500ea18f2dafca10b75d9100c3b9d7a8dc","tarball":"https://registry.npmjs.org/@crapougnax/firestore-export-import/-/firestore-export-import-0.3.0.tgz","fileCount":20,"unpackedSize":42529,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdnzNGCRA9TVsSAnZWagAA7voP+wd8wG7KEkuKAf+pgCed\nxSDuy49btIjGzjRF17ehHAxb99UeSvh7W06RPK3sCNR6rFmTQM1UgSs19Rhc\nA6LPGaqUW+yx4zuk6ZPckeTokK+EG/htdUQs0WH+oAONDEL0X3ups4SArhup\nxOxN63fFHXDKWqkOEiqvVSdXJfv3HW6Ib3C9wP+gziZcrz6sGc3YYfcghRpx\nUi/brojKI1ztwxsJYjhyFBrSNrDlGuyBEu/7DG6hkVHOkQXYip3WxYjms33i\nhKRk63N+Dy60lcp1xqY/+lwYAVQdKznzMOJC13BbWXhjbkLnUG/mTbTDNZI+\n3P1CsT5ceNs1W3ZYFS4lFucAf0kcoNUbXBTKBBS6wVQxTOHHYoV/692xFvKU\nJXzOBT0VVU0w8gjhg2g6ZdYL25Lv1x5DHb6LnCYMEEN+rjiPNTYLEc/IMG8y\nU9SAexTED9n69363SpVbirtrbz7y0kfrCAvlUuPRWyy9ThQfhKJ4QchqDJuh\nTnVtHVL4HIBhalxynKZZi2DiXqql7tno8D2ZENVJT67Rk2yHKv3qHb4DqHRe\nhVG6jF8wjQyqIesynOYR2RzLLbZaTjXQp6eiZLY4bQJEQZQjTxy5DEhGzJDt\nzHGW33z28aqZ8goCOQGpO8LbbAhUzuhW27YIuZtQ/+cu/yMmDRU/7mA5OuMo\nSLNF\r\n=W0oz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDKUFqjF/Q16Jc6P2DwSeHZ4Vfjehc86jtYMSei6B+bBAiEAsnrN2gtmDeLtOTwT75IKW9Wuiqn/pf6BWPDAzhdxuNI="}]},"maintainers":[{"name":"crapougnax","email":"olivier@lepine.fr"}],"_npmUser":{"name":"crapougnax","email":"olivier@lepine.fr"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/firestore-export-import_0.3.0_1570714437587_0.3212749773829702"},"_hasShrinkwrap":false}},"time":{"created":"2019-10-10T13:33:57.382Z","0.3.0":"2019-10-10T13:33:57.702Z","modified":"2022-04-05T01:37:17.437Z"},"maintainers":[{"name":"crapougnax","email":"olivier@lepine.fr"}],"description":"NPM package for backup and restore Firebase Firestore","homepage":"https://github.com/dalenguyen/firestore-backup-restore#readme","keywords":["firebase","firestore","backup","restore","import","export"],"repository":{"type":"git","url":"git+https://github.com/dalenguyen/firestore-backup-restore.git"},"author":{"name":"Dale Nguyen","email":"dungnq@itbox4vn.com","url":"http://dalenguyen.me"},"bugs":{"url":"https://github.com/dalenguyen/firestore-backup-restore/issues"},"license":"ISC","readme":"# firestore-export-import\n\n[![GitHub version](https://badge.fury.io/gh/dalenguyen%2Ffirestore-backup-restore.svg)](https://badge.fury.io/gh/dalenguyen%2Ffirestore-backup-restore)\n[![Build Status](https://travis-ci.org/dalenguyen/firestore-backup-restore.svg?branch=master)](https://travis-ci.org/dalenguyen/firestore-backup-restore)\n[![David badge](https://david-dm.org/dalenguyen/firestore-backup-restore.svg)](https://david-dm.org/dalenguyen/firestore-backup-restore)\n\nNPM package for backup and restore Firebase Firestore\n\nYou can export and import data from firestore with sub collection.\n\n## Installation\n\nInstall using [__npm__](https://www.npmjs.com/).\n\n```sh\nnpm install firestore-export-import\n```\n\n## Get Google Cloud Account Credentials from Firebase\n\nYou can __Generate New Private Key__ from Project Settings from [Firebase Console](https://console.firebase.google.com).\n\nAfter that you need to copy the __databaseURL__ for initiating the App.\n\n## Usage\n\nYou have to import this package in a JavaScript file and work from there.\n\n### Export data from firestore\n\nYou can export collection and sub collection from your data. The sub collection is optional.\n\n```javascript\n// In your index.js\n\nconst firestoreService = require('firestore-export-import');\nconst serviceAccount = require('./serviceAccountKey.json');\n\n// Initiate Firebase App\nfirestoreService.initializeApp(serviceAccount, databaseURL);\n\n// Start exporting your data\nfirestoreService\n  .backup('collection-name', 'sub-collection-optional')\n  .then(data => console.log(JSON.stringify(data)))\n```\n\nIf the sub collection exists, it will be saved under __subCollection__.\n\n### Get all collections data\n\nThis is a suggestion from [jcummings2](https://github.com/jcummings2) and [leningsv](https://github.com/Leningsv)\n\nThe ['collectionName1', 'collectionName2'] is OPTIONAL, you can remove this parameter to get all of the current collections in your firestore.\n\nThe result is an object of collection's data.\n\n```javascript\nfirestoreService\n  .backups(['collectionName1', 'collectionName2']) // Array of collection's name is OPTIONAL\n  .then(collections => {\n    // You can do whatever you want with collections\n    console.log(JSON.stringify(collections));\n  })\n\n```\n\n### Import data to firestore\n\nThis code will help you to import data from a JSON file to firestore. You have two options:\n\n+ Restore from a JSON file from your local machine\n+ Restore from a JSON from a HTTP request\n\nThis will return a Promise<{status: boolean, message: string}>\n\nRemember that, this action doesn't remove the collection. It will override or add new data to the collection. If you want to remove the current collection, you should do it from firebase console or using [firebase firestore:delete](https://firebase.google.com/docs/cli)\n\n```sh\nfirebase firestore:delete [options] <<path>>\n```\n\n#### For local JSON\n\n```javascript\n// In your index.js\n\nconst firestoreService = require('firestore-export-import');\nconst serviceAccount = require('./serviceAccountKey.json');\n\n// Initiate Firebase App\nfirestoreService.initializeApp(serviceAccount, databaseURL);\n\n// Start importing your data\n// The array of date and location fields are optional\nfirestoreService.restore('your-file-path.json', ['date1', 'date2'], ['location1', 'location2']);\n```\n\n#### For HTTP Request\n\n```javascript\nimport request from 'request-promise';\n...\nconst backupData = await request('JSON-URL');\nconst status = await firestoreService.restore(JSON.parse(backupData), ['date'], ['location']);\n```\n\nThe JSON is formated as below. The collection name is __test__. __first-key__ and __second-key__ are document ids. \n\n```json\n{\n  \"test\": {\n    \"first-key\": {\n      \"website\": \"dalenguyen.me\",\n      \"date\": {\n        \"_seconds\": 1534046400,\n        \"_nanoseconds\": 0\n      },\n      \"custom\": {\n        \"lastName\": \"Nguyen\",\n        \"firstName\": \"Dale\"\n      },\n      \"location\": {\n        \"_latitude\": 49.290683,\n        \"_longitude\": -123.133956\n      },\n      \"email\": \"dungnq@itbox4vn.com\",\n      \"subCollection\": {\n        \"test/first-key/details\": {\n          \"33J2A10u5902CXagoBP6\": {\n            \"dogId\": \"2\",\n            \"dogName\": \"hello\"\n          },\n          \"MSZTWEP7Lewx0Qr1Mu5s\": {\n            \"dogName\": \"lala\",\n            \"dogId\": \"2\"\n          }\n        }\n      }\n    },\n    \"second-key\": {\n      \"website\": \"google.com\",\n      \"date\": {\n        \"_seconds\": 1534262435,\n        \"_nanoseconds\": 0\n      },\n      \"custom\": {\n        \"lastName\": \"Potter\",\n        \"firstName\": \"Harry\"\n      },\n      \"location\": {\n        \"_latitude\": 49.290683,\n        \"_longitude\": -123.133956\n      },\n      \"email\": \"test@dalenguyen.me\"\n    }\n  }\n}\n```\n\n## Contributions\n\nThis project is based on [firestore-import-export](https://github.com/dalenguyen/firestore-import-export), feel free to report bugs and make feature requests in the [Issue Tracker](https://github.com/dalenguyen/firestore-backup-restore/issues), fork and create pull requests!\n","readmeFilename":"README.md"}