@progress/sitefinity-webservices-sdk 0.3.1 → 1.0.0

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 +1141 -1737
  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 +64 -82
  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 +92 -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/version.txt +1 -1
  139. package/config/html.conf.json +0 -5
  140. package/dist/docs/assets/css/main.css +0 -865
  141. package/dist/docs/assets/css/main.css.map +0 -7
  142. package/dist/docs/assets/images/icons.png +0 -0
  143. package/dist/docs/assets/images/icons@2x.png +0 -0
  144. package/dist/docs/assets/js/main.js +0 -5
  145. package/dist/docs/assets/js/search.js +0 -3
  146. package/dist/docs/classes/_authentication_.authentication.html +0 -527
  147. package/dist/docs/classes/_blobbuilder_.blobbuilder.html +0 -351
  148. package/dist/docs/classes/_data_.data.html +0 -974
  149. package/dist/docs/classes/_expression_.binaryexpression.html +0 -450
  150. package/dist/docs/classes/_expression_.complexexpression.html +0 -374
  151. package/dist/docs/classes/_expression_.expressionbase.html +0 -336
  152. package/dist/docs/classes/_orderproperty_.orderproperty.html +0 -381
  153. package/dist/docs/classes/_query_.query.html +0 -896
  154. package/dist/docs/classes/_querybase_.querybase.html +0 -518
  155. package/dist/docs/classes/_querybuilder_.querybuilder.html +0 -496
  156. package/dist/docs/classes/_requests_batchrequest_.batchrequest.html +0 -1511
  157. package/dist/docs/classes/_requests_batchrequest_.transaction.html +0 -804
  158. package/dist/docs/classes/_requests_executablerequest_.executablerequest.html +0 -549
  159. package/dist/docs/classes/_requests_request_.createrelatedrequest.html +0 -689
  160. package/dist/docs/classes/_requests_request_.createrequest.html +0 -680
  161. package/dist/docs/classes/_requests_request_.deleterelatedbyidrequest.html +0 -687
  162. package/dist/docs/classes/_requests_request_.deleterelatedrequest.html +0 -673
  163. package/dist/docs/classes/_requests_request_.deleterequest.html +0 -666
  164. package/dist/docs/classes/_requests_request_.getbyidrequest.html +0 -666
  165. package/dist/docs/classes/_requests_request_.getrelatedbyidrequest.html +0 -687
  166. package/dist/docs/classes/_requests_request_.getrelatedrequest.html +0 -673
  167. package/dist/docs/classes/_requests_request_.getrequest.html +0 -658
  168. package/dist/docs/classes/_requests_request_.requestbase.html +0 -687
  169. package/dist/docs/classes/_requests_request_.updaterequest.html +0 -686
  170. package/dist/docs/classes/_requests_request_.uploadrequest.html +0 -715
  171. package/dist/docs/classes/_requests_requestfactory_.requestfactory.html +0 -724
  172. package/dist/docs/classes/_sitefinity_.sitefinity.html +0 -521
  173. package/dist/docs/classes/_utils_.utils.html +0 -597
  174. package/dist/docs/classes/_wherequery_.wherequery.html +0 -992
  175. package/dist/docs/globals.html +0 -238
  176. package/dist/docs/modules/_authentication_.html +0 -225
  177. package/dist/docs/modules/_blobbuilder_.html +0 -225
  178. package/dist/docs/modules/_constants_.html +0 -528
  179. package/dist/docs/modules/_contenttypes_.html +0 -248
  180. package/dist/docs/modules/_data_.html +0 -225
  181. package/dist/docs/modules/_expression_.html +0 -233
  182. package/dist/docs/modules/_headers_.html +0 -328
  183. package/dist/docs/modules/_httpmethods_.html +0 -288
  184. package/dist/docs/modules/_main_.html +0 -209
  185. package/dist/docs/modules/_orderproperty_.html +0 -225
  186. package/dist/docs/modules/_query_.html +0 -225
  187. package/dist/docs/modules/_querybase_.html +0 -225
  188. package/dist/docs/modules/_querybuilder_.html +0 -247
  189. package/dist/docs/modules/_requests_batchrequest_.html +0 -265
  190. package/dist/docs/modules/_requests_executablerequest_.html +0 -296
  191. package/dist/docs/modules/_requests_request_.html +0 -333
  192. package/dist/docs/modules/_requests_requestfactory_.html +0 -247
  193. package/dist/docs/modules/_sitefinity_.html +0 -225
  194. package/dist/docs/modules/_utils_.html +0 -225
  195. package/dist/docs/modules/_wherequery_.html +0 -247
  196. package/dist/index.html +0 -474
  197. package/src/Authentication.ts +0 -96
  198. package/src/ContentTypes.ts +0 -5
  199. package/src/Headers.ts +0 -12
  200. package/src/HttpMethods.ts +0 -9
  201. package/src/main.ts +0 -2
