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

[Themes] Theme Console - ensureReplEnv 1/2 - Storefront Password Prompting #4191

Merged
merged 8 commits into from
Jul 18, 2024

Conversation

jamesmengo
Copy link
Contributor

@jamesmengo jamesmengo commented Jul 11, 2024

WHY are these changes introduced?

WHAT is this pull request doing?

graph LR
    A[Start] --> B{Is the storefront password protected?}
    B -- No --> I[End]
    B -- Yes --> D{Is the --store-password flag provided?}
    D -- No --> E[Prompt the user for a password]
    D -- Yes --> F[Validate the provided --store-password flag]
    E --> G[Validate the prompted password]
    F --> H{Is the password valid?}
    G --> H{Is the password valid?}
    H -- Yes --> I[End]
    H -- No --> E[Prompt the user for a password]
Loading

How to test your changes?

  1. Ensure your storefront is password protected via the admin
  2. pnpm shopify theme console --dev-preview
  3. You should see a password prompt
    a. Enter a couple of incorrect passwords, then the correct one
  4. pnpm shopify theme console --dev-preview --store-password=<PASSWORD>
    a. Try with some valid and invalid passwords.
iTerm2.-.jamesmeng@Jamess-MacBook-Pro-2_._src_github.com_Shopify_cli.mp4
image

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

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

Copy link
Contributor

Thanks for your contribution!

Depending on what you are working on, you may want to request a review from a Shopify team:

  • Themes: @shopify/advanced-edits
  • UI extensions: @shopify/ui-extensions-cli
    • Checkout UI extensions: @shopify/checkout-ui-extensions-api-stewardship
  • Hydrogen: @shopify/hydrogen
  • Other: @shopify/app-management

Copy link
Contributor

github-actions bot commented Jul 11, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 72.37% 7551/10434
🟡 Branches 69.01% 3719/5389
🟡 Functions 71.37% 1997/2798
🟡 Lines 72.68% 7131/9811

Test suite run success

1736 tests passing in 800 suites.

Report generated by 🧪jest coverage report action from a2b6b54

@jamesmengo jamesmengo changed the title Jmeng/console ensure repl [Themes] Theme Console - Prompt user for storefront password Jul 12, 2024
@jamesmengo jamesmengo changed the title [Themes] Theme Console - Prompt user for storefront password [Themes] Theme Console - ensureReplEnv 1/2 - Storefront Password Prompting Jul 12, 2024
@jamesmengo jamesmengo marked this pull request as ready for review July 13, 2024 00:36
@jamesmengo jamesmengo self-assigned this Jul 13, 2024
Copy link
Contributor

We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset.
If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

@jamesmengo jamesmengo added the #gsd:40767 Fortify local development experience for Liquid themes label Jul 13, 2024
@jamesmengo jamesmengo requested review from karreiro and a team July 13, 2024 00:36
Comment on lines 16 to 28
export function promptPassword(prompt: string): Promise<string> {
const readline = createInterface({
input: process.stdin,
output: process.stdout,
})

return new Promise((resolve) => {
readline.question(prompt, (password) => {
readline.close()
resolve(password)
})
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we prompting with readline instead of using one of the prompts defined in cli-kit?
We should be consistent with the style CLI prompts

Copy link
Contributor Author

@jamesmengo jamesmengo Jul 16, 2024

Choose a reason for hiding this comment

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

Good question - let me double check with @karreiro when he returns next week.
I agree that CLI UI-Kit should be used to prompt for the password. I have applied that change 🙂


I'm trying to get the cli-kit for the REPL loop, I would like a way to optionally hide the prompt message

Currently, the prompt looks like this if I pass an empty string in message: renderTextPrompt({message: ''})

Current State
image

Desired State
I would like to hide the prompt to achieve something like this - this will bring us to parity with the current theme console command
image


I have a PR enabling the above. Could you take a look and let me know what you think 🙏🏻 ? @isaacroldan

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, we should use cli-kit prompts to get the store password. However, we really need to rely on readline to power REPL DX, as readline also supports history of commands (when users press ), the minimal UI component cohesive with other REPL tools, and the life cycle callbacks.

@lucyxiang
Copy link
Contributor

🎩 and works as expected

@jamesmengo jamesmengo merged this pull request into jmeng/themeconsole Jul 18, 2024
@jamesmengo jamesmengo deleted the jmeng/console-ensureRepl branch July 18, 2024 16:50
@sleekping
Copy link

WHY are these changes introduced?

WHAT is this pull request doing?

graph LR
    A[Start] --> B{Is the storefront password protected?}
    B -- No --> I[End]
    B -- Yes --> D{Is the --store-password flag provided?}
    D -- No --> E[Prompt the user for a password]
    D -- Yes --> F[Validate the provided --store-password flag]
    E --> G[Validate the prompted password]
    F --> H{Is the password valid?}
    G --> H{Is the password valid?}
    H -- Yes --> I[End]
    H -- No --> E[Prompt the user for a password]
Loading

How to test your changes?

  1. Ensure your storefront is password protected via the admin
  2. pnpm shopify theme console --dev-preview
  3. You should see a password prompt
    a. Enter a couple of incorrect passwords, then the correct one
  4. pnpm shopify theme console --dev-preview --store-password=<PASSWORD>
    a. Try with some valid and invalid passwords.

iTerm2.-.jamesmeng@Jamess-MacBook-Pro-2_._src_github.com_Shopify_cli.mp4
image

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

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

Hello sir pls help.. mine keeps saying incorrect password even after I used the right one

@jamesmengo
Copy link
Contributor Author

@sleekping can you ensure that you're accessing the correct storefront by passing the --store flag and specifying your store?

Could you also double check the password you set here?
image

If that doesn't work, please open an issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#gsd:40767 Fortify local development experience for Liquid themes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants