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

fix[gen1][core] ENG-7841 change to queryParams #3787

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

clyde-builderio
Copy link
Contributor

Description

Gen1 SDK: use same Content API defaults as Gen2 SDK

@clyde-builderio clyde-builderio requested a review from a team as a code owner December 17, 2024 15:09
@clyde-builderio clyde-builderio requested review from samijaber and removed request for a team December 17, 2024 15:09
Copy link

changeset-bot bot commented Dec 17, 2024

🦋 Changeset detected

Latest commit: c11643b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@builder.io/sdk Patch
@builder.io/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

nx-cloud bot commented Dec 17, 2024

View your CI Pipeline Execution ↗ for commit c11643b.

Command Status Duration Result
nx test @e2e/angular ❌ Failed 5m 34s View ↗
nx test @snippet/react-sdk-next-pages ❌ Failed 2m 27s View ↗
nx test @e2e/react-sdk-next-pages ❌ Failed 2m 2s View ↗
nx test @e2e/nextjs-sdk-next-app ✅ Succeeded 8m 17s View ↗
nx test @e2e/nuxt ✅ Succeeded 7m 46s View ↗
nx test @e2e/qwik-city ✅ Succeeded 7m 56s View ↗
nx test @e2e/react-native ✅ Succeeded 6m 2s View ↗
nx test @e2e/sveltekit ✅ Succeeded 5m 46s View ↗
Additional runs (33) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2024-12-20 13:39:33 UTC

@clyde-builderio clyde-builderio changed the title fix[gen1][core] ENG-7841 change to queryParams [DRAFT]fix[gen1][core] ENG-7841 change to queryParams Dec 17, 2024
Comment on lines 2642 to 2645
if (this.apiEndpoint === 'content') {
queryParams.enrich = true;
queryParams.noTraverse = queue[0].limit !== 1;
queryParams.includeRefs = true;

Copy link
Contributor

Choose a reason for hiding this comment

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

We should move this logic before the following code blocks:

  • for (const key of properties) {
    const value = options[key];
    if (value !== undefined) {
    if (this.apiEndpoint === 'query') {
    queryParams.options = queryParams.options || {};
    queryParams.options[options.key!] = queryParams.options[options.key!] || {};
    queryParams.options[options.key!][key] = JSON.stringify(value);
    } else {
    queryParams[key] = JSON.stringify(value);
    }
    }
    }
    }
  • if (this.overrideParams) {
    const params = omit(QueryString.parse(this.overrideParams), 'apiKey');
    assign(queryParams, params);
    }

These are two ways customers can override properties, so they need to exist after you set the noTraverse and includeRefs defaults.

I also just noticed these two noTraverse settings:

if ('noTraverse' in queue[0]) {
queryParams.noTraverse = queue[0].noTraverse;
}

// Set noTraverse=true if NOT already passed by user, for query performance
if (!('noTraverse' in options)) {
options.noTraverse = true;
}

This means that noTraverse is already handled (set to true in getAll() which has limit > 1. So you don't need to set noTraverse, you only need to add the includeRefs = true.

TLDR:

  • remove noTraverse default
  • move the includeRefs default higher up so it can still be overridden by customer
  • add some tests that show:
    • default value of includeRefs is true
    • if customer provides includeRefs: false to builder.get() or builder.getAll(), then they are able to update the URL

Copy link

gitguardian bot commented Dec 18, 2024

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
14200383 Triggered Generic High Entropy Secret 42a258b packages/core/src/builder.class.test.ts View secret
14200385 Triggered Generic High Entropy Secret 42a258b packages/core/src/builder.class.test.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@@ -2227,6 +2227,11 @@ export class Builder {
let instance: Builder = this;
let finalLocale =
options.locale || options.userAttributes?.locale || this.getUserAttributes().locale;

if (!('noTraverse' in options)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be?

Suggested change
if (!('noTraverse' in options)) {
if (!('noTraverse' in options) && this.apiEndpoint === 'content') {

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, @sanyamkamat correct me if i'm wrong but I think we want the noTraverse default for Query and Content.

Copy link
Contributor

Choose a reason for hiding this comment

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

When will there be any apiEndpoint which will not be content?

Copy link
Contributor

Choose a reason for hiding this comment

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

@samijaber Replied to your question in slack thread.

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.

4 participants