Skip to content

[Py SDK] Port transformWithMapping to @common-grants/sdk; add handler-registry API #745

Closed

Description

@SnowboardTechie

Summary

Port website/src/lib/transformation.ts into lib/ts-sdk/src/extensions/transformation.ts, update the website to import from @common-grants/sdk, and expose buildTransforms() with a per-call handlers? argument as the public API in both SDKs — matching ADR-0022 Decision #8 (handlers registered per call, not globally). The Python equivalent (common_grants_sdk/utils/transformation.py) is already in the SDK but needs its public API formalized.

Acceptance criteria

  • @common-grants/sdk exports buildTransforms(toCommonMapping, fromCommonMapping, handlers?) returning { toCommon, fromCommon } and safeTransform(transform, inputs) returning { results, errors }
  • common-grants-sdk exports build_transforms(to_common_mapping, from_common_mapping, handlers=None)
  • Default handler set (field, switch) is exported and documented; Handler type is exported for custom-handler typing
  • Name collisions between user-supplied handlers and the default set raise at buildTransforms() load time (not silently shadowed)
  • Per-call handler scoping documented with an example

Related

Activity

  1. added 3 commits that reference this issue on Apr 20, 2026
  2. added a commit that references this issue on Apr 23, 2026
  3. SnowboardTechie commented on Apr 23, 2026

    @SnowboardTechie
    CollaboratorAuthor

    FYI: ADR 0022 Decision #8 in #753 was updated with one handler-registry guardrail worth noting before implementation starts.

    Handler-name lookup on the per-call handlers registry should use own-property access (Object.hasOwn in TypeScript, explicit dict in checks in Python) rather than naive handlers[name]. The reason: mergeExtensions() reconstitutes mapping JSON that can originate from untrusted extension packages, and a plain lookup could resolve inherited prototype or class-dict members like __proto__, constructor, or toString and execute them as handlers.

    No ADR changes needed here, just flagging so the lookup path gets the right shape on the first pass.

  4. jcrichlake commented on May 13, 2026

    @jcrichlake
    Collaborator

    I think some wires got crossed on this story, I don't think we want to move the websites transformation code into the SDK. The flow should be website to SDK in terms of data models etc. I think the transformation code in the website could perhaps be used a base for the typescript portion.

    That being said I think the first 2 AC can be removed

  5. changed the title [-][SDK] Port transformWithMapping to @common-grants/sdk; add handler-registry API[/-] [+][Py SDK] Port transformWithMapping to @common-grants/sdk; add handler-registry API[/+] on May 14, 2026
  6. moved this from Todo to In Progress in Simpler Grants Product & Deliveryon May 26, 2026
  7. moved this from In Progress to In Review in Simpler Grants Product & Deliveryon May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

py-sdkRelated to Python SDKpythonIssue or PR related to Python toolingsdkIssue or PR related to our SDKs

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions