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

Authenticate on app init command #4492

Merged
merged 26 commits into from
Sep 25, 2024
Merged

Authenticate on app init command #4492

merged 26 commits into from
Sep 25, 2024

Conversation

isaacroldan
Copy link
Contributor

@isaacroldan isaacroldan commented Sep 20, 2024

WHY are these changes introduced?

All commands should require authentication, starting with app init.

WHAT is this pull request doing?.

  • Move the logic for the init command from create-app to app, so we are inverting the dependency, now create-app will depend on app and will expose the init command from there.
    This allows the init command to access all the shared stuff from app and cli-kit

  • Remove the name prompt, no longer needed since it will happen during app selection

  • Clear up some extra messages that are not needed anymore

  • Add an auth step to the app init command and forces the user to select and org and app so that the project is linked to a remote app from the start. (the link happens in the init service)

  • Extract some of the utilities and validations to their own files and add tests for them.

How to test your changes?

Install the snapit version.

run:

shopify auth logout
shopify app init

or

shopify auth logout
npm create @shopify/app@<the snapit version>

Post-release steps

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-inner-loop

Copy link
Contributor

github-actions bot commented Sep 20, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.74% (-0.35% 🔻)
8488/11669
🟡 Branches
69.44% (-0.16% 🔻)
4156/5985
🟡 Functions
71.56% (-0.3% 🔻)
2202/3077
🟡 Lines
73.07% (-0.37% 🔻)
8032/10992
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🔴
... / init.ts
0% 0% 0% 0%
🟢
... / init.ts
96.43% 57.89% 100% 96.3%
🔴
... / init.ts
0% 0% 0% 0%
🟢
... / validate.ts
100% 100% 100% 100%
🟢
... / cleanup.ts
100% 100% 100% 100%
🟢
... / npm.ts
100% 85.71% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / select-app.ts
92.86% (-0.48% 🔻)
75% 100% 100%

Test suite run success

1928 tests passing in 872 suites.

Report generated by 🧪jest coverage report action from ad6d0ab

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code in this file was just moved from the original init.ts and extracted to its own file. I also added tests, but I'd say you don't need to spend a lot reviewing this

@isaacroldan isaacroldan marked this pull request as ready for review September 20, 2024 12:42
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.

@isaacroldan
Copy link
Contributor Author

/snapit

Copy link
Contributor

🫰✨ Thanks @isaacroldan! Your snapshot has been published to npm.

Test the snapshot by intalling your package globally:

pnpm i -g @shopify/cli@0.0.0-snapshot-20240923104240

After installing, validate the version by running just shopify in your terminal
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

* The Client ID of your app.
* @environment SHOPIFY_FLAG_CLIENT_ID
*/
'--client-id <value>'?: string
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be used to init an app, but linked to an existing? 🤔

Command docs should reflect that if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, this is actually the file for the command docs.

I added this for the case where you might want to have some automated CI test that create new apps, you'd need to have a non-interactive option to create them. By passing this you avoid the prompts to select an app.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add that to the flag description, so it's more obvious when you would use it?

Copy link
Contributor

@gonzaloriestra gonzaloriestra left a comment

Choose a reason for hiding this comment

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

It works as expected with Partners, but not with App Management API. We can have a look tomorrow.

@gonzaloriestra
Copy link
Contributor

/snapit

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

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/common/url.d.ts
@@ -5,4 +5,11 @@
  * @returns True if the URL is valid, false otherwise.
  * @throws An error if URL's constructor throws an error other than .
  */
-export declare function isValidURL(url: string): boolean;
\ No newline at end of file
+export declare function isValidURL(url: string): boolean;
+/**
+ * Safely parse a string into a URL.
+ *
+ * @param url - The string to parse into a URL.
+ * @returns A URL object if the parsing is successful, undefined otherwise.
+ */
+export declare function safeParseURL(url: string): URL | undefined;
\ No newline at end of file
packages/cli-kit/dist/public/node/node-package-manager.d.ts
@@ -293,4 +293,17 @@ export declare function addResolutionOrOverride(directory: string, dependencies:
  * @param packageJSON - Package.json file to write.
  */
 export declare function writePackageJSON(directory: string, packageJSON: PackageJson): Promise<void>;
+/**
+ * Infers the package manager to be used based on the provided options and environment.
+ *
+ * This function determines the package manager in the following order of precedence:
+ * 1. Uses the package manager specified in the options, if valid.
+ * 2. Infers the package manager from the user agent string.
+ * 3. Infers the package manager used for the global CLI installation.
+ * 4. Defaults to 'npm' if no other method succeeds.
+ *
+ * @param optionsPackageManager - The package manager specified in the options (if any).
+ * @returns The inferred package manager as a PackageManager type.
+ */
+export declare function inferPackageManager(optionsPackageManager: string | undefined, env?: NodeJS.ProcessEnv): PackageManager;
 export {};
\ No newline at end of file

Copy link
Contributor

🫰✨ Thanks @gonzaloriestra! Your snapshot has been published to npm.

Test the snapshot by intalling your package globally:

pnpm i -g @shopify/cli@0.0.0-snapshot-20240925094301

After installing, validate the version by running just shopify in your terminal
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

Copy link
Contributor

@gonzaloriestra gonzaloriestra left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the App Management issue! Everything looks perfect now 👌

@isaacroldan isaacroldan added this pull request to the merge queue Sep 25, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 25, 2024
@isaacroldan isaacroldan added this pull request to the merge queue Sep 25, 2024
Merged via the queue into main with commit f0318f3 Sep 25, 2024
@isaacroldan isaacroldan deleted the login-on-init branch September 25, 2024 15:28
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