feat(ims-client): add PromiseTokenSession for long-running promise-token exchange - #1843
Open
byteclimber wants to merge 1 commit into
Open
feat(ims-client): add PromiseTokenSession for long-running promise-token exchange#1843byteclimber wants to merge 1 commit into
byteclimber wants to merge 1 commit into
Conversation
…ken exchange serenity-docs#33 (async prompt classification pipeline) requires a worker to exchange a promise token more than once within a single long-running job, since the exchanged access token is short-lived (~5 min) but the job can run longer. ImsPromiseClient.exchangeToken already returns the rolled promise token needed for a subsequent exchange, but nothing persisted it across calls. PromiseTokenSession wraps a CONSUMER-type ImsPromiseClient to carry that rolled token forward automatically, exposes isExpired()/getRemainingMs() for TTL checks, and surfaces a typed NeedsReauthError (distinct from a generic IMS error) when the promise token can no longer be exchanged and the user must re-authenticate. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
PromiseTokenSessionto@adobe/spacecat-shared-ims-client, wrapping a CONSUMER-typeImsPromiseClientso a long-running job can exchange a promise token more than once, automatically carrying forward the rolled promise token IMS returns on each exchange (previously discarded by callers).NeedsReauthError(error.code === 'NEEDS_REAUTH') thrown when a 401/403 from IMS means the promise token can no longer be exchanged and the user must re-authenticate — distinct from a transient/retryable error.isExpired()/getRemainingMs()for TTL checks against the rolled promise token, and an idempotentinvalidate().Context
This is Phase 1 of implementing adobe/serenity-docs#33 (async prompt classification pipeline): a future SQS-triggered worker in
spacecat-api-serviceneeds to exchange a promise token carried through the queue, potentially more than once if the job outlives one ~5-minute access token.ImsPromiseClient.exchangeTokenalready returns the rolled promise token needed for a subsequent exchange — this package just didn't have anything to persist it across calls within one job. No changes to the existingImsPromiseClientAPI or its consumers.Test plan
npm testinpackages/spacecat-shared-ims-client— 109/109 passing, 100% line/statement/function coverage on new filesnpm run lint— cleanNeedsReauthErroron 401/403, non-reauth error rethrow, TTL expiry tracking, idempotent and failinginvalidate()🤖 Generated with Claude Code