@@ -0,0 +1,418 @@
1
+ import { SF_PARAMS, HEADER_NAMES } from "./constants";
2
+ import { ResponseHandlers } from "./Requests/ExecutableRequest";
3
+ import { Sitefinity } from "./Sitefinity";
4
+
5
+ describe("Base SDK tests", () => {
6
+ const baseUrl = "http://www.mysite.com/api/default/";
7
+ const batchResponse = `--batchresponse_ab4d3fab-5bee-4ea0-ba40-723ea40d1c32\r
8
+ Content-Type: application/http\r
9
+ Content-Transfer-Encoding: binary\r
10
+ \r
11
+ HTTP/1.1 200 OK\r
12
+ Cache-Control: no-store, must-revalidate, no-cache\r
13
+ Access-Control-Allow-Origin: *\r
14
+ Content-Type: text/plain\r
15
+ OData-Version: 4.0\r
16
+ \r
17
+ 1\r
18
+ --batchresponse_ab4d3fab-5bee-4ea0-ba40-723ea40d1c32--\r
19
+ `;
20
+ let sitefinity: Sitefinity;
21
+
22
+ beforeEach(() => {
23
+ jasmine.Ajax.install();
24
+ });
25
+
26
+ afterEach(() => {
27
+ jasmine.Ajax.uninstall();
28
+ });
29
+
30
+ beforeAll(() => {
31
+ sitefinity = new Sitefinity({
32
+ baseUrl
33
+ });
34
+ });
35
+
36
+ describe("SDK options tests", () => {
37
+ it("Verify baseUrl from SDK options", () => {
38
+ const url = "http://www.mysite.com/api/default/v2/";
39
+ const sdk = new Sitefinity({
40
+ baseUrl: url
41
+ });
42
+ sdk.data({}).get({});
43
+
44
+ const request = jasmine.Ajax.requests.mostRecent();
45
+ expect(request.url).toBe(url);
46
+ });
47
+
48
+ it("Verify siteId from SDK options", () => {
49
+ const siteId = "mySiteId";
50
+ const sdk = new Sitefinity({
51
+ baseUrl: "http://www.mysite.com/api/default/v2/",
52
+ siteId: siteId
53
+ });
54
+ sdk.data({}).get({});
55
+
56
+ const request = jasmine.Ajax.requests.mostRecent();
57
+ expect(request.url).toContain(`${SF_PARAMS.siteId}=${siteId}`);
58
+ });
59
+
60
+ it("Verify enableUnlimitedChoices from SDK options", () => {
61
+ let sdk = new Sitefinity({
62
+ baseUrl: "http://www.mysite.com/api/default/v2/",
63
+ enableUnlimitedChoices: true
64
+ });
65
+ sdk.data({}).get({});
66
+
67
+ let request = jasmine.Ajax.requests.mostRecent();
68
+ expect(request.requestHeaders[HEADER_NAMES.choicesBinaryRepresentation]).toBe("true");
69
+
70
+ sdk = new Sitefinity({
71
+ baseUrl: "http://www.mysite.com/api/default/v2/",
72
+ enableUnlimitedChoices: false
73
+ })
74
+ sdk.data({}).get({});
75
+
76
+ request = jasmine.Ajax.requests.mostRecent();
77
+ expect(request.requestHeaders[HEADER_NAMES.choicesBinaryRepresentation]).toBeUndefined();
78
+ });
79
+
80
+ it("Verify integrationMode from SDK options", () => {
81
+ let sdk = new Sitefinity({
82
+ baseUrl: "http://www.mysite.com/api/default/v2/",
83
+ integrationMode: true
84
+ });
85
+ sdk.data({}).get({});
86
+
87
+ let request = jasmine.Ajax.requests.mostRecent();
88
+ expect(request.requestHeaders[HEADER_NAMES.integrationMode]).toBe("true");
89
+
90
+ sdk = new Sitefinity({
91
+ baseUrl: "http://www.mysite.com/api/default/v2/",
92
+ integrationMode: false
93
+ })
94
+ sdk.data({}).get({});
95
+
96
+ request = jasmine.Ajax.requests.mostRecent();
97
+ expect(request.requestHeaders[HEADER_NAMES.integrationMode]).toBeUndefined();
98
+ });
99
+
100
+ it("Verify global success handler from SDK options", () => {
101
+ const handlers: ResponseHandlers = {
102
+ successCb: () => {},
103
+ failureCb: () => {}
104
+ };
105
+ const successSpy = spyOn<ResponseHandlers, any>(handlers, "successCb");
106
+ const failureSpy = spyOn<ResponseHandlers, any>(handlers, "failureCb");
107
+
108
+ const sdk = new Sitefinity({
109
+ baseUrl: "http://www.mysite.com/api/default/v2/",
110
+ handlers
111
+ });
112
+ sdk.data({}).get({});
113
+
114
+ const request = jasmine.Ajax.requests.mostRecent();
115
+ request.respondWith({
116
+ status: 200,
117
+ responseText: '{"message":"test"}'
118
+ });
119
+
120
+ expect(successSpy).toHaveBeenCalledOnceWith({ message: "test" });
121
+ expect(failureSpy).not.toHaveBeenCalled();
122
+ });
123
+
124
+ it("Verify global failure handler from SDK options", () => {
125
+ const handlers: ResponseHandlers = {
126
+ successCb: () => {},
127
+ failureCb: () => {}
128
+ };
129
+ const successSpy = spyOn<ResponseHandlers, any>(handlers, "successCb");
130
+ const failureSpy = spyOn<ResponseHandlers, any>(handlers, "failureCb");
131
+
132
+ const sdk = new Sitefinity({
133
+ baseUrl: "http://www.mysite.com/api/default/v2/",
134
+ handlers
135
+ });
136
+ sdk.data({}).get({});
137
+
138
+ const request = jasmine.Ajax.requests.mostRecent();
139
+ request.respondWith({
140
+ status: 400,
141
+ responseText: '{"message":"test"}'
142
+ });
143
+
144
+ expect(failureSpy).toHaveBeenCalledOnceWith({ message: "test", status: 400 });
145
+ expect(successSpy).not.toHaveBeenCalled();
146
+ });
147
+
148
+ it("Verify token", () => {
149
+ const sdk = new Sitefinity({
150
+ baseUrl: "http://www.mysite.com/api/default/v2/"
151
+ });
152
+ sdk.data({}).get({});
153
+
154
+ let request = jasmine.Ajax.requests.mostRecent();
155
+ expect(request.requestHeaders[HEADER_NAMES.authorization]).toBeUndefined();
156
+
157
+ sdk.setToken({
158
+ type: "Bearer",
159
+ value: "123"
160
+ });
161
+ sdk.data({}).get({});
162
+
163
+ request = jasmine.Ajax.requests.mostRecent();
164
+ expect(request.requestHeaders[HEADER_NAMES.authorization]).toBe("Bearer 123");
165
+ });
166
+ });
167
+
168
+ describe("Type options tests", () => {
169
+ describe("for data()", () => {
170
+ it("Verify baseUrl is appended trailing slash", () => {
171
+ const url = "http://www.mysite.com/api/default/v2";
172
+ sitefinity.data({
173
+ baseUrl: url
174
+ }).get({});
175
+
176
+ let request = jasmine.Ajax.requests.mostRecent();
177
+ expect(request.url).toBe(`${url}/`);
178
+
179
+ const sdk = new Sitefinity({
180
+ baseUrl: url
181
+ });
182
+ sdk.data({}).get({});
183
+
184
+ request = jasmine.Ajax.requests.mostRecent();
185
+ expect(request.url).toBe(`${url}/`);
186
+ });
187
+
188
+ it("Verify baseUrl from type options overrides baseUrl from SDK options", () => {
189
+ const url = "http://www.mysite.com/api/default/v2/";
190
+ sitefinity.data({
191
+ baseUrl: url
192
+ }).get({});
193
+
194
+ const request = jasmine.Ajax.requests.mostRecent();
195
+ expect(request.url).toBe(url);
196
+ });
197
+
198
+ it("Verify siteId from type options overrides siteId from SDK options", () => {
199
+ const siteId = "mySiteId";
200
+ const sdk = new Sitefinity({
201
+ baseUrl: "http://www.mysite.com/api/default/v2/",
202
+ siteId: "test"
203
+ });
204
+ sdk.data({
205
+ siteId
206
+ }).get({});
207
+
208
+ const request = jasmine.Ajax.requests.mostRecent();
209
+ expect(request.url).toContain(`${SF_PARAMS.siteId}=${siteId}`);
210
+ });
211
+
212
+ it("Verify entitySet from type options", () => {
213
+ const entitySet = "newsitems";
214
+
215
+ sitefinity.data({
216
+ entitySet
217
+ }).get({});
218
+
219
+ const request = jasmine.Ajax.requests.mostRecent();
220
+ expect(request.url).toBe(`${baseUrl}${entitySet}`);
221
+ });
222
+
223
+ it("Verify provider from type options", () => {
224
+ const provider = "myProvider";
225
+
226
+ sitefinity.data({
227
+ provider
228
+ }).get({});
229
+
230
+ const request = jasmine.Ajax.requests.mostRecent();
231
+ expect(request.url).toContain(`${SF_PARAMS.provider}=${provider}`);
232
+ });
233
+
234
+ it("Verify culture from type options", () => {
235
+ const culture = "en";
236
+
237
+ sitefinity.data({
238
+ culture
239
+ }).get({});
240
+
241
+ const request = jasmine.Ajax.requests.mostRecent();
242
+ expect(request.url).toContain(`${SF_PARAMS.culture}=${culture}`);
243
+ });
244
+
245
+ it("Verify additional query params from type options", () => {
246
+ const additionalQueryParams = {
247
+ "p1": "test1",
248
+ "p2": "123",
249
+ };
250
+
251
+ sitefinity.data({
252
+ additionalQueryParams
253
+ }).get({});
254
+
255
+ const request = jasmine.Ajax.requests.mostRecent();
256
+ expect(request.url).toContain(`p1=test1&p2=123`);
257
+ });
258
+ });
259
+
260
+ describe("for batch", () => {
261
+ it("Verify baseUrl is appended trailing slash", () => {
262
+ const url = "http://www.mysite.com/api/default/v2";
263
+ sitefinity.batch(undefined, undefined, undefined, {
264
+ baseUrl: url
265
+ }).execute();
266
+
267
+ let request = jasmine.Ajax.requests.mostRecent();
268
+ expect(request.url).toBe(`${url}/$batch`);
269
+
270
+ const sdk = new Sitefinity({
271
+ baseUrl: url
272
+ });
273
+ sdk.batch().execute();
274
+
275
+ request = jasmine.Ajax.requests.mostRecent();
276
+ expect(request.url).toBe(`${url}/$batch`);
277
+ });
278
+
279
+ it("Verify baseUrl from type options overrides baseUrl from SDK options", () => {
280
+ const url = "http://www.mysite.com/api/default/v2/";
281
+ sitefinity.batch(undefined, undefined, undefined, {
282
+ baseUrl: url
283
+ }).execute();
284
+
285
+ const request = jasmine.Ajax.requests.mostRecent();
286
+ expect(request.url).toBe(`${url}$batch`);
287
+ });
288
+
289
+ it("Verify siteId from type options overrides siteId from SDK options", () => {
290
+ const siteId = "mySiteId";
291
+ const sdk = new Sitefinity({
292
+ baseUrl: "http://www.mysite.com/api/default/v2/",
293
+ siteId: "test"
294
+ });
295
+ sdk.batch(undefined, undefined, undefined, {
296
+ siteId
297
+ }).execute();
298
+
299
+ const request = jasmine.Ajax.requests.mostRecent();
300
+ expect(request.url).toContain(`${SF_PARAMS.siteId}=${siteId}`);
301
+ });
302
+
303
+ it("Verify provider from type options", () => {
304
+ const provider = "myProvider";
305
+
306
+ sitefinity.batch(undefined, undefined, undefined, {
307
+ provider
308
+ }).execute();
309
+
310
+ const request = jasmine.Ajax.requests.mostRecent();
311
+ expect(request.url).toContain(`${SF_PARAMS.provider}=${provider}`);
312
+ });
313
+
314
+ it("Verify culture from type options", () => {
315
+ const culture = "en";
316
+
317
+ sitefinity.batch(undefined, undefined, undefined, {
318
+ culture
319
+ }).execute();
320
+
321
+ const request = jasmine.Ajax.requests.mostRecent();
322
+ expect(request.url).toContain(`${SF_PARAMS.culture}=${culture}`);
323
+ });
324
+
325
+ it("Verify additional query params from type options", () => {
326
+ const additionalQueryParams = {
327
+ "p1": "test1",
328
+ "p2": "123",
329
+ };
330
+
331
+ sitefinity.batch(undefined, undefined, undefined, {
332
+ additionalQueryParams
333
+ }).execute();
334
+
335
+ const request = jasmine.Ajax.requests.mostRecent();
336
+ expect(request.url).toContain(`p1=test1&p2=123`);
337
+ });
338
+
339
+ it("Verify successCb overrides global success handler from SDK options", () => {
340
+ const globalHandlers: ResponseHandlers = {
341
+ successCb: () => {},
342
+ failureCb: () => {}
343
+ };
344
+ const successSpyGlobal = spyOn<ResponseHandlers, any>(globalHandlers, "successCb");
345
+ const failureSpyGlobal = spyOn<ResponseHandlers, any>(globalHandlers, "failureCb");
346
+
347
+ const localHandlers = {
348
+ successCb: () => {},
349
+ failureCb: () => {}
350
+ };
351
+ const successSpyLocal = spyOn<ResponseHandlers, any>(localHandlers, "successCb");
352
+ const failureSpyLocal = spyOn<ResponseHandlers, any>(localHandlers, "failureCb");
353
+
354
+ const sdk = new Sitefinity({
355
+ baseUrl: "http://www.mysite.com/api/default/v2/",
356
+ handlers: globalHandlers
357
+ });
358
+ sdk.batch(localHandlers.successCb, localHandlers.failureCb).execute();
359
+
360
+ const request = jasmine.Ajax.requests.mostRecent();
361
+ request.respondWith({
362
+ status: 200,
363
+ responseText: batchResponse,
364
+ responseHeaders: {
365
+ "Access-Control-Allow-Origin": "*",
366
+ "Cache-Control:": "no-cache",
367
+ "Content-Length": "334",
368
+ "Content-type": "multipart/mixed; boundary=batchresponse_ab4d3fab-5bee-4ea0-ba40-723ea40d1c32"
369
+ }
370
+ });
371
+
372
+ expect(successSpyLocal).toHaveBeenCalledTimes(1);
373
+ expect(failureSpyLocal).not.toHaveBeenCalled();
374
+ expect(successSpyGlobal).not.toHaveBeenCalled();
375
+ expect(failureSpyGlobal).not.toHaveBeenCalled();
376
+ });
377
+
378
+ it("Verify failureCb overrides global failure handler from SDK options", () => {
379
+ const globalHandlers: ResponseHandlers = {
380
+ successCb: () => {},
381
+ failureCb: () => {}
382
+ };
383
+ const successSpyGlobal = spyOn<ResponseHandlers, any>(globalHandlers, "successCb");
384
+ const failureSpyGlobal = spyOn<ResponseHandlers, any>(globalHandlers, "failureCb");
385
+
386
+ const localHandlers = {
387
+ successCb: () => {},
388
+ failureCb: () => {}
389
+ };
390
+ const successSpyLocal = spyOn<ResponseHandlers, any>(localHandlers, "successCb");
391
+ const failureSpyLocal = spyOn<ResponseHandlers, any>(localHandlers, "failureCb");
392
+
393
+ const sdk = new Sitefinity({
394
+ baseUrl: "http://www.mysite.com/api/default/v2/",
395
+ handlers: globalHandlers
396
+ });
397
+ sdk.batch(localHandlers.successCb, localHandlers.failureCb).execute();
398
+
399
+ const request = jasmine.Ajax.requests.mostRecent();
400
+ request.respondWith({
401
+ status: 400,
402
+ responseText: batchResponse,
403
+ responseHeaders: {
404
+ "Access-Control-Allow-Origin": "*",
405
+ "Cache-Control:": "no-cache",
406
+ "Content-Length": "334",
407
+ "Content-type": "multipart/mixed; boundary=batchresponse_ab4d3fab-5bee-4ea0-ba40-723ea40d1c32"
408
+ }
409
+ });
410
+
411
+ expect(failureSpyLocal).toHaveBeenCalledTimes(1);
412
+ expect(successSpyLocal).not.toHaveBeenCalled();
413
+ expect(successSpyGlobal).not.toHaveBeenCalled();
414
+ expect(failureSpyGlobal).not.toHaveBeenCalled();
415
+ });
416
+ });
417
+ });
418
+ });
package/src/Sitefinity.ts CHANGED
@@ -1,183 +1,114 @@
1
1
  import { RequestFactory } from './Requests/RequestFactory';
