Skip to content

validateAndResolveCtx: port ctx validation from go/python SDKs#330

Open
vnykmshr wants to merge 1 commit into
skyflowapi:mainfrom
vnykmshr:validate-ctx-consistency
Open

validateAndResolveCtx: port ctx validation from go/python SDKs#330
vnykmshr wants to merge 1 commit into
skyflowapi:mainfrom
vnykmshr:validate-ctx-consistency

Conversation

@vnykmshr

@vnykmshr vnykmshr commented Jul 3, 2026

Copy link
Copy Markdown

Port ValidateAndResolveCtx from the go SDK and _validate_and_resolve_ctx from the python SDK to node. The go and python SDKs validate ctx type and map-key format before embedding into JWT claims. Node currently passes ctx through as-is.

Changes:

  • src/service-account/index.ts — add validateAndResolveCtx matching go/python behavior (type-switch on string/bool/number/object, regex ^[a-zA-Z0-9_]+$ on map keys, empty/undefined = omit)
  • Wire into getToken() and getSignedTokens() claim construction
  • src/error/codes/index.tsINVALID_CTX_TYPE, INVALID_CTX_MAP_KEY
  • src/error/messages/index.ts — error messages matching existing format
  • test/service-account/token.test.js — 8 test cases covering valid/invalid/edge values

jwt.sign strips undefined values from claims, so { ctx: undefined } produces the same JWT as omitting ctx entirely — no conditional spread needed at the call site.

Go reference: v2/internal/helpers/helpers.go:ValidateAndResolveCtx
Python reference: skyflow/service_account/_utils.py:_validate_and_resolve_ctx


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