Skip to content

Commit

Permalink
Merge pull request #40 from Sitlintac/update-dependencies-esm
Browse files Browse the repository at this point in the history
chore: update dependencies and convert to ESM
  • Loading branch information
Sitlintac authored Feb 6, 2024
2 parents 7a97759 + 52a8be8 commit c9a5c1f
Show file tree
Hide file tree
Showing 7 changed files with 15,561 additions and 13,919 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 20
cache: "npm"
- run: npm ci
- run: npm test
Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 20
cache: "npm"
- run: npm ci
- name: Release
Expand Down
3 changes: 0 additions & 3 deletions config/release.config.js

This file was deleted.

60 changes: 60 additions & 0 deletions index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const admin = require('firebase-admin')

module.exports = class FirestoreDBContextStore {
constructor(serviceAccount, collectionName) {
if (!serviceAccount) {
throw new Error('Need a valid serviceAccount.json')
}

this.serviceAccount = serviceAccount
this.collectionName = collectionName || 'installedApps'

admin.initializeApp({
credential: admin.credential.cert(this.serviceAccount),
})
this.db = admin.firestore()
this.installedApps = this.db.collection(this.collectionName)
}

get(installedAppId) {
return new Promise((resolve, reject) => {
this.installedApps
.doc(installedAppId)
.get()
.then(snapshot => {
resolve(snapshot.data())
})
.catch(reject)
})
}

put(parameters) {
return new Promise((resolve, reject) => {
this.installedApps
.doc(parameters.installedAppId)
.set(parameters, {merge: true})
.then(resolve)
.catch(reject)
})
}

update(installedAppId, parameters) {
return new Promise((resolve, reject) => {
this.installedApps
.doc(installedAppId)
.update(parameters, {merge: true})
.then(resolve)
.catch(reject)
})
}

delete(installedAppId) {
return new Promise((resolve, reject) => {
this.installedApps
.doc(installedAppId)
.delete()
.then(resolve)
.catch(reject)
})
}
}
18 changes: 8 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'
import * as admin from 'firebase-admin'

const admin = require('firebase-admin')

module.exports = class FirestoreDBContextStore {
export class FirestoreDBContextStore {
constructor(serviceAccount, collectionName) {
if (!serviceAccount) {
throw new Error('Need a valid serviceAccount.json')
Expand All @@ -12,7 +10,7 @@ module.exports = class FirestoreDBContextStore {
this.collectionName = collectionName || 'installedApps'

admin.initializeApp({
credential: admin.credential.cert(this.serviceAccount)
credential: admin.credential.cert(this.serviceAccount),
})
this.db = admin.firestore()
this.installedApps = this.db.collection(this.collectionName)
Expand All @@ -30,21 +28,21 @@ module.exports = class FirestoreDBContextStore {
})
}

put(params) {
put(parameters) {
return new Promise((resolve, reject) => {
this.installedApps
.doc(params.installedAppId)
.set(params, {merge: true})
.doc(parameters.installedAppId)
.set(parameters, {merge: true})
.then(resolve)
.catch(reject)
})
}

update(installedAppId, params) {
update(installedAppId, parameters) {
return new Promise((resolve, reject) => {
this.installedApps
.doc(installedAppId)
.update(params, {merge: true})
.update(parameters, {merge: true})
.then(resolve)
.catch(reject)
})
Expand Down
Loading

0 comments on commit c9a5c1f

Please sign in to comment.