xrmfastdev-client
v0.1.0
Published
Xrm API abstraction layer with adapters for PCF, Web Resources, and local development proxy
Maintainers
Readme
xrmfastdev-client
Adapter-pattern abstraction over the Xrm / Dataverse WebApi. Write your data
access once and run it unchanged in a deployed web resource, a PCF control, or
locally against a proxy — you only swap the adapter at startup.
Part of XRM Fast Dev. Zero runtime dependencies.
Install
npm install xrmfastdev-clientUsage
import { initializeXrm, getXrm, GlobalXrmAdapter } from 'xrmfastdev-client';
// Call once at app startup
initializeXrm(new GlobalXrmAdapter());
// Use anywhere
const xrm = getXrm();
const record = await xrm.webApi.retrieveRecord('contact', contactId, '?$select=fullname');Adapters
| Adapter | Use case | Backed by |
|---------|----------|-----------|
| GlobalXrmAdapter | Deployed web resources | window.Xrm.WebApi |
| PcfXrmAdapter | PCF controls | context.webAPI |
| ProxyXrmAdapter | Local development | WebSocket → xrmfastdev |
Web resource
initializeXrm(new GlobalXrmAdapter());PCF control
public init(context: ComponentFramework.Context<IInputs>) {
initializeXrm(new PcfXrmAdapter(context));
}
public updateView(context: ComponentFramework.Context<IInputs>) {
(getXrm() as PcfXrmAdapter).updateContext(context);
}Local development
initializeXrm(new ProxyXrmAdapter({
proxyUrl: 'ws://localhost:8080',
connectTimeout: 5000, // optional, default 5000ms
requestTimeout: 30000, // optional, default 30000ms
}));Environment switch
if (import.meta.env.DEV) {
initializeXrm(new ProxyXrmAdapter({ proxyUrl: 'ws://localhost:8080' }));
} else {
initializeXrm(new GlobalXrmAdapter());
}
// Same business logic works everywhere:
const accounts = await getXrm().webApi.retrieveMultipleRecords('account', '?$top=10');API
Provider functions
initializeXrm(adapter: IXrmContext): void // set the active adapter (once)
getXrm(): IXrmContext // get it anywhere (throws if not initialized)
isXrmInitialized(): boolean // has it been set?
resetXrm(): void // clear it (mainly for tests)IXrmWebApi
retrieveRecord(entityLogicalName, id, options?): Promise<unknown>
retrieveMultipleRecords(entityLogicalName, options?, maxPageSize?): Promise<RetrieveMultipleResult>
createRecord(entityLogicalName, data): Promise<{ id: string }>
updateRecord(entityLogicalName, id, data): Promise<void>
deleteRecord(entityLogicalName, id): Promise<void>getXrm() also exposes userSettings and organizationSettings.
Entity names: Model-Driven / PCF use the singular logical name (
account); the Portal proxy path expects the plural set name (accounts).
License
MIT © Albert Halchanskyi
