Giter Site home page Giter Site logo

romainvialard / firebaseapp Goto Github PK

View Code? Open in Web Editor NEW
113.0 113.0 34.0 106 KB

Google Apps Script binding for Firebase Realtime Database

License: Apache License 2.0

JavaScript 100.00%
apps-script firebase firebase-realtime-database google-apps-script

firebaseapp's People

Contributors

jeanremidelteil avatar nicolas-gomez-20 avatar romainvialard avatar simondebray avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

firebaseapp's Issues

Using "error" as key in Firebase

Currently, if you have a key named "error" in Firebase, when fetching it, the lib return an error 200 (Error: 200 - [object Object]).

Library not found in Google App Script

Hi! I have tried using your library, but it is not found in Google App Script. Library ID has changed? I tried using the MYeP8ZEEt1ylVDxS7uyg9plDOcoke7-2l project key.

Thank you!

Client authentication token generated by Service Account OAuth + FirebaseApp not valid.

I am having trouble and have narrowed down the issue to the auth token generated by .createAuthToken().

FirebaseApp.getDatabaseByUrl(fb_URL, service.getAccessToken())
                    .createAuthToken(Session.getEffectiveUser().getEmail())

When I use the Database Secret it will generate an authentication token that is usable client-side to make calls to Firebase, but for some reason an access token generated by a service account with OAuth2 doesn't make a valid authentication token.

I have also posted an issue here on StackOverflow with my code based on the tutorials mentioned in the readme.

As a side note, I love your work! It has helped me learn a lot about GAS over the years. Thank You!

Issue with optQueryParameters when using a string with only digits

I am using your FirebaseApp library as follow:

var r = base.getData("", { orderBy:"code", equalTo: code });
Assuming there are entries with the codes below, instead of valid results, I am getting these ...

var code = "12345"; // no results
var code = "03456"; // Error: Constraint index field must be a JSON primitive

The issue comes from line 249:
if (isNaN(optQueryParameters[key]) && typeof optQueryParameters[key] !== 'boolean') {
Because in both cases the function isNaN() returns false, considering both codes as numbers (that's how isNaN works as I understand), so it won't add the "" around the string value

But in this case the code values are strings with only digits, that can also have leading zeros

Is there a way to fix / workaround this situation?

Thanks in advance
Fausto

p.s.
I did a dirty hack to make it work, but not sure if it's the right approach

I just redefined isNaN as follow:

  FirebaseApp.isNaN = function(n) {
    return Number(parseFloat(n)) !== n;
  };

and it's working that way

GAS V8 runtime bug

Switched to V8 Runtime and getting a bug where when, requesting to an endpoint which would normally return 'null' the whole script crashes with the 'Error connecting to Google Server'.

Well I loaded the library locally and this fix seems to do the job
baseClass_.getData = function (path, optQueryParameters) {
// Send request
// noinspection JSAnnotator
var [res] = FirebaseApp_._buildAllRequests([
{
method: 'get',
path: path,
optQueryParameters: optQueryParameters,
},
], this);

// Throw error
if (res instanceof Error) {
throw res;
}

if(res){
return res;
}
};

TLDR: dont return anything if the value to be returned is null.

Append data to db without overwriting

First, just want to say thanks for all of the hard work on this. It works great.

My only concern is when writing data, I would like to have the option to disable overwriting. A good example is if you have a huge amount of data that will not fit in a Google sheet. The initial push to the realtime db works great but if I delete the information in that sheet and create new data in the sheet. I would like to append it to the db without overwriting. Is this possible?

If there is a work around for this already, I apologize.

PushData without inserting unique subpath

Looking for a feature to be added. If the pushdata method could optionally push directly into the path.

Currently, if I use the pushdata method it will add a subpath with a unique id under the selected path. It would be great if that object information could be added directly under the specified path instead of creating a subPath with the unique id.

I could loop through to create a record every time but this will be very slow.

This could be useful if I need to add multiple spreadsheets to a single database but do not want to overwrite the information.

getAllData data structure

Thanks for the great script! I used the library from the Google App Script and it works great!
But one thing I noticed is when calling getAllData, the returned data is not in proper json format. Instead of having colons, it has equal signs.

Here is an example return:
[{-LINN2XT9wdCMEQGhZ9C={firstName=myname, yourSalary=200000, position=ioio, salary=100000}, -LINBdoUX4-s793E-cDW={firstName=abcdsad, position=hahahhahha, salary=1223434}, -LINDhN0TNmOcP6Y6_Qq={firstName=yourname, yourSalary=2000000, position=senior leader}}]

Any clue what went wrong?

optQueryParameters argument does not work in updateData

When I try to add query parameters to an updateData call, I get the following error:

Error: Querying related parameters not supported on this request type (line 322, file "Code", project "FirebaseApp")

Is Firebase not able to add query parameters to update calls and there is just an error in the documentation? Or is it possible, and there is a bug in the code?

By the way, I love this library. It's power and simplicity have allowed me to build a world of web apps for my employer. Thank you so much for all your hard work.

getData - optQueryParameters can't take "$key" for orderBy - "Error: 400 - Provided key index type is invalid, must be string"

I was having the same issue as #23 and saw the solution to use limitToFirst & startAt for pagination as per the docs. To use startAt however, you need to use orderBy. Since my data on Firebase is in the format

{
    "hash0": "very-long-string",
    "hash1": "very-long-string",
    "hash2": "very-long-string",
    ...
}

I wanted to use orderBy="$key", however I get the following error:

image

Actual code used:

  let base = FirebaseApp.getDatabaseByUrl(url, env.token);
  return base.getData("", {orderBy: `$key`, startAt: 0, limitToFirst: 5});

Omitting the second parameter on getData() entirely returns all the data, but since I have a lot of data it fails for the same reason as other users got in #23

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.