scottdurow / dataverse-ify

Easily call the Dataverse WebApi from TypeScript using SDK style types, with a NodeJS implementation for integration testing.
MIT License
58 stars 16 forks source link

Question out of curiosity: How does this compare with XrmDefinitelyTyped? #1

Closed dotfede closed 4 years ago

dotfede commented 4 years ago

What are the primary motivations for this library and what advantages/disadvantages may I find in using it, as compared to XrmDefinitelyTyped?

scottdurow commented 4 years ago

Really great question and well done for spotting this project early on before it's publicized! 😀

I've used this library in all my PCF and JS Webresources for a couple of years now - here are some of the differences to other libraries. In summary, it's not meant to compete - but rather tries to provide an interface that is closer to IOrganizationService as well as an implementation that can be used in NodeJS Integration tests (without running in the browser).

  1. Allows generation of early-bound types entity, function & action types for use in TypeScript Webresource/PCF projects - right from inside VSCode.
  2. Provides similar syntax similar to the server-side CDS/XRM SDK (e.g. IOrganizationService create, update, delete, retrieve, retreiveMultiple, execute)
  3. Deals with some of the limitations of the WebApi (e.g. not being able to null lookup fields).
  4. Deals with the complexity of calling actions/functions via the WebApi.
  5. The API is delivered as node modules that can be webpacked into your own libraries rather than loaded as externals.
  6. Runs purely on nodejs and works cross-platform.
  7. Delivered via npm - not NuGet - and so only needs VSCode.
  8. Uses On-behalf-of authentication flow - no username/password/appid needed (this is also cross-platform using node-cds-auth).
  9. Provides an implementation of Xrm.WebApi.* that can be used in NodeJS integration tests without running in the CDS browser context.
  10. Provides customisable ejs templates via cdsify-gen eject
  11. Provides a CLI for easily adding types/actions/functions to your project
  12. Doesn't attempt to provide form script typings - rather simple attribute name constants can be used. You could still use XrmDefinitelyTyped for this if you wish.

Regarding the API style - this is how you would create an account, opportunity, then win the opportunity in TypeScript running in the Form Context:

// Create account
const account1 = {
  logicalName: accountMetadata.logicalName,
  name: "Account 1",
} as Account;
account1.id = await cdsServiceClient.create(account1);

// Create opportunity
const opportunity1 = {
  logicalName: opportunityMetadata.logicalName,
  name: "Opportunity 1",
} as Opportunity;
opportunity1.customerid = Entity.toEntityReference(account1);
opportunity1.id = await cdsServiceClient.create(opportunity1);

// WinOpportunity
const winRequest = {
  logicalName: WinOpportunityMetadata.operationName,
  Status: 3,
  OpportunityClose: {
    logicalName: opportunitycloseMetadata.logicalName,
    description: "Sample Opportunity Close",
    subject: "Sample",
    opportunityid: Entity.toEntityReference(opportunity1),
  },
} as WinOpportunityRequest;
const winResponse = await cdsServiceClient.execute(winRequest);

// Get the Opportunity
const opportunityRetreived = (await cdsServiceClient.retrieve(opportunity1.logicalName, opportunity1.id, 
  "customerid",
])) as Opportunity;
console.log(opportunityRetreived.customerid?.id);

You can also use activity parties for creating activities:

letter1.regardingobjectid = Entity.toEntityReference(account1);
letter1.to = [
  {
    logicalName: "activityparty",
    partyid: Entity.toEntityReference(account1)
  } as ActivityParty
];
letter1.id = await cdsServiceClient.create(letter1);

Keep checking back in for more info on how to set up and use!

Thanks! 👍