Add extractHost and extractMyshopifyHandle to cli-kit/common/url#7754
Merged
Conversation
Contributor
Author
This was referenced Jun 8, 2026
This was referenced Jun 8, 2026
dmerand
approved these changes
Jun 8, 2026
dmerand
left a comment
Contributor
There was a problem hiding this comment.
I'm wondering if there's a generalized skill/approach here that we can encode in the repo for agents to pick up?
Contributor
Author
|
@dmerand what kind of skill do you think is missing here? |
Contributor
|
I was thinking that skill that finds the patterns that can be extracted to shared helpers. Or guidance for agents along the same lines. WDYT, have you found a detectable pattern that can be replicated? |
4a1a131 to
14f6ca7
Compare
1a47b56 to
0dba372
Compare
Provide shared URL helpers in `@shopify/cli-kit/common/url`: `extractHost` parses a hostname from a possibly-scheme-less URL string, and `extractMyshopifyHandle` returns the subdomain of a `*.myshopify.com` host. These back domain/host matching that would otherwise be re-implemented per command.
0dba372 to
c9c73a0
Compare
14f6ca7 to
854c2e3
Compare
Contributor
Differences in type declarationsWe 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:
New type declarationspackages/cli-kit/dist/public/common/gid.d.ts/**
* Extracts the trailing numeric id from a plain GraphQL global id like
* `gid://shopify/Product/123`.
*
* @param gid - A plain GraphQL global id string.
* @returns The trailing numeric id, or undefined when the string does not end with `/<digits>`.
*/
export declare function numericIdFromGid(gid: string): string | undefined;
/**
* Decodes a base64-encoded GraphQL global id (for example, the form
* Business Platform APIs return) and returns the trailing numeric id.
*
* @param gid - A base64-encoded GraphQL global id.
* @returns The trailing numeric id, or undefined when the decoded string does not end with `/<digits>`.
*/
export declare function numericIdFromEncodedGid(gid: string): string | undefined;
/**
* Encodes a plain GraphQL global id (`gid://...`) as base64, which is the
* form some Business Platform endpoints require.
*
* @param gid - A plain GraphQL global id string to encode.
* @returns The base64-encoded gid.
*/
export declare function encodeGid(gid: string): string;
Existing type declarationspackages/cli-kit/dist/public/common/url.d.ts@@ -12,4 +12,20 @@ export declare function isValidURL(url: string): boolean;
* @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
+export declare function safeParseURL(url: string): URL | undefined;
+/**
+ * Extracts the lowercased hostname from a URL-shaped string. Tolerates
+ * bare hosts (without a scheme) and inputs that come back from APIs as
+ * either or .
+ *
+ * @param value - A URL or bare host string, possibly null/undefined.
+ * @returns The lowercased hostname, or undefined when the input is empty.
+ */
+export declare function extractHost(value: string | null | undefined): string | undefined;
+/**
+ * Extracts the subdomain handle from a URL or host.
+ *
+ * @param value - A URL or host string, possibly null/undefined.
+ * @returns The myshopify subdomain handle, or undefined when the input isn't a URL.
+ */
+export declare function extractMyshopifyHandle(value: string | null | undefined): string | undefined;
\ No newline at end of file
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

WHY are these changes introduced?
shopify store info(top of this stack, #7660) needs to (a) normalize a store host out of values that arrive as eitherhttps://shop.myshopify.comor a bareshop.myshopify.com, and (b) pull the subdomain handle out of a*.myshopify.comdomain to build an admin URL. Both are generic URL operations that belong alongside the existing helpers incli-kit/common/urlrather than inside a command-specific module. This base PR adds them so the store PR can simply import them.WHAT is this pull request doing?
Adds two helpers to
@shopify/cli-kit/common/url:extractHost(value)— lowercased hostname from a URL or bare-host string; tolerates a missing scheme andnull/undefined.extractMyshopifyHandle(value)— the<handle>from a*.myshopify.comURL or host;undefinedfor anything that isn't a myshopify domain.extractMyshopifyHandleis built onextractHost, so the scheme-tolerance and null-handling are shared. No existing exports change; this is purely additive. Internal refactor with no user-facing surface, so no changeset.How to test your changes?
pnpm vitest run packages/cli-kit/src/public/common/url.test.ts— added cases cover scheme/no-scheme, casing, trailing path, non-myshopify hosts, and empty input.Checklist
URLparsing