2
- import { Authentication } from './Authentication';
3
2
  import { Data } from './Data';
4
3
  import { Query } from './Query';
5
4
  import { utils } from './utils';
5
+ import { ResponseHandlers } from "./Requests/ExecutableRequest";
6
+ import { BatchRequest } from "./Requests/BatchRequest";
6
7
 
7
- /**
8
- * @class Sitefinity
9
- * @classdesc The constructor of the Sitefinity JavaScript SDK. This is the entry point for the SDK.
10
- * @property {Object} authentication - The authentication object used for authenticating to Sitefinity. See {@link Authentication}
11
- * @param {object} options - An object containing configuration options for the Setup object.
12
- * @param {string} options.serviceUrl - Your service url that points to the configured instance of Sitefinity service.
13
- * @param {string} options.siteId - The ID of the site, for which the query will be executed.
14
- * @param {string} options.handlers - The global handlers for request execution
15
- * @param {string} options.handlers.successCb - The success handler.
16
- * @param {string} options.handlers.failureCb - The failure handler.
17
- */
18
8
  export class Sitefinity {
9
+ public static Query: typeof Query = Query;
10
+
19
11
  private factory: RequestFactory;
20
- private authentication: Authentication;
21
- private profileUrl: string;
12
+ private baseUrl: string;
22
13
  private siteId: string;
23
- public static Query: typeof Query = Query;
24
14
 
25
- constructor(options: any) {
26
- this.profileUrl = utils.addTrailingSlash(options.serviceUrl);
15
+ /**
16
+ * The constructor of the Sitefinity JavaScript SDK. This is the entry point for the SDK.
17
+ */
18
+ constructor(options: SDKOptions) {
19
+ this.baseUrl = options.baseUrl;
27
20
  this.siteId = options.siteId;
28
- this.factory = new RequestFactory({
29
- handlers: options.handlers,
30
- enableUnlimitedChoices: options.enableUnlimitedChoices,
31
- integrationMode: options.integrationMode
32
- });
33
-
34
- this.authentication = new Authentication({
35
- serviceUrl: this.profileUrl,
36
- factory: this.factory
37
- });
21
+ this.factory = new RequestFactory(options);
38
22
  }
39
23
 
40
- /**
41
- * Creates a new {@link Data} class.
42
- * @memberOf Sitefinity
43
- * @instance
44
- * @param {object} options - An object containing configuration options for the Setup object.
45
- * @param {string} options.urlName - The URL name of the type..
46
- * @param {string} [options.providerName] - The name of the provider. If empty the default provider for the site will be used.
47
- * @param {string} [options.cultureName] - The name of the culture. If empty the default culture for the site will be used.
48
- * @example
49
- * var data = sf.data({
50
- * urlName: "newsitems",
51
- * providerName: "OpenAccessDataProvider",
52
- * cultureName: "en"
53
- * });
54
- * @returns {Data}
55
- */
56
- data(options: any) {
57
- var optionsServiceUrl = options.serviceUrl ? utils.addTrailingSlash(options.serviceUrl) : options.serviceUrl;
58
- var dataOptions = {
59
- baseUrl: optionsServiceUrl || this.profileUrl,
60
- SFParams: {
61
- provider: options.providerName,
62
- culture: options.cultureName,
63
- siteId: options.siteId || this.siteId
64
- },
24
+ data(options: TypeOptions): Data {
25
+ const urlOptions: TypeOptions = {
26
+ baseUrl: utils.addTrailingSlash(options.baseUrl || this.baseUrl),
27
+ provider: options.provider,
28
+ culture: options.culture,
29
+ siteId: options.siteId || this.siteId,
65
30
  additionalQueryParams: options.additionalQueryParams,
66
- entitySet: options.urlName
31
+ entitySet: options.entitySet
67
32
  }
68
33
 
69
- this.factory.token = this.authentication.getToken();
70
- return new Data(dataOptions, this.factory);
34
+ return new Data(urlOptions, this.factory);
71
35
  }
72
36
 
73
- /**
74
- * Creates a new {@link BatchRequest} class. OData batch requests -> {@link http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Toc372793748}
75
- * @memberOf Sitefinity
76
- * @instance
77
- * @param {Function} success - The success callback of the batch execution.
78
- * @param {string} options.urlName - The URL name of the type..
79
- * @param {string} [options.providerName] - The name of the provider. If empty the default provider for the site will be used.
80
- * @param {string} [options.cultureName] - The name of the culture. If empty the default culture for the site will be used.
81
- * @example
82
- * var sf = new Sitefinity({
83
- * serviceUrl: 'http://mydomain/route/service/'
84
- * });
85
- *
86
- * var batch = sf.batch(successCbBatch, failureCb);
87
- * batch.get({
88
- * entitySet: entitySet,
89
- * query: query8
90
- * });
91
- *
92
- * var transaction = batch.beginTransaction();
93
- * var createId = transaction.create({
94
- * entitySet: entitySet,
95
- * data: newsItem
96
- * });
97
- *
98
- * batch.endTransaction(transaction);
99
- *
100
- * var transaction2 = batch.beginTransaction();
101
- * var createId2 = transaction2.create({
102
- * entitySet: entitySet,
103
- * data: newsItem
104
- * });
105
- *
106
- * var updateId2 = transaction2.update({
107
- * entitySet: entitySet,
108
- * key: createId2,
109
- * data: newsItemUpdate
110
- * });
111
- *
112
- * batch.endTransaction(transaction2);
113
- *
114
- * batch.get({
115
- * entitySet: entitySet
116
- * });
117
- *
118
- * batch.execute();
119
- * @returns {BatchRequest}
120
- */
121
- batch(success: any, failure: any, progress: any, options: any) {
122
- if (typeof progress !== 'function') {
123
- options = progress;
124
- progress = null;
125
- }
126
-
37
+ batch(success?: Function, failure?: Function, progress?: Function, options?: TypeOptions): BatchRequest {
127
38
  if (!options)
128
39
  options = {};
129
40
 
130
- this.factory.token = this.authentication.getToken();
131
-
132
- var optionsServiceUrl = options.serviceUrl ? utils.addTrailingSlash(options.serviceUrl) : options.serviceUrl;
133
- var batch = this.factory.batch({
41
+ const batch = this.factory.batch({
134
42
  successCb: success,
135
43
  failureCb: failure,
136
44
  progressCb: progress,
137
45
  urlOptions: {
138
- baseUrl: optionsServiceUrl || this.profileUrl,
139
- SFParams: {
140
- provider: options.providerName,
141
- culture: options.cultureName,
142
- siteId: options.siteId || this.siteId
143
- },
46
+ baseUrl: utils.addTrailingSlash(options.baseUrl || this.baseUrl),
47
+ provider: options.provider,
48
+ culture: options.culture,
49
+ siteId: options.siteId || this.siteId,
144
50
  additionalQueryParams: options.additionalQueryParams
145
51
  }
146
52
  });
147
53
 
148
- var executor: any = this.factory.createExecutor(batch);
149
- executor.beginTransaction = () => {
150
- return batch.beginTransaction();
151
- }
54
+ return batch;
55
+ }
152
56
 
153
- executor.endTransaction = (transaction) => {
154
- batch.endTransaction(transaction);
155
- }
57
+ /**
58
+ * Sets the authentication token.
59
+ */
60
+ setToken(token: Token) {
61
+ this.factory.token = token;
62
+ }
63
+ }
156
64
 
157
- executor.get = (options) => {
158
- batch.constructor.prototype.get.call(batch, options);
159
- }
65
+ interface OptionsBase {
66
+ /**
67
+ * Your service url that points to the configured instance of Sitefinity service.
68
+ */
69
+ baseUrl?: string;
160
70
 
161
- executor.getOperations = (options) => {
162
- batch.constructor.prototype.getOperations.call(batch, options);
163
- }
71
+ /**
72
+ * The ID of the site, for which the queries will be executed.
73
+ */
74
+ siteId?: string;
75
+ }
164
76
 
165
- executor.getSingle = (options) => {
166
- batch.constructor.prototype.getSingle.call(batch, options);
167
- }
77
+ /**
78
+ * Defines an object containing configuration options for the SDK object.
79
+ */
80
+ export interface SDKOptions extends OptionsBase {
81
+ /**
82
+ * The global handlers for request execution
83
+ */
84
+ handlers?: ResponseHandlers;
168
85
 
169
- executor.getProperty = (options) => {
170
- batch.constructor.prototype.getProperty.call(batch, options);
171
- }
86
+ enableUnlimitedChoices?: boolean;
87
+ integrationMode?: boolean;
88
+ }
172
89
 
173
- executor.getRelated = (options) => {
174
- batch.constructor.prototype.getRelated.call(batch, options);
175
- }
90
+ /**
91
+ * Defines an object containing configuration options related to a specific type.
92
+ */
93
+ export interface TypeOptions extends OptionsBase {
94
+ /**
95
+ * The URL name of the type.
96
+ */
97
+ entitySet?: string;
176
98
 
177
- executor.getRelatedById = (options) => {
178
- batch.constructor.prototype.getRelatedById.call(batch, options);
179
- }
99
+ /**
100
+ * The name of the provider. If empty the default provider for the site will be used.
101
+ */
102
+ provider?: string;
180
103
 
181
- return executor;
182
- }
104
+ /**
105
+ * The name of the culture. If empty the default culture for the site will be used.
106
+ */
107
+ culture?: string;
108
+ additionalQueryParams?: { [key: string]: string };
109
+ }
110
+
111
+ export interface Token {
112
+ type: string;
113
+ value: string;
183
114
  }