flamelink-js-sdk icon indicating copy to clipboard operation
flamelink-js-sdk copied to clipboard

cannot edit entry after adding via JS SDK

Open echong112 opened this issue 2 years ago • 17 comments

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 avatar Mar 07 '22 13:03 echong112

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 }

echong112 avatar Mar 07 '22 13:03 echong112

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:

  • JS SDK: [email protected]
  • CMS: Not sure where to find the version, but got an update popup just a day or two ago, so I guess the most recent one

ptreitler avatar Mar 07 '22 13:03 ptreitler

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?

gitdubz avatar Mar 07 '22 13:03 gitdubz

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

echong112 avatar Mar 07 '22 13:03 echong112

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 avatar Mar 07 '22 13:03 gitdubz

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.

gitdubz avatar Mar 07 '22 13:03 gitdubz

yes to both. node.js v14.17.6

"firebase": "^9.6.8",
"firebase-admin": "^10.0.2",
"flamelink": "^1.0.0-rc.1",

echong112 avatar Mar 07 '22 13:03 echong112

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.

echong112 avatar Mar 07 '22 13:03 echong112

In my case the content is created in an Android app via [email protected].

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?

ptreitler avatar Mar 07 '22 13:03 ptreitler

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)

gitdubz avatar Mar 07 '22 14:03 gitdubz

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.

ptreitler avatar Mar 07 '22 14:03 ptreitler

@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 avatar Mar 07 '22 16:03 gitdubz

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?

gitdubz avatar Mar 07 '22 16:03 gitdubz

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.

echong112 avatar Mar 07 '22 23:03 echong112

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 avatar Mar 10 '22 13:03 ptreitler

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 avatar Mar 10 '22 13:03 ptreitler

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.

ptreitler avatar Mar 10 '22 15:03 ptreitler