Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Update decodeOpaqueId.js #63

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open

Conversation

hrhosni
Copy link

@hrhosni hrhosni commented Jan 28, 2021

This is required in order to be consistent with:

if (config.REACTION_SHOULD_ENCODE_IDS === false) return id;

Since the entire encoding/decoding of IDs was built for a reason that is no longer valid, we've found it very practical to simply set the environment variable REACTION_SHOULD_ENCODE_IDS to false. This makes development considerably easier, especially for quick API tests with graphQL playground.
But in order for that to work, decodeOpaqueId() should also check for the env variable. If we don't do that, decodeOpaqueId() can return wrong namespace and id values.

(Note that decodeOpaqueId() did NOT always fail prior to our change. For example, decoding reaction/mediaRecord:xifjgK9ckbptZ2ew2 will yield a null namespace and return the ID as is (because there's no : character to split on I believe), whereas decoding ID reaction/mediaRecord:dTp6az9ghgoLSGGTo will yield a namespace equal to u and a wrong ID)

This is required in order to be consistent with: https://github.com/reactioncommerce/api-utils/blob/f7690705c49c4a0d94799ed3deaf6be9ff909f76/lib/encodeOpaqueId.js#L20

Since the entire encoding/decoding of IDs was built for a reason that is no longer valid, we've found it very practical to simply set the environment variable REACTION_SHOULD_ENCODE_IDS to false. This makes development considerably easier, especially for quick API tests with graphQL playground.
But in order for that to work, `decodeOpaqueId()` should also check for the env variable. If we don't do that, `decodeOpaqueId()` can return wrong `namespace` and `id` values.

(Note that `decodeOpaqueId()` did NOT always fail prior to our change. For example, decoding ID `xifjgK9ckbptZ2ew2 ` will yield a null namespace and return the ID as is, whereas decoding ID `dTp6az9ghgoLSGGTo` will yield a namespace equal to `u` and a wrong ID)

Signed-off-by: hrhosni <[email protected]>
@hrhosni hrhosni force-pushed the patch-1 branch 2 times, most recently from 043d1e9 to a9ab566 Compare February 24, 2021 15:28
Signed-off-by: hrhosni <[email protected]>
Signed-off-by: hrhosni <[email protected]>
Signed-off-by: hrhosni <[email protected]>
@hrhosni
Copy link
Author

hrhosni commented Feb 24, 2021

Hi @mpaktiti @mikemurray,
Would it be possible to merge this branch please? We can't really code without it (currently patch-packageing it which isn't ideal).
Thank you!

@Akarshit Akarshit self-requested a review May 12, 2021 07:44
@Akarshit Akarshit self-assigned this May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants