Skip to content

Commit 4e1a8ea

Browse files
minor changes in type declarations; adding more details to readme
1 parent 0c29000 commit 4e1a8ea

15 files changed

+154
-105
lines changed

.github/README.md

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ Both `dataApi` and `searchApi` can be omitted from a configuration. Their defaul
330330

331331
Please use [DynamicsWebApi Wiki](../../../wiki/) for an object reference. It is automatically generated and I could not find a better doc generator, pardon me for that. If you know a good ".d.ts -> .md" doc generator - let me know!
332332

333-
The following table describes all __possible__ properties that can be set in `request` object.
333+
The following table describes all __possible__ properties that can be set in `request` object. Some parameters may still be absent in a table, please refer to [DynamicsWebApi Wiki](../../../wiki/).
334334

335335
__Please note!__ Not all operaions accept all properties and if
336336
by mistake an invalid property has been specified you will receive either an error saying that the request is invalid or the response will not have expected results.
@@ -352,7 +352,8 @@ duplicateDetection | `boolean` | `create`, `update`, `upsert` | **D365 Web API v
352352
expand | `Expand[]` | `retrieve`, `retrieveMultiple`, `create`, `update`, `upsert` | An array of Expand Objects (described below the table) representing the $expand OData System Query Option value to control which related records are also returned.
353353
fetchXml | `string` | `fetch`, `fetchAll` | Property that sets FetchXML - a proprietary query language that provides capabilities to perform aggregation.
354354
fieldName | `string` | `uploadFile`, `downloadFile`, `deleteRequest` | **D365 Web API v9.1+** Use this option to specify the name of the file attribute in Dynamics 365. [More Info](https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/file-attributes)
355-
fileName | `string` | `uploadFile` | **D365 Web API v9.1+** Specifies the name of the filefilter | String | `retrieve`, `retrieveMultiple`, `retrieveAll` | Use the $filter system query option to set criteria for which entities will be returned.
355+
fileName | `string` | `uploadFile` | **D365 Web API v9.1+** Specifies the name of the file
356+
filter | String | `retrieve`, `retrieveMultiple`, `retrieveAll` | Use the $filter system query option to set criteria for which entities will be returned.
356357
functionName | `string` | `callFunction` | Name of a D365 Web Api function.
357358
headers | `Object` | All | `v2.1+` Custom headers to supply with a request. These headers will override configuraiton headers if the identical ones were set. For example: `{ "my-header": "value", "another-header": "another-value" }`.
358359
ifmatch | `string` | `retrieve`, `update`, `upsert`, `deleteRecord` | Sets If-Match header value that enables to use conditional retrieval or optimistic concurrency in applicable requests. [More Info](https://msdn.microsoft.com/en-us/library/mt607711.aspx)
@@ -373,7 +374,7 @@ pageNumber | `number` | `fetch` | Sets a page number for Fetch XML request ONLY!
373374
pagingCookie | `string` | `fetch` | Sets a paging cookie for Fetch XML request ONLY!
374375
parameters | `Object` | `callFunction` | Function's input parameters. Example: `{ param1: "test", param2: 3 }`.
375376
partitionId | `string` | `create`, `update`, `upsert`, `delete`, `retrieve`, `retrieveMultiple` | Sets a unique partition key value of a logical partition for non-relational custom entity data stored in NoSql tables of Azure heterogenous storage. [More Info](https://docs.microsoft.com/en-us/power-apps/developer/data-platform/webapi/azure-storage-partitioning)
376-
queryParams | `string[]` | `retrieveMultiple`, `retrieveAll` | Additional query parameters that either have not been implemented yet or they are [parameter aliases](https://docs.microsoft.com/en-us/power-apps/developer/data-platform/webapi/query-data-web-api#use-parameter-aliases-with-system-query-options) for "$filter" and "$orderBy". **Important!** These parameters ARE NOT URI encoded!
377+
queryParams | `string[]` | All | Custom query parameters. Can also be used to set the [parameter aliases](https://docs.microsoft.com/en-us/power-apps/developer/data-platform/webapi/query-data-web-api#use-parameter-aliases-with-system-query-options) for "$filter" and "$orderBy". **Important!** These parameters ARE NOT URI encoded!
377378
returnRepresentation | `boolean` | `create`, `update`, `upsert` | Sets Prefer header request with value "return=representation". Use this property to return just created or updated entity in a single request.
378379
savedQuery | `string` | `retrieve` | A String representing the GUID value of the saved query.
379380
select | `string[]` | `retrieve`, `retrieveMultiple`, `retrieveAll`, `update`, `upsert` | An array (of Strings) representing the $select OData System Query Option to control which attributes will be returned.
@@ -2408,7 +2409,7 @@ import { DynamicsWebApi, Config } from "dynamics-web-api";
24082409
//const DynamicsWebApi = require("dynamics-web-api");
24092410
```
24102411
2411-
### Dynamics 365 web resource
2412+
### Browsers and Dynamics 365 web resource
24122413
If you are developing CRM Web Resources with TypeScript (and are not using NPM), you can download a TypeScript declaration file `dynamics-web-api.d.ts` manually from v2 [dist](https://github.com/AleksandrRogov/DynamicsWebApi/tree/v2/dist) folder. I usually put all declarations in the "./types/" folder of my web resources project. For example:
24132414
24142415
```
@@ -2429,19 +2430,67 @@ If you are developing CRM Web Resources with TypeScript (and are not using NPM),
24292430
]
24302431
```
24312432
2432-
The declaration file is an ESM module, so if you are not using any bundler, you will have to add another d.ts file (let's call it `dynamics-web-api.browser.d.ts` and put it in the `types` folder) that will make DynamicsWebApi available globally. Here is an example (the same folder structure as mentioned above):
2433+
The declaration file is an ESM module, so if you are not using any bundler, you will have to add another d.ts file (let's call it `dynamics-web-api.umd.d.ts` and put it in the `types` folder) that will make DynamicsWebApi available globally. Here is an example (the same folder structure as mentioned above):
24332434
24342435
```ts
2435-
//dynamics-web-api.browser.d.ts
2436+
//dynamics-web-api.umd.d.ts
24362437
//import a DynamicsWebApi class from dynamics-web-api.d.ts file
2437-
import { DynamicsWebApi } from "./dynamicsWebApi"
2438+
import { DynamicsWebApi } from "./dynamics-web-api"
24382439
//make the DynamicsWebApi class available globally
24392440
export = DynamicsWebApi;
2440-
//wrap all other exports with a namespace called DynamicsWebApi
2441+
//wrap all other exports with in namespace
24412442
export as namespace DynamicsWebApi;
24422443
```
24432444
2444-
You can now access `DynamicsWebApi` anywhere in your source code without needing to import the declarations.
2445+
`DynamicsWebApi` will now be a global object.
2446+
2447+
If you need to access other types that `DynamicsWebApi` exports, you will have to create an additional `d.ts` file, unfortunately. I could not find a way to do this in a single file (mostly because of `export =` which cannot be combined with any other exports except for "as namespace"). If anyone knows a way to do that - let me know. Here's an example with a seprate file:
2448+
2449+
```ts
2450+
//dynamics-web-api.types.umd.d.ts
2451+
export type {
2452+
RetrieveMultipleRequest,
2453+
CreateRequest
2454+
/* Other exports here if needed */
2455+
} from "./dynamics-web-api";
2456+
export as namespace Dwa;
2457+
```
2458+
2459+
These types can then be used anywhere in the code the following way:
2460+
2461+
```ts
2462+
const createRequest: Dwa.CreateRequest<Account> = {
2463+
collection: "accounts",
2464+
data: {
2465+
name: "Example"
2466+
}
2467+
}
2468+
2469+
const id = await dynamicsWebApi.create(createRequest) as string;
2470+
```
2471+
2472+
**DynamicsWebApi as an external library.** For those who use bundlers, but want to keep DynamicsWebApi as an external library (meaning that you don't want to bundle the library but reference it separately in a script tag somewhere): 1. you will have to make sure that your bundler supports `externals` configuraiton. 2. you will need to set the replacement for the import of `dynamics-web-api` with `_dynamicsWebApiExports`. For example, in webpack's case, you will have something like that:
2473+
```json
2474+
{
2475+
//...your bundle configuration
2476+
"externals": {
2477+
"dynamics-web-api" : "_dynamicsWebApiExports"
2478+
}
2479+
}
2480+
```
2481+
2482+
This will work __only__ if in your scripts you import the library like this: `import { DynamicsWebApi } from "dynamics-web-api"`. In case if you don't install the package with npm but just keep the declaration files somewhere and import it with relative paths, you can set the [paths](https://www.typescriptlang.org/tsconfig#paths) option in your `tsconfig.json` which will create a consistent alias for all your relative import paths.
2483+
2484+
```json
2485+
{
2486+
"compilerOptions": {
2487+
//...your compiler options
2488+
"paths": {
2489+
"dynamics-web-api": ["./types/dynamics-web-api"]
2490+
}
2491+
}
2492+
}
2493+
```
24452494
24462495
### In Progress / Feature List
24472496

dist/browser/esm/dynamics-web-api.js

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/esm/dynamics-web-api.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/dynamics-web-api.js

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/dynamics-web-api.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)