flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
42 stars 5 forks source link

cannot edit entry after adding via JS SDK #196

Open echong112 opened 2 years ago

echong112 commented 2 years ago

When running a node.js migration script for about 400 entries. migration went fine, but i cannot seem to edit any of the entries on the CMS. The createdBy us 'UNKNOWN', and is the only difference I am seeing so far. Thank you!

app.content.add({ schemaKey: 'videos', data: { title: 'new-title' } })

echong112 commented 2 years ago

One additional note: I am seeing the schemaRef being different for the SDK created vs. the CMS created.

_fl_meta : { schemaRef: fl_schemas/videos } vs.

_fl_meta : { schemaRef: fl_schemas/p5T6tjZbgQgc3J9BmiRf }

ptreitler commented 2 years ago

Same here. When editing an entry that I recently added via the JS SDK in the Flamelink App I get:

Save Unsuccessful

The browser console shows [Violation] 'setTimeout' handler took 407ms

I can still edit entries that I created with the JS SDK a while ago, so this is probably related to a recent update of either the JS SDK or Flamelink CMS itself.

Versions:

gitdubz commented 2 years ago

One additional note: I am seeing the schemaRef being different for the SDK created vs. the CMS created.

_fl_meta : { schemaRef: fl_schemas/videos } vs.

_fl_meta : { schemaRef: fl_schemas/p5T6tjZbgQgc3J9BmiRf }

is the "schemaRef: fl_schemas/videos" when using the SDK or when creating an entry via the CMS?

also: Are you both working on the same project or are these separate issues that a similar in error?

echong112 commented 2 years ago

SDK created: fl_schemas/videos CMS created: fl_schemas/p5T6tjZbgQgc3J9BmiRf

gitdubz commented 2 years ago

Thanks, I will have a look at the SDK, the CMS created value is correct.

You can perhaps test on your end, if you change the ref to fl_schemas/p5T6tjZbgQgc3J9BmiRf for an entry created via the SDK in the DB, and then check if it works in the CMS?

gitdubz commented 2 years ago

Just to confirm, the Flamelink SDK is initialized using the firebase-admin SDK and not the firebase client SDK and is running in a node environment and not a browser.

echong112 commented 2 years ago

yes to both. node.js v14.17.6

"firebase": "^9.6.8",
"firebase-admin": "^10.0.2",
"flamelink": "^1.0.0-rc.1",
echong112 commented 2 years ago

Thanks, I will have a look at the SDK, the CMS created value is correct.

You can perhaps test on your end, if you change the ref to fl_schemas/p5T6tjZbgQgc3J9BmiRf for an entry created via the SDK in the DB, and then check if it works in the CMS?

this did not work. i updated the 'createBy' as well to see if that would help, but both did not work.

ptreitler commented 2 years ago

In my case the content is created in an Android app via react-native-firebase@14.5.0.

Interestingly, downgrading the JS SDK to the previously used version (1.0.0-alpha.34) doesn't change anything either. So probably a change in the CMS that somehow broke things?

gitdubz commented 2 years ago

From what I can tell the createdDate is a string timestamp and not a Firestore timestamp and in the case of @echong112 the schema ref is also incorrect.

I am just having a look too see if this might be related to changes on the Firebase SDK's (newer versions)

ptreitler commented 2 years ago

Possibly related: I also noticed that setting the content status (Draft / Review / Publish) stopped working: https://github.com/flamelink/flamelink-js-sdk/issues/183

When I add content with status: "draft" (or with the old workaround via .update()) it shows up as "Publish" in the CMS.

gitdubz commented 2 years ago

@ptreitler @echong112

This might be a side-effect of latest versions of the Firebase SDK's.

For now, if you are using the firebase-admin SDK, it should work as expected if you use < 10 (e.g 9.21.0)

I have not had a chance to test this yet, but from looking at the code, the fallback value is a string date.

gitdubz commented 2 years ago

Possibly related: I also noticed that setting the content status (Draft / Review / Publish) stopped working: #183

When I add content with status: "draft" (or with the old workaround via .update()) it shows up as "Publish" in the CMS.

Can you perhaps provide me with a code example of how you are using this at the moment?

echong112 commented 2 years ago

For now, if you are using the firebase-admin SDK, it should work as expected if you use < 10 (e.g 9.21.0)

This seems to have solved the issue.

ptreitler commented 2 years ago

Possibly related: I also noticed that setting the content status (Draft / Review / Publish) stopped working: #183 When I add content with status: "draft" (or with the old workaround via .update()) it shows up as "Publish" in the CMS.

Can you perhaps provide me with a code example of how you are using this at the moment?

Pretty much exactly as described in the other issue:

 app.content.add({
  schemaKey: 'blogPost',
    data: {
      title: 'New Post',
    },
    status: 'draft',
 })
ptreitler commented 2 years ago

I haven't managed to fix this by downgrading react-native-firebase after trying several older major versions. Not sure which one would correspond to the admin SDK v9.* though.

@gitdubz I also noticed that some older entries created by the SDK have a schemaRef like fl_schemas/videos, but can be edited just fine.

ptreitler commented 2 years ago

I found a different workaround - updating the broken timestamp manually:

flamelinkApp.content
  .add({
    schemaKey: "mySchema",
    data: {
      title: 'New Post',
    },
    status: "draft",
  })
  .then(post => {
    const docId = post._fl_meta_.docId
    firebase
      .firestore()
      .collection("fl_content")
      .doc(docId)
      .update({
        _fl_meta_: {
          ...post._fl_meta_,
          createdDate: firebase.firestore.FieldValue.serverTimestamp(),
        },
      })
  })

Setting the draft status seems to work this way as well.