Skip to content

feat(ims-client): add PromiseTokenSession for long-running promise-token exchange - #1843

Open
byteclimber wants to merge 1 commit into
mainfrom
worktree-agent-a8870dd395f19c637
Open

feat(ims-client): add PromiseTokenSession for long-running promise-token exchange#1843
byteclimber wants to merge 1 commit into
mainfrom
worktree-agent-a8870dd395f19c637

Conversation

@byteclimber

Copy link
Copy Markdown
Contributor

Summary

  • Adds PromiseTokenSession to @adobe/spacecat-shared-ims-client, wrapping a CONSUMER-type ImsPromiseClient so 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).
  • Adds a typed 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.
  • Exposes isExpired() / getRemainingMs() for TTL checks against the rolled promise token, and an idempotent invalidate().

Context

This is Phase 1 of implementing adobe/serenity-docs#33 (async prompt classification pipeline): a future SQS-triggered worker in spacecat-api-service needs to exchange a promise token carried through the queue, potentially more than once if the job outlives one ~5-minute access token. ImsPromiseClient.exchangeToken already 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 existing ImsPromiseClient API or its consumers.

Test plan

  • npm test in packages/spacecat-shared-ims-client — 109/109 passing, 100% line/statement/function coverage on new files
  • npm run lint — clean
  • New unit tests cover: multi-exchange token rolling, encryption pass-through, NeedsReauthError on 401/403, non-reauth error rethrow, TTL expiry tracking, idempotent and failing invalidate()

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant