@progress/sitefinity-webservices-sdk 0.3.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.js +19 -0
  3. package/ci/pipelines/ci.yml +219 -0
  4. package/config/helpers.js +0 -6
  5. package/config/webpack.common.js +1 -3
  6. package/config/webpack.dev.js +2 -9
  7. package/config/webpack.prod.js +5 -6
  8. package/dist/docs/.nojekyll +1 -0
  9. package/dist/docs/assets/highlight.css +57 -0
  10. package/dist/docs/assets/icons.css +1043 -0
  11. package/dist/docs/assets/icons.png +0 -0
  12. package/dist/docs/assets/icons@2x.png +0 -0
  13. package/dist/docs/assets/main.js +52 -0
  14. package/dist/docs/assets/search.js +1 -0
  15. package/dist/docs/assets/style.css +1413 -0
  16. package/dist/docs/assets/{images/widgets.png → widgets.png} +0 -0
  17. package/dist/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
  18. package/dist/docs/classes/BlobBuilder.BlobBuilder-1.html +7 -0
  19. package/dist/docs/classes/Data.Data-1.html +65 -0
  20. package/dist/docs/classes/Expression.BinaryExpression.html +1 -0
  21. package/dist/docs/classes/Expression.ComplexExpression.html +1 -0
  22. package/dist/docs/classes/Expression.ExpressionBase.html +1 -0
  23. package/dist/docs/classes/OrderProperty.OrderProperty-1.html +1 -0
  24. package/dist/docs/classes/Query.Query-1.html +33 -0
  25. package/dist/docs/classes/QueryBase.QueryBase-1.html +7 -0
  26. package/dist/docs/classes/QueryBuilder.QueryBuilder-1.html +1 -0
  27. package/dist/docs/classes/Requests_BatchRequest.BatchRequest.html +17 -0
  28. package/dist/docs/classes/Requests_BatchRequest.Transaction.html +17 -0
  29. package/dist/docs/classes/Requests_ExecutableRequest.ExecutableRequest.html +1 -0
  30. package/dist/docs/classes/Requests_Request.CreateRelatedRequest.html +1 -0
  31. package/dist/docs/classes/Requests_Request.CreateRequest.html +1 -0
  32. package/dist/docs/classes/Requests_Request.DeleteRelatedByIdRequest.html +1 -0
  33. package/dist/docs/classes/Requests_Request.DeleteRelatedRequest.html +1 -0
  34. package/dist/docs/classes/Requests_Request.DeleteRequest.html +1 -0
  35. package/dist/docs/classes/Requests_Request.GetByIdRequest.html +1 -0
  36. package/dist/docs/classes/Requests_Request.GetRelatedByIdRequest.html +1 -0
  37. package/dist/docs/classes/Requests_Request.GetRelatedRequest.html +1 -0
  38. package/dist/docs/classes/Requests_Request.GetRequest.html +1 -0
  39. package/dist/docs/classes/Requests_Request.UpdateRequest.html +1 -0
  40. package/dist/docs/classes/Requests_Request.UploadRequest.html +1 -0
  41. package/dist/docs/classes/Requests_RequestBase.RequestBase.html +1 -0
  42. package/dist/docs/classes/Requests_RequestFactory.RequestFactory.html +1 -0
  43. package/dist/docs/classes/Sitefinity.Sitefinity-1.html +5 -0
  44. package/dist/docs/classes/WhereQuery.WhereQuery-1.html +31 -0
  45. package/dist/docs/classes/utils.utils-1.html +1 -0
  46. package/dist/docs/index.html +54 -242
  47. package/dist/docs/interfaces/Data.CreateRelatedRequestOptions.html +1 -0
  48. package/dist/docs/interfaces/Data.CreateRequestOptions.html +1 -0
  49. package/dist/docs/interfaces/Data.OperationsRequestOptions.html +1 -0
  50. package/dist/docs/interfaces/Data.PropertyRequestOptions.html +1 -0
  51. package/dist/docs/interfaces/Data.RequestOptionsBase.html +1 -0
  52. package/dist/docs/interfaces/Data.SingleRelatedItemRequestOptions.html +1 -0
  53. package/dist/docs/interfaces/Data.UpdateRequestOptions.html +1 -0
  54. package/dist/docs/interfaces/Data.UploadRequestOptions.html +1 -0
  55. package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRelatedRequestOptions.html +1 -0
  56. package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRequestOptions.html +1 -0
  57. package/dist/docs/interfaces/Requests_BatchRequest.BatchPropertyRequestOptions.html +1 -0
  58. package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsBase.html +1 -0
  59. package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsExtended.html +1 -0
  60. package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleItemRequestOptions.html +1 -0
  61. package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleRelatedItemRequestOptions.html +1 -0
  62. package/dist/docs/interfaces/Requests_BatchRequest.BatchUpdateRequestOptions.html +1 -0
  63. package/dist/docs/interfaces/Requests_ExecutableRequest.ResponseHandlers.html +5 -0
  64. package/dist/docs/interfaces/Requests_Request.PostRequestOptionsExtended.html +1 -0
  65. package/dist/docs/interfaces/Requests_Request.PutRequestOptionsExtended.html +1 -0
  66. package/dist/docs/interfaces/Requests_Request.RelatedByIdRequestOptionsExtended.html +1 -0
  67. package/dist/docs/interfaces/Requests_Request.RelatedRequestOptionsExtended.html +1 -0
  68. package/dist/docs/interfaces/Requests_Request.UploadRequestOptionsExtended.html +1 -0
  69. package/dist/docs/interfaces/Requests_RequestBase.RequestOptionsBaseExtended.html +1 -0
  70. package/dist/docs/interfaces/Sitefinity.SDKOptions.html +9 -0
  71. package/dist/docs/interfaces/Sitefinity.Token.html +1 -0
  72. package/dist/docs/interfaces/Sitefinity.TypeOptions.html +13 -0
  73. package/dist/docs/modules/BlobBuilder.html +1 -0
  74. package/dist/docs/modules/Data.html +1 -0
  75. package/dist/docs/modules/Expression.html +1 -0
  76. package/dist/docs/modules/OrderProperty.html +1 -0
  77. package/dist/docs/modules/Query.html +1 -0
  78. package/dist/docs/modules/QueryBase.html +1 -0
  79. package/dist/docs/modules/QueryBuilder.html +1 -0
  80. package/dist/docs/modules/Requests_BatchRequest.html +1 -0
  81. package/dist/docs/modules/Requests_ExecutableRequest.html +1 -0
  82. package/dist/docs/modules/Requests_Request.html +1 -0
  83. package/dist/docs/modules/Requests_RequestBase.html +1 -0
  84. package/dist/docs/modules/Requests_RequestFactory.html +1 -0
  85. package/dist/docs/modules/Sitefinity.html +1 -0
  86. package/dist/docs/modules/WhereQuery.html +1 -0
  87. package/dist/docs/modules/constants.html +1 -0
  88. package/dist/docs/modules/utils.html +1 -0
  89. package/dist/docs/modules.html +1 -0
  90. package/dist/samples.html +33 -81
  91. package/dist/sitefinity-webservices-sdk.d.ts +16 -0
  92. package/dist/sitefinity-webservices-sdk.js +1140 -1734
  93. package/dist/sitefinity-webservices-sdk.js.map +1 -1
  94. package/dist/sitefinity-webservices-sdk.min.js +2 -16
  95. package/dist/sitefinity-webservices-sdk.min.js.LICENSE.txt +14 -0
  96. package/dist/src/BlobBuilder.d.ts +14 -0
  97. package/dist/src/Data.d.ts +144 -0
  98. package/dist/src/Expression.d.ts +19 -0
  99. package/dist/src/OrderProperty.d.ts +8 -0
  100. package/dist/src/Query.d.ts +59 -0
  101. package/dist/src/QueryBase.d.ts +18 -0
  102. package/dist/src/QueryBuilder.d.ts +13 -0
  103. package/dist/src/Requests/BatchRequest.d.ts +146 -0
  104. package/dist/src/Requests/ExecutableRequest.d.ts +20 -0
  105. package/dist/src/Requests/Request.d.ts +88 -0
  106. package/dist/src/Requests/RequestBase.d.ts +28 -0
  107. package/dist/src/Requests/RequestFactory.d.ts +22 -0
  108. package/dist/src/Sitefinity.d.ts +66 -0
  109. package/dist/src/WhereQuery.d.ts +68 -0
  110. package/dist/src/constants.d.ts +55 -0
  111. package/dist/src/utils.d.ts +16 -0
  112. package/karma.conf.js +29 -0
  113. package/package-lock.json +16108 -6805
  114. package/package.json +28 -10
  115. package/sitefinity-webservices-sdk.ts +16 -0
  116. package/src/BlobBuilder.ts +7 -12
  117. package/src/Data.spec.ts +160 -0
  118. package/src/Data.ts +132 -207
  119. package/src/Expression.ts +0 -1
  120. package/src/OrderProperty.ts +4 -5
  121. package/src/Query.ts +52 -78
  122. package/src/QueryBase.ts +21 -47
  123. package/src/QueryBuilder.ts +68 -83
  124. package/src/Requests/BatchRequest.ts +312 -335
  125. package/src/Requests/ExecutableRequest.ts +46 -73
  126. package/src/Requests/Request.ts +134 -260
  127. package/src/Requests/RequestBase.ts +161 -0
  128. package/src/Requests/RequestFactory.ts +36 -54
  129. package/src/Requests/request.spec.ts +108 -0
  130. package/src/Sitefinity.spec.ts +418 -0
  131. package/src/Sitefinity.ts +77 -146
  132. package/src/WhereQuery.ts +52 -112
  133. package/src/constants.ts +58 -39
  134. package/src/utils.ts +17 -14
  135. package/template.html +33 -35
  136. package/tsconfig.json +8 -1
  137. package/type.txt +1 -1
  138. package/config/html.conf.json +0 -5
  139. package/dist/docs/assets/css/main.css +0 -865
  140. package/dist/docs/assets/css/main.css.map +0 -7
  141. package/dist/docs/assets/images/icons.png +0 -0
  142. package/dist/docs/assets/images/icons@2x.png +0 -0
  143. package/dist/docs/assets/js/main.js +0 -5
  144. package/dist/docs/assets/js/search.js +0 -3
  145. package/dist/docs/classes/_authentication_.authentication.html +0 -527
  146. package/dist/docs/classes/_blobbuilder_.blobbuilder.html +0 -351
  147. package/dist/docs/classes/_data_.data.html +0 -974
  148. package/dist/docs/classes/_expression_.binaryexpression.html +0 -450
  149. package/dist/docs/classes/_expression_.complexexpression.html +0 -374
  150. package/dist/docs/classes/_expression_.expressionbase.html +0 -336
  151. package/dist/docs/classes/_orderproperty_.orderproperty.html +0 -381
  152. package/dist/docs/classes/_query_.query.html +0 -896
  153. package/dist/docs/classes/_querybase_.querybase.html +0 -518
  154. package/dist/docs/classes/_querybuilder_.querybuilder.html +0 -493
  155. package/dist/docs/classes/_requests_batchrequest_.batchrequest.html +0 -1511
  156. package/dist/docs/classes/_requests_batchrequest_.transaction.html +0 -804
  157. package/dist/docs/classes/_requests_executablerequest_.executablerequest.html +0 -549
  158. package/dist/docs/classes/_requests_request_.createrelatedrequest.html +0 -689
  159. package/dist/docs/classes/_requests_request_.createrequest.html +0 -680
  160. package/dist/docs/classes/_requests_request_.deleterelatedbyidrequest.html +0 -687
  161. package/dist/docs/classes/_requests_request_.deleterelatedrequest.html +0 -673
  162. package/dist/docs/classes/_requests_request_.deleterequest.html +0 -666
  163. package/dist/docs/classes/_requests_request_.getbyidrequest.html +0 -666
  164. package/dist/docs/classes/_requests_request_.getrelatedbyidrequest.html +0 -687
  165. package/dist/docs/classes/_requests_request_.getrelatedrequest.html +0 -673
  166. package/dist/docs/classes/_requests_request_.getrequest.html +0 -658
  167. package/dist/docs/classes/_requests_request_.requestbase.html +0 -687
  168. package/dist/docs/classes/_requests_request_.updaterequest.html +0 -686
  169. package/dist/docs/classes/_requests_request_.uploadrequest.html +0 -715
  170. package/dist/docs/classes/_requests_requestfactory_.requestfactory.html +0 -724
  171. package/dist/docs/classes/_sitefinity_.sitefinity.html +0 -521
  172. package/dist/docs/classes/_utils_.utils.html +0 -597
  173. package/dist/docs/classes/_wherequery_.wherequery.html +0 -992
  174. package/dist/docs/globals.html +0 -238
  175. package/dist/docs/modules/_authentication_.html +0 -225
  176. package/dist/docs/modules/_blobbuilder_.html +0 -225
  177. package/dist/docs/modules/_constants_.html +0 -528
  178. package/dist/docs/modules/_contenttypes_.html +0 -248
  179. package/dist/docs/modules/_data_.html +0 -225
  180. package/dist/docs/modules/_expression_.html +0 -233
  181. package/dist/docs/modules/_headers_.html +0 -328
  182. package/dist/docs/modules/_httpmethods_.html +0 -288
  183. package/dist/docs/modules/_main_.html +0 -209
  184. package/dist/docs/modules/_orderproperty_.html +0 -225
  185. package/dist/docs/modules/_query_.html +0 -225
  186. package/dist/docs/modules/_querybase_.html +0 -225
  187. package/dist/docs/modules/_querybuilder_.html +0 -247
  188. package/dist/docs/modules/_requests_batchrequest_.html +0 -265
  189. package/dist/docs/modules/_requests_executablerequest_.html +0 -296
  190. package/dist/docs/modules/_requests_request_.html +0 -333
  191. package/dist/docs/modules/_requests_requestfactory_.html +0 -247
  192. package/dist/docs/modules/_sitefinity_.html +0 -225
  193. package/dist/docs/modules/_utils_.html +0 -225
  194. package/dist/docs/modules/_wherequery_.html +0 -247
  195. package/dist/index.html +0 -474
  196. package/src/Authentication.ts +0 -96
  197. package/src/ContentTypes.ts +0 -5
  198. package/src/Headers.ts +0 -12
  199. package/src/HttpMethods.ts +0 -9
  200. package/src/main.ts +0 -2
  201. package/version.txt +0 -1
@@ -0,0 +1,161 @@
1
+ import { CONTENT_TYPES, HEADER_NAMES, ODATA_PARAMS, SF_PARAMS } from "../constants";
2
+ import { RequestOptionsBase } from "../Data";
3
+ import { Query } from "../Query";
4
+ import { TypeOptions } from "../Sitefinity";
5
+ import { utils } from '../utils';
6
+
7
+ export class RequestBase {
8
+ public successCb: Function;
9
+ public failureCb: Function;
10
+ public progressCb: Function;
11
+ public key: string | number;
12
+ public urlOptions: TypeOptions;
13
+ protected query: Query;
14
+ private action: string;
15
+ private fallbackProperties: string[];
16
+
17
+ constructor(options: RequestOptionsBaseExtended) {
18
+ this.successCb = options.successCb;
19
+ this.failureCb = options.failureCb;
20
+ this.urlOptions = options.urlOptions;
21
+ this.progressCb = options.progressCb;
22
+ this.key = options.key;
23
+ this.action = options.action;
24
+ this.fallbackProperties = options.fallbackProperties;
25
+ this.query = options.query;
26
+ }
27
+
28
+ getQueryString(urlOptions: TypeOptions, query: Query): string {
29
+ const paramDictionary: { [key: string]: string } = {};
30
+
31
+ this.getQueryParameters(paramDictionary, urlOptions, query);
32
+ const keys = Object.keys(paramDictionary);
33
+ if (keys.length == 0)
34
+ return null;
35
+
36
+ let queryString = "?";
37
+ for (const prop in paramDictionary) {
38
+ queryString += prop + "=" + paramDictionary[prop] + "&";
39
+ }
40
+
41
+ queryString = queryString.substring(0, queryString.length - 1);
42
+
43
+ return queryString;
44
+ }
45
+
46
+ getBody(): object {
47
+ return undefined;
48
+ }
49
+
50
+ getMethod(): string {
51
+ return null;
52
+ }
53
+
54
+ getHeaders(): { [key: string]: string } {
55
+ const headers = {};
56
+ headers[HEADER_NAMES.contentType] = CONTENT_TYPES.json;
57
+ return headers;
58
+ }
59
+
60
+ buildUrl(): string {
61
+ let url = this.urlOptions.baseUrl + (this.urlOptions.entitySet || "");
62
+ url += this.key ? ("(" + this.key + ")") : "";
63
+ if (this.action) {
64
+ url += url.endsWith("/") ? "" : "/";
65
+ url += this.action;
66
+ }
67
+
68
+ // including count here
69
+ // not the best solution as build() is called once more in getQueryString
70
+ // but not that big of an issue right now
71
+ if (this.query) {
72
+ const getCount = this.query.build().$count;
73
+
74
+ if (utils.isBoolean(getCount) && !getCount) {
75
+ url += "/$count";
76
+ }
77
+ }
78
+
79
+ return this.addQueryParameters(url);
80
+ }
81
+
82
+ protected parseResponse(http: XMLHttpRequest): string | any {
83
+ const data = utils.parseStringToJson(http.responseText);
84
+ if (data) {
85
+ if (http.status >= 400 && data.error) {
86
+ return data.error;
87
+ }
88
+
89
+ return data;
90
+ }
91
+
92
+ return http.responseText;
93
+ }
94
+
95
+ protected addQueryParameters(url: string): string {
96
+ let queryString = this.getQueryString(this.urlOptions, this.query);
97
+
98
+ if (queryString) {
99
+ if (url.indexOf("?") > -1 && queryString[0] == "?") {
100
+ queryString = "&" + queryString.substring(1);
101
+ }
102
+
103
+ url += queryString;
104
+ }
105
+
106
+ return url;
107
+ }
108
+
109
+ private getQueryParameters(paramDictionary: { [key: string]: string }, urlOptions: TypeOptions, query: Query) {
110
+ if (query) {
111
+ const builtQuery = query.build();
112
+ if (utils.isString(builtQuery.$filter))
113
+ paramDictionary[ODATA_PARAMS.$filter] = builtQuery.$filter;
114
+ if (utils.isString(builtQuery.$select))
115
+ paramDictionary[ODATA_PARAMS.$select] = builtQuery.$select;
116
+ if (utils.isString(builtQuery.$expand))
117
+ paramDictionary[ODATA_PARAMS.$expand] = builtQuery.$expand;
118
+ if (utils.isString(builtQuery.$orderby))
119
+ paramDictionary[ODATA_PARAMS.$orderby] = builtQuery.$orderby;
120
+ if (utils.isNumber(builtQuery.$skip))
121
+ paramDictionary[ODATA_PARAMS.$skip] = builtQuery.$skip;
122
+ if (utils.isNumber(builtQuery.$top))
123
+ paramDictionary[ODATA_PARAMS.$top] = builtQuery.$top;
124
+ if (utils.isString(builtQuery.$search))
125
+ paramDictionary[ODATA_PARAMS.$search] = builtQuery.$search;
126
+
127
+ // inline count
128
+ if (utils.isBoolean(builtQuery.$count) && builtQuery.$count)
129
+ paramDictionary[ODATA_PARAMS.$count] = builtQuery.$count;
130
+ }
131
+
132
+ if (urlOptions.provider) {
133
+ paramDictionary[SF_PARAMS.provider] = urlOptions.provider;
134
+ }
135
+
136
+ if (urlOptions.culture) {
137
+ paramDictionary[SF_PARAMS.culture] = urlOptions.culture;
138
+ }
139
+
140
+ if (urlOptions.siteId) {
141
+ paramDictionary[SF_PARAMS.siteId] = urlOptions.siteId;
142
+ }
143
+
144
+ if (this.fallbackProperties) {
145
+ paramDictionary[SF_PARAMS.fallbackParams] = this.fallbackProperties.join();
146
+ }
147
+
148
+ if (urlOptions.additionalQueryParams) {
149
+ for (const key in urlOptions.additionalQueryParams) {
150
+ if (urlOptions.additionalQueryParams.hasOwnProperty(key)) {
151
+ paramDictionary[key] = urlOptions.additionalQueryParams[key];
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ export interface RequestOptionsBaseExtended extends RequestOptionsBase {
159
+ progressCb?: Function;
160
+ urlOptions: TypeOptions;
161
+ }
@@ -1,85 +1,67 @@
1
- import { GetRequest, GetByIdRequest, CreateRequest, UpdateRequest, DeleteRequest, GetRelatedRequest, GetRelatedByIdRequest, DeleteRelatedRequest, DeleteRelatedByIdRequest, CreateRelatedRequest, UploadRequest } from "./Request";
2
- import { ExecutableRequest } from './ExecutableRequest';
3
-
4
- var BatchRequest = require('./BatchRequest');
1
+ import { GetRequest, GetByIdRequest, CreateRequest, UpdateRequest, DeleteRequest, GetRelatedRequest, GetRelatedByIdRequest, DeleteRelatedRequest, DeleteRelatedByIdRequest, CreateRelatedRequest, UploadRequest, PostRequestOptionsExtended, PutRequestOptionsExtended, RelatedRequestOptionsExtended, RelatedByIdRequestOptionsExtended, UploadRequestOptionsExtended } from "./Request";
2
+ import { SDKOptions, Token } from "../Sitefinity";
3
+ import { BatchRequest, BatchRequestOptionsExtended } from "./BatchRequest";
4
+ import { RequestOptionsBaseExtended } from "./RequestBase";
5
5
 
6
6
  export class RequestFactory {
7
- public token: any;
8
- private handlers: any;
9
- private enableUnlimitedChoices: boolean;
10
- private integrationMode: boolean;
11
-
12
- constructor(options: any) {
13
- this.token = null;
14
- this.handlers = options.handlers;
15
- this.enableUnlimitedChoices = options.enableUnlimitedChoices;
16
- this.integrationMode = options.integrationMode;
17
- }
7
+ public token: Token;
8
+ private options: SDKOptions;
18
9
 
19
- get(parameters: any) {
20
- return this.createExecutor(new GetRequest(parameters));
10
+ constructor(options: SDKOptions) {
11
+ this.options = options;
21
12
  }
22
13
 
23
- getSingle(parameters: any) {
24
- return this.createExecutor(new GetByIdRequest(parameters));
14
+ get(parameters: RequestOptionsBaseExtended) {
15
+ return new GetRequest(parameters, this.token, this.options);
25
16
  }
26
17
 
27
- create(parameters: any) {
28
- return this.createExecutor(new CreateRequest(parameters));
18
+ getSingle(parameters: RequestOptionsBaseExtended) {
19
+ return new GetByIdRequest(parameters, this.token, this.options);
29
20
  }
30
21
 
31
- update(parameters: any) {
32
- return this.createExecutor(new UpdateRequest(parameters));
22
+ create(parameters: PostRequestOptionsExtended) {
23
+ return new CreateRequest(parameters, this.token, this.options);
33
24
  }
34
25
 
35
- destroy(parameters: any) {
36
- return this.createExecutor(new DeleteRequest(parameters));
26
+ update(parameters: PutRequestOptionsExtended) {
27
+ return new UpdateRequest(parameters, this.token, this.options);
37
28
  }
38
29
 
39
- getProperty(parameters: any) {
40
- return this.createExecutor(new GetRelatedRequest(parameters));
30
+ destroy(parameters: RequestOptionsBaseExtended) {
31
+ return new DeleteRequest(parameters, this.token, this.options);
41
32
  }
42
33
 
43
- getRelated(parameters: any) {
44
- return this.createExecutor(new GetRelatedRequest(parameters));
34
+ getProperty(parameters: RelatedRequestOptionsExtended) {
35
+ return new GetRelatedRequest(parameters, this.token, this.options);
45
36
  }
46
37
 
47
- getRelatedById(parameters: any) {
48
- return this.createExecutor(new GetRelatedByIdRequest(parameters));
38
+ getRelated(parameters: RelatedRequestOptionsExtended) {
39
+ return new GetRelatedRequest(parameters, this.token, this.options);
49
40
  }
50
41
 
51
- destroyRelated(parameters: any) {
52
- return this.createExecutor(new DeleteRelatedRequest(parameters));
42
+ getRelatedById(parameters: RelatedByIdRequestOptionsExtended) {
43
+ return new GetRelatedByIdRequest(parameters, this.token, this.options);
53
44
  }
54
45
 
55
- destroyRelatedById(parameters: any) {
56
- return this.createExecutor(new DeleteRelatedByIdRequest(parameters));
46
+ destroyRelated(parameters: RelatedRequestOptionsExtended) {
47
+ return new DeleteRelatedRequest(parameters, this.token, this.options);
57
48
  }
58
49
 
59
- createRelated(parameters: any) {
60
- return this.createExecutor(new CreateRelatedRequest(parameters));
50
+ destroyRelatedById(parameters: RelatedByIdRequestOptionsExtended) {
51
+ return new DeleteRelatedByIdRequest(parameters, this.token, this.options);
61
52
  }
62
53
 
63
- batch(parameters) {
64
- parameters._factory = this;
65
- return new BatchRequest(parameters);
54
+ createRelated(parameters: RelatedRequestOptionsExtended) {
55
+ return new CreateRelatedRequest(parameters, this.token, this.options);
66
56
  }
67
57
 
68
- upload(parameters: any) {
69
- return this.createExecutor(new UploadRequest(parameters));
58
+ upload(parameters: UploadRequestOptionsExtended) {
59
+ return new UploadRequest(parameters, this.token, this.options);
70
60
  }
71
61
 
72
- createExecutor(request: any) {
73
- var executor = new ExecutableRequest({
74
- request: request,
75
- handlers: this.handlers || {},
76
- token: this.token,
77
- enableUnlimitedChoices: this.enableUnlimitedChoices,
78
- integrationMode: this.integrationMode
79
- });
80
-
81
- // TODO
82
- (executor as any).navigationProperty = request.navigationProperty;
83
- return executor;
62
+ batch(parameters: RequestOptionsBaseExtended) {
63
+ const batchParams = parameters as BatchRequestOptionsExtended;
64
+ batchParams.factory = this;
65
+ return new BatchRequest(batchParams, this.token, this.options);
84
66
  }
85
67
  }
@@ -0,0 +1,108 @@
1
+ import { Query } from "../Query";
2
+ import { Sitefinity } from "../Sitefinity";
3
+
4
+ describe("SDK basic tests", () => {
5
+ const baseUrl = "http://www.mysite.com/api/default/"
6
+ let sitefinity: Sitefinity;
7
+ let query: Query;
8
+
9
+ beforeEach(function() {
10
+ jasmine.Ajax.install();
11
+ });
12
+
13
+ afterEach(function() {
14
+ jasmine.Ajax.uninstall();
15
+ });
16
+
17
+ beforeAll(() => {
18
+ sitefinity = new Sitefinity({
19
+ baseUrl
20
+ });
21
+
22
+ query = new Sitefinity.Query();
23
+ });
24
+
25
+ it("query assert", () => {
26
+ const testQuery = (query.where().and().endsWith("Title", "Record").done() as any).or().startsWith('Title', 'asd').done().done();
27
+ const resultingQuery = testQuery.build();
28
+ expect(resultingQuery.$filter).toEqual("(endswith(Title, 'Record')) and (startswith(Title, 'asd'))");
29
+ });
30
+
31
+ it("complex query assert", () => {
32
+ const testQuery = query.where().not().endsWith("Record", "Title").done().and().not().eq('Content', 'test').done().done().done();
33
+ const resultingQuery = testQuery.build();
34
+ expect(resultingQuery.$filter).toEqual("(not endswith(Record, 'Title')) and ((not (Content eq 'test')))");
35
+ });
36
+
37
+ it("query count assert", () => {
38
+ const data = sitefinity.data({
39
+ entitySet: "newsitems"
40
+ });
41
+
42
+ data.get({query: query.count(false)});
43
+
44
+ let request = jasmine.Ajax.requests.mostRecent();
45
+ expect(request.url).toBe('http://www.mysite.com/api/default/newsitems/$count');
46
+
47
+ data.get({query: query.count(true)});
48
+
49
+ request = jasmine.Ajax.requests.mostRecent();
50
+ expect(request.url).toBe('http://www.mysite.com/api/default/newsitems?$count=true');
51
+ });
52
+
53
+ it("request assert", () => {
54
+ sitefinity.data({
55
+ entitySet: "newsitems",
56
+ provider: "newsProvider",
57
+ culture: "en-US"
58
+ }).get({query: null});
59
+
60
+ const request = jasmine.Ajax.requests.mostRecent();
61
+ expect(request.url).toBe('http://www.mysite.com/api/default/newsitems?sf_provider=newsProvider&sf_culture=en-US');
62
+ expect(request.method).toBe('GET');
63
+ expect(request.data()).toEqual({});
64
+ });
65
+
66
+ it("batch assert", async () => {
67
+ const batch = sitefinity.batch();
68
+ const getQuery = query.where().eq('Title', 'newTitleN11').done();
69
+
70
+ batch.get({
71
+ entitySet: "newsitems",
72
+ query: getQuery
73
+ });
74
+
75
+ const transaction = batch.beginTransaction();
76
+
77
+ transaction.create({
78
+ entitySet: "newsitems",
79
+ data: { title: "Test" }
80
+ });
81
+
82
+ batch.endTransaction(transaction);
83
+ (batch as any).execute();
84
+
85
+ const request = jasmine.Ajax.requests.mostRecent();
86
+ expect(request.url).toBe('http://www.mysite.com/api/default/$batch');
87
+ expect(request.method).toBe('POST');
88
+
89
+ await readBlobAsText(request.params).then((result) => {
90
+ expect(result).toContain("{\"title\":\"Test\"}");
91
+ });
92
+ });
93
+
94
+ function readBlobAsText(blob: Blob): Promise<string> {
95
+ return new Promise((resolve, reject) => {
96
+ const reader = new FileReader();
97
+
98
+ reader.onload = () => {
99
+ resolve(<string>reader.result);
100
+ };
101
+
102
+ reader.onerror = () => {
103
+ reject();
104
+ };
105
+ reader.readAsText(blob);
106
+ });
107
+ }
108
+ });