Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the getIdentity command to read ECID from the kndctr cookie #1230

Merged
merged 23 commits into from
Feb 19, 2025

Conversation

carterworks
Copy link
Contributor

@carterworks carterworks commented Jan 27, 2025

Description

Add a step to the getIdentity (and appendIdentityToUrl) command that will read the kndctr cookie.

For review, the kndctr cookie is a url-safe base64 encoded protobuf. So decoding it involves reading the protobuf bytes. #1171 uses protobuf.js but to significantly increased bundle size.

The current main builds at 41.024 KB minzipped and with protobuf.js it builds to 56.493 KB minzipped (a 37.7% increase in size). The protobufjs library is not tree shakable, so this is as small as it could be.

With that in mind, this PR (unlike #1171) hand-implements the decoding of the protobuf. Since we only care about the ECID, we can skip decoding all the other fields, which simplifies the process significantly. Since the Konductor API also returns the region id and the information is store in the cookie, we could, in the future or in this PR, also decode that value for a little extra effort. Full details for decoding it can be found in the code and I tried to make the process as clear as possible, with many comments.

The hand-implemented version included in this PR weighs in at 41.521 KB minzipped (a 1.2% increase in size).

Now the flow is

  1. Call getIdentity or appendIdentityToUrl
  2. Wait for consent
  3. Check to see if the ECID namespace was requested (which is it, by default)
  4. Read the kndctr cookie and return that value, if it exists
  5. If not, make a request to the edge.

Related Issue

PDCL-12708: Check for ECID stored in cookie prior to sending request to Edge to obtain ECID

Motivation and Context

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change which does not add functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA or I'm an Adobe employee.
  • I have made any necessary test changes and all tests pass.
  • I have run the Sandbox successfully.

@carterworks carterworks marked this pull request as ready for review January 27, 2025 21:26
@carterworks carterworks self-assigned this Jan 27, 2025
namespaces[ecidNamespace] = ecidFromCookie;
return undefined;
}
return getIdentity(options);
})
.then(() => {
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get the ecid from cookie, edge is going to be null. Will this be a problem for some customers? If I run getIdentity in the sandbox, I get: {identity: {ECID: "66399393517766757241886600785428160922"}, edge: {regionId: 9}}. Can we pull out the region from the cookie too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find the answer for Jon's question?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't identify any use cases. We will proceed without it and make some changes if something comes up.

@carterworks carterworks force-pushed the pdcl-12708-read-ecid-from-cookie branch from a4f7d37 to 3f0e28c Compare January 31, 2025 22:06
@carterworks
Copy link
Contributor Author

I have written some tests to make sure that the failover to network request is solid—if there is no cookie, or the cookie isn't valid base64, or if the cookie isn't a valid protobuf, then we will log a console warning and fall back to network request.
We have also decided to go forward without the regionId.
Please review the latest version.

@dompuiu dompuiu removed the request for review from shammowla February 12, 2025 17:04
@@ -82,7 +94,18 @@ export default ({
return consent
.withConsent()
.then(() => {
return namespaces ? undefined : getIdentity(options);
if (namespaces) {
return undefined;
Copy link
Member

@dompuiu dompuiu Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section seems identical with the section from line 67. Can this be extracted as a method?

Copy link
Contributor

@jonsnyder jonsnyder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a functional test?

@carterworks
Copy link
Contributor Author

Can you add a functional test?

@jonsnyder There are functional tests: https://github.com/adobe/alloy/pull/1230/files#diff-0f6f78ea4f3f2771d460497bf4f4b48278e2ea0c597d729de741fcdab4dc6748

for

  • Extracts information from kndctr cookie
  • Gracefully falls back to a network request if the cookie is not base64 encoded
  • Gracefully falls back to a network request if the cookie is base64 decoded but not a valid protobuf

Do you think we should have any other tests?

@jonsnyder
Copy link
Contributor

Those tests are good I just didn't see them.

@carterworks carterworks merged commit 6a5aac9 into main Feb 19, 2025
4 checks passed
@carterworks carterworks deleted the pdcl-12708-read-ecid-from-cookie branch February 19, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants