Add a shared GID codec to cli-kit and adopt it in app and organizations#7753
Conversation
There was a problem hiding this comment.
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
organizationsfetching logic to decode organization IDs via the shared helper. - Updated
app-management-clientto 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.
dmerand
left a comment
There was a problem hiding this comment.
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.
1a47b56 to
0dba372
Compare
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.
0dba372 to
c9c73a0
Compare
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 declarationsWe found no diffs with existing type declarations |

WHY are these changes introduced?
Decoding/encoding GraphQL global ids (
gid://shopify/<Type>/<id>) was open-coded in more than one place —app'sapp-management-clientand theorganizationsfetch service each carried their own regex/base64 handling. This is the base of the stack forshopify 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/gidand adopts it at the two existing call sites:numericIdFromGid(gid)— trailing numeric id from a plaingid://…/123(orundefined).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.tsandpackages/organizations/.../fetch.tsnow 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 throughencodeGid.pnpm vitest run packages/app packages/organizations— existing suites for the adopting call sites still pass.Checklist