Giter Club home page Giter Club logo

fireworkers's People

Contributors

alexiglesias93 avatar aliyome avatar github-actions[bot] avatar lukepighetti avatar westlinkin 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

Watchers

 avatar  avatar  avatar  avatar  avatar

fireworkers's Issues

Incorrect Endpoint URL in v0.2.0

Description

I've noticed a discrepancy in the endpoint URL between version v0.1.0 and v0.2.0. The URL structure seems to have changed, leading to potential issues.

Details

In v0.1.0, the endpoint was: https://firestore.googleapis.com/v1/projects/{project_id}/databases/(default)/documents/{path}
In v0.2.0, it has changed to: https://firestore.googleapis.com/v1/projects/{project_id}/databases/(default)/{path}

Expected Behavior

The endpoint URL should remain consistent across versions, or a change should be clearly documented.

Actual Behavior

The endpoint URL has changed between v0.1.0 and v0.2.0 without clear documentation.

Steps to Reproduce

  • Use the endpoint in v0.1.0 via get method.
  • Update to v0.2.0, and use get method.
  • Observe the change in the endpoint URL.

Cryptokey is not defined

I'm using this with these values:
const db = await Firestore.init({
uid: nanoid(16),
project_id: serviceAccount.project_id,
client_email: serviceAccount.client_email,
private_key: serviceAccount.private_key,
private_key_id: serviceAccount.private_key_id,
claims: {
premium_account: true
}
});

and if i try to create document. I get ReferenceError: CryptoKey is not defined in node_modules/dist/index.js.

get collections without using a query

Hi,

I have the need to query all of the items in a collection or sub collection. Firestore.get only returns a single document, but get can also return an array of documents.

I ended up forking your repo and adding a getCollection to add a loop when parsing the json results.

I'm happy to make a pull request if you think it would be useful addition.

/* eslint-disable @typescript-eslint/no-explicit-any */
import { extract_fields_from_document } from "./fields";
import type * as Firestore from "./types";
import { get_firestore_endpoint } from "./utils";

/**
 * Gets a collection of documents from Firestore.
 * Reference: {@link https://firebase.google.com/docs/firestore/reference/rest/v1/projects.databases.documents/get}
 *
 * @param firestore The DB instance.
 * @param collection_path The collection path.
 */
export const getCollection = async <Fields extends Record<string, any>>(
  { jwt, project_id }: Firestore.DB,
  ...args: string[]
) => {
  const endpoint = get_firestore_endpoint(project_id);
  const collection_path = args.join("/");

  const response = await fetch(`${endpoint}/${collection_path}`, {
    headers: {
      Authorization: `Bearer ${jwt}`,
    },
  });

  const data: Firestore.GetCollectionResponse = await response.json();

  if ("error" in data) throw new Error(data.error.message);

  const documents = data.documents.map((doc) =>
    extract_fields_from_document<Fields>(doc),
  );

  return documents;
};

update action will clear all other fields except the ones provided

If todos has fileds: name, completed, createdTime ... etc

const updatedTodo = await Firestore.update(db, 'todos', 'aDyjLiTViX1G7HyF74Ax', {
  completed: false,
});

executing the above code will clear the name, createdTime fields, result in this todo document has only one field: completed.

I believe you missed the updateMask.fieldPaths=completed query parameter

Export Firebase types

Hi there! Currently the underlying Firebase types (e.g. StructuredQuery) are not exported by the library, causing difficulties when using TypeScript (for example if I want to put a StructuredQuery in a variable but still get auto-complete and type checking, by annotating my variable with the type).

Is there any reason behind hiding them, or could this be done?

And thanks for this amazing library!

JWT's generated are invalid

Hi, thanks for this library! It's helped a lot :)

I noticed however, the JWT's generated by the init function are invalid, notably that they have an iat of 0 and exp of 3600.

Notably,

const db = await Firestore.init({
    uid: 'anything',
    project_id: authConfig.projectId,
    client_email: serviceUser.client_email,
    private_key: serviceUser.private_key,
    private_key_id: serviceUser.private_key_id
})

const a = await Firestore.get(db, 'users')

Would return the following error:

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

I don't know enough about JOSE to help debug or fix the actual issue, but I was able to get the library working with a JWT I generate myself using @tsndr/cloudflare-worker-jwt (https://github.com/tsndr/cloudflare-worker-jwt):

const now = new Date().getTime() / 1000

const JWT = await jwt.sign({
    iss: serviceUser.client_email,
    sub: serviceUser.client_email,
    aud: "https://firestore.googleapis.com/",
    iat: now,
    exp: now + 3600,
}, serviceUser.private_key, {algorithm: "RS256"})

Passing this into my own DB object with the public key gives me better responses. Putting the two key's into jwt.io side by side reveals:

Firestore.init jwt.sign
image image

I'm happy to open a PR that replaces jose with @tsndr/cloudflare-worker-jwt if you're okay with the library change.

[ERROR] Could not resolve "fireworkers"

src/worker.js:1:27: 1 โ”‚ import * as Firestore from 'fireworkers'; โ•ต ~~~~~~~~~~~~~ You can mark the path "fireworkers" as external to exclude it from the bundle, which will remove this error.

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.