Skip to content

Add a shared GID codec to cli-kit and adopt it in app and organizations#7753

Open
amcaplan wants to merge 1 commit into
mainfrom
ariel/cli-kit-gid-codec
Open

Add a shared GID codec to cli-kit and adopt it in app and organizations#7753
amcaplan wants to merge 1 commit into
mainfrom
ariel/cli-kit-gid-codec

Conversation

@amcaplan

@amcaplan amcaplan commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

Decoding/encoding GraphQL global ids (gid://shopify/<Type>/<id>) was open-coded in more than one place — app's app-management-client and the organizations fetch service each carried their own regex/base64 handling. This is the base of the stack for shopify store info, which needs the same decoding for Business Platform ids, so the logic is centralized into one small, tested cli-kit module rather than copied a third time.

WHAT is this pull request doing?

Adds @shopify/cli-kit/common/gid and adopts it at the two existing call sites:

  • numericIdFromGid(gid) — trailing numeric id from a plain gid://…/123 (or undefined).
  • numericIdFromEncodedGid(gid) — same, for the base64-encoded form Business Platform APIs return.
  • encodeGid(gid) — base64-encode a plain gid (the form some BP endpoints require).

packages/app/.../app-management-client.ts and packages/organizations/.../fetch.ts now call the shared helpers instead of their inline equivalents. Behavior is unchanged — this is a pure, internal refactor with no user-facing surface, so no changeset is included (consistent with how other private-package extractions in this repo are handled).

How to test your changes?

  • pnpm vitest run packages/cli-kit/src/public/common/gid.test.ts — 6 unit tests cover plain/encoded decoding, the no-trailing-id case, and round-tripping through encodeGid.
  • pnpm vitest run packages/app packages/organizations — existing suites for the adopting call sites still pass.

Checklist

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

@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:55
@amcaplan amcaplan requested a review from a team as a code owner June 8, 2026 15:55
Copilot AI review requested due to automatic review settings June 8, 2026 15:55

Copilot AI 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.

Pull request overview

This PR centralizes GraphQL Global ID (GID) encoding/decoding into a shared @shopify/cli-kit/common/gid helper and refactors existing app and organizations call sites to use it, reducing duplicated regex/base64 handling across the codebase.

Changes:

  • Added a new shared GID codec module in cli-kit (numericIdFromGid, numericIdFromEncodedGid, encodeGid) with unit tests.
  • Updated organizations fetching logic to decode organization IDs via the shared helper.
  • Updated app-management-client to use the shared helper for encoding/decoding GIDs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/organizations/src/cli/services/fetch.ts Switches org ID decoding to the shared cli-kit GID helper.
packages/cli-kit/src/public/common/gid.ts Introduces shared GID parsing/encoding utilities.
packages/cli-kit/src/public/common/gid.test.ts Adds unit tests covering plain/encoded decoding and encoding round-trips.
packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts Replaces inline GID encode/decode logic with shared helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/organizations/src/cli/services/fetch.ts Outdated
Comment thread packages/cli-kit/src/public/common/gid.ts Outdated

@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.

Approving as all suggestions are for net-new adjustments to code that's just moved in this PR. I would like to see the suggestions implemented though.

@amcaplan amcaplan force-pushed the ariel/cli-kit-gid-codec branch from 1a47b56 to 0dba372 Compare June 9, 2026 18:26
@amcaplan amcaplan added this pull request to the merge queue Jun 9, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 9, 2026
@amcaplan amcaplan added this pull request to the merge queue Jun 9, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 9, 2026
Introduce `@shopify/cli-kit/common/gid` (numericIdFromGid, numericIdFromEncodedGid,
encodeGid) and use it from the app-management client and the organizations fetch
service, replacing the GID encode/decode logic that was duplicated inline across
packages.
@amcaplan amcaplan force-pushed the ariel/cli-kit-gid-codec branch from 0dba372 to c9c73a0 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

We found no diffs with existing type declarations

@amcaplan amcaplan added this pull request to the merge queue Jun 10, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 10, 2026
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.

3 participants