Skip to content

Add a Dataverse template generated from the Web API's CSDL metadata - #433

Merged
tnkuehne merged 3 commits into
mainfrom
dataverse-template
Nov 26, 2026
Merged

tnkuehne merged 3 commits into
mainfrom
dataverse-template

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Adds a Microsoft Dataverse template. Like the other REST templates, it exposes the vendor API's own shape: every table's rows through the Web API's entity-set operations, and each action and function of the Web API as a typed method.

Changes

  • packages/template-generator/src/csdl.ts (new): turns an OData v4 CSDL $metadata document into an OpenAPI description.
    • Rows of any table: /{entitySet} list and create, /{entitySet}({id}) get, update and delete, and $ref associate and disassociate.
    • Actions are POSTs with a JSON body. Parameters are required when they are not nullable and not optional.
    • Functions are GETs that write their arguments into the call: enum literals, unquoted numbers, GUIDs and dates, and quoted strings. Lists, objects and rows go as @alias query parameters.
    • Bound operations use their type's entity set.
    • Types: entity and complex types become schemas, enums become string enums, and propertyless base entities become any-row objects.
  • OpenAPI server variables: {variable} in a server URL becomes a required input of every method. The runtime substitutes it and accepts only a host name, so a value can never add a path, credentials or another address. Dataverse uses this for environment, because every Web API call names its environment in its address.
  • runtime/rest.ts: server variables, @alias query parameters sent as JSON, and optional OData function parameters left out of the call. Only parameters the description marks optional (optionalPathParameters) are left out. The file is copied into all REST templates; their behavior is unchanged.
  • Results: OData answers collections, primitives and enum members inside value, so those methods return { value }. Complex types keep their navigation properties, such as the principal in PrincipalAccess.
  • templates/dataverse:
    • 496 methods, among them listRows, getRow, createRow, updateRow, deleteRow, associateRows, disassociateRows, getMetadata, callAction for actions a solution adds, and the typed actions and functions such as whoAmI, addPrivilegesRole and publishXml.
    • listEnvironments reads the Global Discovery Service and returns each environment's host as methods take it.
    • Tokens are issued per environment from the account's refresh token and cached encrypted per user and environment.
    • A Dataverse 403 without an error body reports network_required with the origin to allow.
    • createRow writes only to an entity set that the environment's service document lists. OData addresses unbound actions the same way, and an action must keep its own change class.
    • Change classes: create only adds something new. Operations that also change what exists, such as granting privileges, adding team members or importing over existing customizations, are update.
  • Login: connects through the organization's own Entra application (MICROSOFT_CLIENT_ID, MICROSOFT_CLIENT_SECRET) with the delegated Dynamics CRM user_impersonation permission. Managed sign-in is not offered yet. The managed broker would have to issue a token per environment, and that will come separately.

Screenshots

New template, so there are no before images. Connected and setup, at 1280 px light and 390 px dark:

The not-connected and failed states are not shown. They use #422's layout unchanged.

Verification

  • Tests:
    • Dataverse template: 9 of 9 pass, including two environments that each get their own token, discovery and its failure, network_required, rejected tokens, a refresh that finishes after the grant changed, createRow against an action's address, and setup without OAuth.
    • Template generator: all tests pass, including new CSDL tests for operations, bound paths, function arguments and aliases, types, and server-variable validation.
    • All other REST templates pass with the updated rest.ts.
    • pnpm check is clean.
  • Live calls against a Dataverse trial environment with a custom Entra app returned 200 for whoAmI, retrieveVersion, retrieveUserPrivileges (bound), retrieveCurrentOrganization (an enum argument) and getMetadata.
  • Not checked live: creating tables and security roles, which needs the System Administrator role in the environment.

Known limits

  • $batch (multipart/mixed) is not offered.
  • getMetadata may exceed the 8 MiB response limit in environments with many Dynamics 365 apps. The trial environment's document is 6.8 MB.

Confidence Score: 5/5 · The PR appears safe to merge; the remaining token-caching issue is non-blocking.RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the remaining token-caching issue is non-blocking.

Findings

  1. P2 Parallel refreshes skip caching tokens ▶

Summary

Adds a Dataverse template with typed methods generated from CSDL metadata.

  • The generator builds typed API descriptions from OData metadata.
  • REST calls now support server variables and OData function arguments.
  • Dataverse methods can read and change rows and call Web API operations.
  • Users can connect a Microsoft account and choose a Dataverse environment.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Dataverse method] --> B[Check connection and request]
  B --> C{createRow?}
  C -->|Yes| D[Read service document]
  D --> E{Request succeeded?}
  E -->|No| F[Return recovery details]
  E -->|Yes| G[Check entity set]
  C -->|No| H[Check approval]
  G --> H
  H --> I[Send request with environment token]
  I --> J[Return data or recovery details]
Loading

Reviews (3) · Last reviewed commit: "Report blocked environments and throttli..." · Reviewed by Greptile

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs a2aa8fa Nov 26 2026, 06:35 PM

The template generator reads OData CSDL documents and turns them into OpenAPI
descriptions: rows of every table, associations, bound and unbound actions and
functions, and $metadata. OpenAPI server variables become inputs of every
method, validated as host names, so each Dataverse call names its environment.

The template connects through the organization's own Microsoft Entra
application and lists the user's environments on its page.
Comment thread templates/dataverse/src/connection.ts Resolved
Comment thread packages/template-generator/src/csdl.ts Resolved
Comment thread packages/template-generator/src/csdl.ts Resolved
Comment thread templates/dataverse/src/run.ts Resolved
Comment thread templates/dataverse/src/connection.ts Resolved
createRow writes only to entity sets the environment lists, operations that
change existing data are updates, and environment tokens are never saved for
a grant that changed meanwhile or offered again after Dataverse rejected them.
Collections and primitive results are typed inside value, complex types keep
their navigation properties, and only optional path parameters are left out.
Comment thread templates/dataverse/src/run.ts Resolved
Comment on lines +249 to +252
`INSERT INTO resource_token (userId, resource, accessToken, expiresAt)
SELECT ?, ?, ?, ? WHERE EXISTS (
SELECT 1 FROM account WHERE userId = ? AND providerId = ? AND refreshToken = ?
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Parallel refreshes skip caching tokens

Concurrent refreshes for different environments can read the same stored value. If the first batch rotates account.refreshToken, the second batch's cache insert matches nothing. That call succeeds, but its next request must contact Microsoft again, adding delay and token requests.

Guard cache writes with a stable connection version rather than a refresh token that sibling requests also rotate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this as is. The second request still gets and uses its token; only the cache write is skipped, so the next call to that environment refreshes once more. Saving it would need the condition this guard removes. The rotated refresh token from the first request stays saved, and the previous one stays valid with Microsoft.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s right. The second request still returns and uses its newly issued access token; only its cache write is skipped, so a later call to that environment refreshes again. The guard also prevents a refresh completing after disconnect/reconnect from restoring stale state. I’ll treat this as an intentional cache-efficiency tradeoff, not a correctness issue or merge blocker.

@tnkuehne
tnkuehne merged commit 5b2c46b into main Nov 26, 2026
18 checks passed
@tnkuehne
tnkuehne deleted the dataverse-template branch November 26, 2026 18:53
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