-
Notifications
You must be signed in to change notification settings - Fork 11
/
WebApi.ts
104 lines (87 loc) · 3.81 KB
/
WebApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import * as playwright from "playwright";
import { RethrownError } from "../utils/RethrownError";
import { EnsureXrmGetter } from "./Global";
import { XrmUiTest } from "./XrmUITest";
/**
* Module for interacting with D365 Web API
*/
export class WebApi {
private _page: playwright.Page;
constructor(private xrmUiTest: XrmUiTest) {
this._page = xrmUiTest.page;
this.xrmUiTest = xrmUiTest;
}
/**
* Create a single record
*
* @param entityLogicalName Entity logical name of the record to create
* @param data JSON Object with attribute names and values
* @returns Promise which fulfills once the record has been created
*/
createRecord = async (entityLogicalName: string, data: any): Promise<Xrm.CreateResponse> => {
await EnsureXrmGetter(this._page);
return this._page.evaluate(([entityLogicalName, data]) => {
const xrm = window.oss_FindXrm();
return xrm.WebApi.createRecord(entityLogicalName, data);
}, [entityLogicalName, data]);
}
/**
* Retrieves a single record
*
* @param entityLogicalName Entity LogicalName of the record to retrieve
* @param id ID of the record to retrieve
* @param options OData system query options
* @returns Promise which fulfills with the requested record data
*/
retrieveRecord = async (entityLogicalName: string, id: string, options?: string): Promise<any> => {
await EnsureXrmGetter(this._page);
return this._page.evaluate(([entityLogicalName, id, options]) => {
const xrm = window.oss_FindXrm();
return xrm.WebApi.retrieveRecord(entityLogicalName, id, options);
}, [entityLogicalName, id, options]);
}
/**
* Retrieves multiple records
*
* @param entityLogicalName Entity logical name of the entity to retrieve
* @param options OData system query options or FetchXML query
* @param maxPageSize Specify the number of records to return per page
* @returns Promise which fulfills with the data once the retrieval succeeds
*/
retrieveMultipleRecords = async (entityLogicalName: string, options?: string, maxPageSize?: number): Promise<Xrm.RetrieveMultipleResult> => {
await EnsureXrmGetter(this._page);
return this._page.evaluate(([entityLogicalName, options, maxPageSize]) => {
const xrm = window.oss_FindXrm();
return xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize);
}, [entityLogicalName, options, maxPageSize] as [string, string?, number?]);
}
/**
* Updates a single record
*
* @param entityLogicalName Entity logical name of the record to retrieve
* @param id ID of the record to update
* @param data JSON Object with attribute names and values
* @returns Promise which fulfills once the update succeeds
*/
updateRecord = async (entityLogicalName: string, id: string, data: any): Promise<any> => {
await EnsureXrmGetter(this._page);
return this._page.evaluate(([entityLogicalName, id, data]) => {
const xrm = window.oss_FindXrm();
return xrm.WebApi.updateRecord(entityLogicalName, id, data);
}, [entityLogicalName, id, data]);
}
/**
* Delete a single record
*
* @param entityLogicalName Entity logical name of the record to retrieve
* @param id ID of the record to delete
* @returns Promise which fulfills once the deletion succeeds
*/
deleteRecord = async (entityLogicalName: string, id: string): Promise<any> => {
await EnsureXrmGetter(this._page);
return this._page.evaluate(([entityLogicalName, id]) => {
const xrm = window.oss_FindXrm();
return xrm.WebApi.deleteRecord(entityLogicalName, id);
}, [entityLogicalName, id]);
}
}