Repository navigation
Conversation
With an automation token that has no Dev store management, store create dev, store list and store delete crashed with a raw "GraphQL Error (Code: 401)" and a stack trace. The Business Platform token exchange succeeds, because the CLI requests no explicit scopes, and the Organizations API then refuses the token with an empty 401. cli-kit's refresh retry exchanges the same token again, gets the same 401, and the raw graphql-request error reaches the top level as an unexpected error. Store commands now send their Organizations API requests through storeManagementRequestDoc, next to businessPlatformTokenRefreshHandler in the organizations package. When a 401 survives the refresh retry while an automation token is in use, it aborts with "This token can't manage dev stores." and points to creating a service account with Dev store management. Expired, revoked and invalid tokens still fail earlier, at the token exchange. A 403, which this API only sends for a locked organization, human sessions and other errors are unchanged. Co-authored-by: Eddie Gao <eddie.gao@shopify.com>
This branch has not been deployed
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.
Closes shop/issues-develop#24293
TL;DR: With a token whose service account doesn't have Dev store management,
store create dev,store listandstore deletenow stop with "This token can't manage dev stores." and a next step, instead of crashing with a rawGraphQL Error (Code: 401)and a stack trace.WHY are these changes introduced?
Found in the Organization Tokens end-to-end run on October 16 (finding F3). With an app-only token:
What happens:
graphql-requesterror reaches the top level and is reported as an unexpected error, with a stack trace.Expired, revoked and invalid tokens never get this far. Identity refuses the exchange, and the CLI already stops with "The custom token provided can't be used for the Business Platform API." A token revoked partway through a command fails the same way on the refresh. So a 401 that survives the refresh means the token lacks Dev store management.
WHAT is this pull request doing?
storeManagementRequestDoc()in the organizations package, next tobusinessPlatformTokenRefreshHandlerand exported the same way. It callsbusinessPlatformOrganizationsRequestDocunchanged. If the request still fails with a 401 after the refresh retry while an automation token is in use (getAppAutomationToken()), it throws anAbortError:"Dev store management" is the option's label in the Shopify admin. The status is read from the error's shape, as in
store'sadmin-errors.ts, so the package doesn't importgraphql-request.Store commands use it for all six of their Organizations API calls:
store create dev: create and poll;store delete: store lookup, delete and poll;store list.Unchanged:
[ORGANIZATION_DISABLED]), so mapping it would give the wrong reason.store infoandorganization listcan't produce this crash.store info's Organizations API lookup already ignores errors. Whetherstore infoshould explain a missing store for a service-account token belongs with shop/issues-develop#24291.organization listuses the Destinations API, which app tokens can read.No changeset: store commands with automation tokens ship for the first time in 4.10, under the
SHOPIFY_SERVICE_ACCOUNT_TOKENchangeset.How to manually test your changes?
With an App Automation Token, or a service account token without Dev store management:
Each one stops with "This token can't manage dev stores." and the next step, with no stack trace.
shopify organization liststill lists the organization.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add