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

Replace isStorefrontPasswordProtected with API call #5166

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

graygilmore
Copy link
Contributor

@graygilmore graygilmore commented Jan 7, 2025

WHY are these changes introduced?

We were previously determining whether or not a storefront was password protected by making a HTTP request to the storefront and checking the response status. This worked for us in the past but is a known fragile piece.

We've now shipped the ability to query whether the storefront is password protected directly in the Admin API so we no longer need to guess. This replaces all instances of isStorefrontPasswordProtected with the updated API call.

WHAT is this pull request doing?

Replaces a fragile process of guessing the meaning of an HTTP status code with making an explicit call to the Admin API to determine whether or not a storefront is password protected.

How to test your changes?

  1. Pull down gg-query-password-setting and run pnpm install && pnpm run build
  2. Ensure the Online Store that you're auth'd against has password protection enabled
  3. Run shopify theme dev --path <local theme path>
  4. Ensure you are prompted to enter your storefront's password

    Note: if you aren't prompted and you're sure you have password protection enabled then you may have already entered a password for your storefront and we've stored it. You can trigger this path by changing the password in the admin.

  5. Ensure after entering the password the dev server is correctly running
  6. Stop the process
  7. Disable password protection for your store
  8. Run shopify theme dev --path <local theme path>
  9. Ensure you are not prompted to provide a password

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Jan 7, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
75.16% (-0.03% 🔻)
8892/11831
🟡 Branches
70.28% (-0.01% 🔻)
4342/6178
🟡 Functions
75.06% (-0.02% 🔻)
2326/3099
🟡 Lines
75.71% (-0.02% 🔻)
8407/11104
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / online_store_password_protection.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / app-event-watcher.ts
93.83% (-1.23% 🔻)
86.49% 90.48% 98.61%
🔴
... / api.ts
57.56% (-1.72% 🔻)
43.75% (-1.12% 🔻)
58.54% (-1.46% 🔻)
58.9% (-1.86% 🔻)

Test suite run success

2007 tests passing in 906 suites.

Report generated by 🧪jest coverage report action from 4510992

Copy link
Contributor

@jamesmengo jamesmengo left a comment

Choose a reason for hiding this comment

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

🎩 and code both LGTM - for other reviewers, you may need to flush your store password by providing an incorrect value or changing the password via admin to trigger the input.

@graygilmore graygilmore force-pushed the gg-query-password-setting branch 2 times, most recently from 1afd8f6 to e55902a Compare January 14, 2025 17:39
@graygilmore graygilmore marked this pull request as ready for review January 14, 2025 17:42
@graygilmore graygilmore requested review from a team as code owners January 14, 2025 17:42
Copy link
Contributor

@alexanderMontague alexanderMontague left a comment

Choose a reason for hiding this comment

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

small naming nit but lgtm!

We were previously determining whether or not a storefront was password
protected by making a HTTP request to the storefront and checking the
response status. This worked for us in the past but is a known fragile
piece.

We've now shipped the ability to query whether the storefront is
password protected directly in the Admin API so we no longer need to
guess. This replaces all instances of `isStorefrontPasswordProtected`
with the updated API call.
@graygilmore graygilmore force-pushed the gg-query-password-setting branch from e55902a to f004019 Compare January 15, 2025 17:38
@graygilmore
Copy link
Contributor Author

Force Push Patch Notes

  • Rebased with main
  • Renamed isPasswordProtected back to isStorefrontPasswordProtected

Copy link
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

packages/cli-kit/dist/cli/api/graphql/admin/generated/online_store_password_protection.d.ts
import * as Types from './types.js';
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
export type OnlineStorePasswordProtectionQueryVariables = Types.Exact<{
    [key: string]: never;
}>;
export type OnlineStorePasswordProtectionQuery = {
    onlineStore: {
        passwordProtection: {
            enabled: boolean;
        };
    };
};
export declare const OnlineStorePasswordProtection: DocumentNode<OnlineStorePasswordProtectionQuery, OnlineStorePasswordProtectionQueryVariables>;

Existing type declarations

packages/cli-kit/dist/public/node/themes/api.d.ts
@@ -22,4 +22,5 @@ export declare function metafieldDefinitionsByOwnerType(type: MetafieldOwnerType
         name: string;
         category: string;
     };
-}[]>;
\ No newline at end of file
+}[]>;
+export declare function passwordProtected(session: AdminSession): Promise<boolean>;
\ No newline at end of file

@graygilmore graygilmore added this pull request to the merge queue Jan 15, 2025
Merged via the queue into main with commit 976dd9d Jan 15, 2025
27 checks passed
@graygilmore graygilmore deleted the gg-query-password-setting branch January 15, 2025 17:55
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