Skip to content

Add extractHost and extractMyshopifyHandle to cli-kit/common/url#7754

Open
amcaplan wants to merge 1 commit into
ariel/cli-kit-gid-codecfrom
ariel/cli-kit-url-helpers
Open

Add extractHost and extractMyshopifyHandle to cli-kit/common/url#7754
amcaplan wants to merge 1 commit into
ariel/cli-kit-gid-codecfrom
ariel/cli-kit-url-helpers

Conversation

@amcaplan

@amcaplan amcaplan commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

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 either https://shop.myshopify.com or a bare shop.myshopify.com, and (b) pull the subdomain handle out of a *.myshopify.com domain to build an admin URL. Both are generic URL operations that belong alongside the existing helpers in cli-kit/common/url rather 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 and null/undefined.
  • extractMyshopifyHandle(value) — the <handle> from a *.myshopify.com URL or host; undefined for anything that isn't a myshopify domain.

extractMyshopifyHandle is built on extractHost, 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

  • I've considered possible cross-platform impacts (Mac, Linux, Windows) — pure string/URL parsing
  • I've considered possible documentation changes — internal helpers, no public docs
  • I've considered analytics changes to measure impact — none
  • The change is user-facing — N/A, internal refactor; no changeset

amcaplan commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label Jun 8, 2026
@amcaplan amcaplan marked this pull request as ready for review June 8, 2026 15:56
@amcaplan amcaplan requested a review from a team as a code owner June 8, 2026 15:56

@dmerand dmerand left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering if there's a generalized skill/approach here that we can encode in the repo for agents to pick up?

@amcaplan

amcaplan commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@dmerand what kind of skill do you think is missing here?

dmerand commented Jun 9, 2026

Copy link
Copy Markdown
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?

@amcaplan amcaplan force-pushed the ariel/cli-kit-url-helpers branch from 4a1a131 to 14f6ca7 Compare June 9, 2026 18:26
@amcaplan amcaplan force-pushed the ariel/cli-kit-gid-codec branch from 1a47b56 to 0dba372 Compare June 9, 2026 18:26
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.
@amcaplan amcaplan force-pushed the ariel/cli-kit-gid-codec branch from 0dba372 to c9c73a0 Compare June 9, 2026 20:19
@amcaplan amcaplan force-pushed the ariel/cli-kit-url-helpers branch from 14f6ca7 to 854c2e3 Compare June 9, 2026 20:19
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
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/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 declarations

packages/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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants