Skip to content

Commit 9f72ccf

Browse files
fixing esm bundles; added more details to batch operations chapter of the readme
1 parent c62f48f commit 9f72ccf

File tree

14 files changed

+133
-125
lines changed

14 files changed

+133
-125
lines changed

.github/README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,14 +1113,27 @@ As mentioned before, by default, all operations that modify data: CREATE, UPDATE
11131113
11141114
In some cases this can be an undesirable behaviour and with v2 there are several ways to make those operations non-atomic: per batch operation and per request. Let's use a code sample above and make **all** operations non-atomic. It can be done by setting `inChangeSet` property to `false`.
11151115
1116+
**Important!** `contentId` can **only** be used inside the Change Sets. Any `contentId` set in a request won't be included in a non-atomic batch operation! If `$1` parameter was used outside of Change Set you will get an error similar to the following: `Error identified in Payload provided by the user for Entity :'<entity name>'`.
1117+
11161118
Per batch operation:
11171119
11181120
```ts
1121+
const contact = {
1122+
firstname: "John",
1123+
lastname: "Doe"
1124+
};
1125+
1126+
const order = {
1127+
name: "1 year membership",
1128+
//reference a request in a navigation property
1129+
//"[email protected]": "$1" <--- commented out because we don't want to get an error
1130+
};
1131+
11191132
dynamicsWebApi.startBatch();
11201133
dynamicsWebApi.create({
11211134
data: contact,
11221135
collection: "contacts",
1123-
contentId: "1",
1136+
contentId: "1", //<--- will not be used
11241137
});
11251138
dynamicsWebApi.create({
11261139
data: order,
@@ -1132,14 +1145,15 @@ const responses = await dynamicsWebApi.executeBatch({
11321145
});
11331146
```
11341147
1148+
**Important!** There seem to be a bug in Dynamics 365 Web Api (Checked: July 16, 2023) where it does not process the last operation in a batch request (Change Sets work fine). As a workaround, you can add any "GET" operation at the end to make it work, like in the following example. Please let me know if this bug was fixed.
1149+
11351150
Per request:
11361151
11371152
```ts
11381153
dynamicsWebApi.startBatch();
11391154
dynamicsWebApi.create({
11401155
data: contact,
11411156
collection: "contacts",
1142-
contentId: "1",
11431157
inChangeSet: false //<--- do not include in a change set
11441158
});
11451159
dynamicsWebApi.create({
@@ -1148,6 +1162,13 @@ dynamicsWebApi.create({
11481162
inChangeSet: false //<--- do not include in a change set
11491163
});
11501164

1165+
//this is a workaround a D365 bug (checked on July 16, 2023)
1166+
dynamicsWebApi.retrieveMutliple({
1167+
collection: "contacts",
1168+
top: 1,
1169+
select: ["firstname"]
1170+
});
1171+
11511172
const responses = await dynamicsWebApi.executeBatch();
11521173
```
11531174
@@ -1160,7 +1181,6 @@ dynamicsWebApi.startBatch();
11601181
dynamicsWebApi.create({
11611182
data: contact,
11621183
collection: "contacts",
1163-
contentId: "1",
11641184
});
11651185
dynamicsWebApi.create({
11661186
data: order,
@@ -1197,6 +1217,8 @@ dynamicsWebApi.create({
11971217
dynamicsWebApi.create({
11981218
data: order,
11991219
collection: "salesorders",
1220+
//"$1" parameter cannot be used here because it is defined in a Change Set A
1221+
//otherwise, you will get an error
12001222
});
12011223
//Change Set B ends
12021224

.github/workflows/build-test-coverage-v1.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

Lines changed: 3 additions & 5 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: 28 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dynamics-web-api.d.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ export declare class DynamicsWebApi {
315315
*/
316316
retrieveGlobalOptionSets: <T = any>(request?: RetrieveGlobalOptionSetsRequest) => Promise<RetrieveMultipleResponse<T>>;
317317
/**
318-
* Retrieves CSDL Document Metadata
318+
* Retrieves a CSDL Document Metadata
319319
* @param request - An object that represents all possible options for a current request.
320-
* @returns {Promise<string>} Unformatted and unparsed CSDL $metadata document.
320+
* @returns {Promise<string>} A raw CSDL $metadata document.
321321
*/
322322
retrieveCsdlMetadata: (request?: CsdlMetadataRequest) => Promise<string>;
323323
/**
@@ -399,6 +399,7 @@ export interface BaseRequest {
399399
inChangeSet?: boolean;
400400
}
401401
export interface BatchRequest extends BaseRequest {
402+
/** Sets Prefer header to "odata.continue-on-error" that allows more requests be processed when errors occur. The batch request will return '200 OK' and individual response errors will be returned in the batch response body. */
402403
continueOnError?: boolean;
403404
}
404405
export interface Request extends BaseRequest {
@@ -430,7 +431,7 @@ export interface FetchXmlRequest extends FetchAllRequest {
430431
pagingCookie?: string;
431432
}
432433
export interface CreateRequest<T = any> extends CRUDRequest {
433-
/**v.1.7.5+ If set to true, the request bypasses custom business logic, all synchronous plug-ins and real-time workflows are disabled. Check for special exceptions in Microsft Docs. */
434+
/**If set to true, the request bypasses custom business logic, all synchronous plug-ins and real-time workflows are disabled. Check for special exceptions in Microsft Docs. */
434435
bypassCustomPluginExecution?: boolean;
435436
/**Web API v9+ only! Boolean that enables duplicate detection. */
436437
duplicateDetection?: boolean;
@@ -450,11 +451,11 @@ export interface CreateRequest<T = any> extends CRUDRequest {
450451
returnRepresentation?: boolean;
451452
/**BATCH REQUESTS ONLY! Sets Content-ID header or references request in a Change Set. */
452453
contentId?: string;
453-
/**v.1.7.7+ A unique partition key value of a logical partition for non-relational custom entity data stored in NoSql tables of Azure heterogenous storage. */
454+
/**A unique partition key value of a logical partition for non-relational custom entity data stored in NoSql tables of Azure heterogenous storage. */
454455
partitionId?: string;
455456
}
456457
export interface UpdateRequestBase<T = any> extends CRUDRequest {
457-
/**v.1.7.5+ If set to true, the request bypasses custom business logic, all synchronous plug-ins and real-time workflows are disabled. Check for special exceptions in Microsft Docs. */
458+
/**If set to true, the request bypasses custom business logic, all synchronous plug-ins and real-time workflows are disabled. Check for special exceptions in Microsft Docs. */
458459
bypassCustomPluginExecution?: boolean;
459460
/**Web API v9+ only! Boolean that enables duplicate detection. */
460461
duplicateDetection?: boolean;
@@ -478,7 +479,7 @@ export interface UpdateRequestBase<T = any> extends CRUDRequest {
478479
navigationProperty?: string;
479480
/**A String representing navigation property's Primary Key (GUID) or Alternate Key(s). (For example, to retrieve Attribute Metadata). */
480481
navigationPropertyKey?: string;
481-
/**v.1.7.7+ A unique partition key value of a logical partition for non-relational custom entity data stored in NoSql tables of Azure heterogenous storage. */
482+
/**A unique partition key value of a logical partition for non-relational custom entity data stored in NoSql tables of Azure heterogenous storage. */
482483
partitionId?: string;
483484
}
484485
export interface UpdateRequest<T = any> extends UpdateRequestBase<T> {
@@ -508,7 +509,7 @@ export interface UpsertRequest<T = any> extends UpdateRequestBase<T> {
508509
ifnonematch?: string;
509510
}
510511
export interface DeleteRequest extends CRUDRequest {
511-
/**v.1.7.5+ If set to true, the request bypasses custom business logic, all synchronous plug-ins and real-time workflows are disabled. Check for special exceptions in Microsft Docs. */
512+
/**If set to true, the request bypasses custom business logic, all synchronous plug-ins and real-time workflows are disabled. Check for special exceptions in Microsft Docs. */
512513
bypassCustomPluginExecution?: boolean;
513514
/**Sets If-Match header value that enables to use conditional retrieval or optimistic concurrency in applicable requests.*/
514515
ifmatch?: string;
@@ -538,7 +539,7 @@ export interface RetrieveRequest extends CRUDRequest {
538539
select?: string[];
539540
/**A String representing the GUID value of the user query. */
540541
userQuery?: string;
541-
/**v.1.7.7+ A unique partition key value of a logical partition for non-relational custom entity data stored in NoSql tables of Azure heterogenous storage. */
542+
/**A unique partition key value of a logical partition for non-relational custom entity data stored in NoSql tables of Azure heterogenous storage. */
542543
partitionId?: string;
543544
}
544545
export interface RetrieveMultipleRequest extends Request {
@@ -562,9 +563,9 @@ export interface RetrieveMultipleRequest extends Request {
562563
top?: number;
563564
/**Sets Prefer header with value 'odata.track-changes' to request that a delta link be returned which can subsequently be used to retrieve entity changes. */
564565
trackChanges?: boolean;
565-
/**v.1.7.7+ A unique partition key value of a logical partition for non-relational custom entity data stored in NoSql tables of Azure heterogenous storage. */
566+
/**A unique partition key value of a logical partition for non-relational custom entity data stored in NoSql tables of Azure heterogenous storage. */
566567
partitionId?: string;
567-
/**v.1.7.7+ Additional query parameters that either have not been implemented yet or they are parameter aliases for "$filter" and "$orderBy". Important! These parameters ARE NOT URI encoded! */
568+
/**Additional query parameters that either have not been implemented yet or they are parameter aliases for "$filter" and "$orderBy". Important! These parameters ARE NOT URI encoded! */
568569
queryParams?: string[];
569570
}
570571
export interface AssociateRequest extends Request {
@@ -824,6 +825,7 @@ export interface ApiConfig {
824825
path?: string;
825826
}
826827
export interface AccessToken {
828+
/** Access Token */
827829
accessToken: string;
828830
}
829831
export interface Config {
@@ -834,7 +836,7 @@ export interface Config {
834836
/**Impersonates a user based on their Azure Active Directory (AAD) object id by passing that value along with the header "CallerObjectId". A String should represent a GUID value. */
835837
impersonateAAD?: string | null;
836838
/**A function that is called when a security token needs to be refreshed. */
837-
onTokenRefresh?: (() => Promise<AccessToken | string>) | null;
839+
onTokenRefresh?: (() => Promise<AccessToken | string | null>) | null;
838840
/**Sets Prefer header with value "odata.include-annotations=" and the specified annotation.Annotations provide additional information about lookups, options sets and other complex attribute types.*/
839841
includeAnnotations?: string | null;
840842
/**Sets the odata.maxpagesize preference value to request the number of entities returned in the response. */

dist/dynamics-web-api.js

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

0 commit comments

Comments
 (0)