@progress/sitefinity-webservices-sdk 1.0.4 → 1.1.3
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.
- package/.eslintrc.js +30 -9
- package/README.md +28 -11
- package/config/helpers.ts +8 -0
- package/config/webpack.common.ts +39 -0
- package/config/webpack.dev.ts +37 -0
- package/config/webpack.prod.ts +17 -0
- package/dist/docs/assets/highlight.css +23 -9
- package/dist/docs/assets/main.js +58 -52
- package/dist/docs/assets/search.js +1 -1
- package/dist/docs/assets/style.css +488 -621
- package/dist/docs/classes/BlobBuilder.BlobBuilder.html +137 -0
- package/dist/docs/classes/Data.Data.html +387 -0
- package/dist/docs/classes/Expression.BinaryExpression.html +184 -1
- package/dist/docs/classes/Expression.ComplexExpression.html +146 -1
- package/dist/docs/classes/Expression.ExpressionBase.html +125 -1
- package/dist/docs/classes/OrderProperty.OrderProperty.html +151 -0
- package/dist/docs/classes/Query.Query.html +353 -0
- package/dist/docs/classes/QueryBase.QueryBase.html +185 -0
- package/dist/docs/classes/QueryBuilder.QueryBuilder.html +204 -0
- package/dist/docs/classes/Requests_BatchRequest.BatchRequest.html +731 -17
- package/dist/docs/classes/Requests_BatchRequest.Transaction.html +332 -17
- package/dist/docs/classes/Requests_ExecutableRequest.ExecutableRequest.html +340 -1
- package/dist/docs/classes/Requests_Request.CommitChunksRequest.html +303 -0
- package/dist/docs/classes/Requests_Request.CreateRelatedRequest.html +310 -1
- package/dist/docs/classes/Requests_Request.CreateRequest.html +307 -1
- package/dist/docs/classes/Requests_Request.DeleteRelatedByIdRequest.html +309 -1
- package/dist/docs/classes/Requests_Request.DeleteRelatedRequest.html +302 -1
- package/dist/docs/classes/Requests_Request.DeleteRequest.html +298 -1
- package/dist/docs/classes/Requests_Request.GetByIdRequest.html +298 -1
- package/dist/docs/classes/Requests_Request.GetRelatedByIdRequest.html +309 -1
- package/dist/docs/classes/Requests_Request.GetRelatedRequest.html +302 -1
- package/dist/docs/classes/Requests_Request.GetRequest.html +295 -1
- package/dist/docs/classes/Requests_Request.UpdateRequest.html +309 -1
- package/dist/docs/classes/Requests_Request.UploadChunkRequest.html +352 -0
- package/dist/docs/classes/Requests_Request.UploadRequest.html +329 -1
- package/dist/docs/classes/Requests_RequestBase.RequestBase.html +275 -1
- package/dist/docs/classes/Requests_RequestFactory.RequestFactory.html +344 -1
- package/dist/docs/classes/Sitefinity.Sitefinity.html +188 -0
- package/dist/docs/classes/WhereQuery.WhereQuery.html +417 -0
- package/dist/docs/classes/chunk_upload_chunk_upload_sdk.ChunkUploadSdk.html +231 -0
- package/dist/docs/classes/chunk_upload_chunked_file_upload_utilities.ChunkedFileUploadUtilities.html +131 -0
- package/dist/docs/classes/utils.utils.html +303 -0
- package/dist/docs/index.html +84 -15
- package/dist/docs/interfaces/Data.CreateRelatedRequestOptions.html +155 -1
- package/dist/docs/interfaces/Data.CreateRequestOptions.html +153 -1
- package/dist/docs/interfaces/Data.OperationsRequestOptions.html +145 -1
- package/dist/docs/interfaces/Data.PropertyRequestOptions.html +149 -1
- package/dist/docs/interfaces/Data.RequestOptionsBase.html +136 -1
- package/dist/docs/interfaces/Data.SingleRelatedItemRequestOptions.html +155 -1
- package/dist/docs/interfaces/Data.UpdateRequestOptions.html +155 -1
- package/dist/docs/interfaces/Data.UploadRequestOptions.html +169 -1
- package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRelatedRequestOptions.html +161 -1
- package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRequestOptions.html +153 -1
- package/dist/docs/interfaces/Requests_BatchRequest.BatchPropertyRequestOptions.html +153 -1
- package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsBase.html +145 -1
- package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsExtended.html +153 -1
- package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleItemRequestOptions.html +145 -1
- package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleRelatedItemRequestOptions.html +161 -1
- package/dist/docs/interfaces/Requests_BatchRequest.BatchUpdateRequestOptions.html +161 -1
- package/dist/docs/interfaces/Requests_ExecutableRequest.ResponseHandlers.html +98 -5
- package/dist/docs/interfaces/Requests_Request.CommitChunksRequestOptionsExtended.html +215 -0
- package/dist/docs/interfaces/Requests_Request.PostRequestOptionsExtended.html +159 -1
- package/dist/docs/interfaces/Requests_Request.PutRequestOptionsExtended.html +161 -1
- package/dist/docs/interfaces/Requests_Request.RelatedByIdRequestOptionsExtended.html +169 -1
- package/dist/docs/interfaces/Requests_Request.RelatedRequestOptionsExtended.html +163 -1
- package/dist/docs/interfaces/Requests_Request.UploadChunkRequestOptionsExtended.html +210 -0
- package/dist/docs/interfaces/Requests_Request.UploadRequestOptionsExtended.html +180 -1
- package/dist/docs/interfaces/Requests_RequestBase.RequestOptionsBaseExtended.html +148 -1
- package/dist/docs/interfaces/Sitefinity.SDKOptions.html +128 -9
- package/dist/docs/interfaces/Sitefinity.Token.html +94 -1
- package/dist/docs/interfaces/Sitefinity.TypeOptions.html +144 -13
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.ChunkUploadInfoDTO.html +159 -0
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.ChunkUploadResult.html +111 -0
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.CleanUpChunksRequestOptions.html +171 -0
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.CommitChunksRequestOptions.html +204 -0
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.GetChunkUploadInfoRequestOptions.html +166 -0
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.UploadChunkRequestOptions.html +201 -0
- package/dist/docs/interfaces/chunk_upload_chunked_file_upload_utilities.ChunkFileResult.html +101 -0
- package/dist/docs/interfaces/chunk_upload_chunked_file_upload_utilities.FileUploadChunk.html +94 -0
- package/dist/docs/modules/BlobBuilder.html +73 -1
- package/dist/docs/modules/Data.html +92 -1
- package/dist/docs/modules/Expression.html +77 -1
- package/dist/docs/modules/OrderProperty.html +73 -1
- package/dist/docs/modules/Query.html +73 -1
- package/dist/docs/modules/QueryBase.html +73 -1
- package/dist/docs/modules/QueryBuilder.html +73 -1
- package/dist/docs/modules/Requests_BatchRequest.html +94 -1
- package/dist/docs/modules/Requests_ExecutableRequest.html +78 -1
- package/dist/docs/modules/Requests_Request.html +114 -1
- package/dist/docs/modules/Requests_RequestBase.html +78 -1
- package/dist/docs/modules/Requests_RequestFactory.html +73 -1
- package/dist/docs/modules/Sitefinity.html +82 -1
- package/dist/docs/modules/WhereQuery.html +73 -1
- package/dist/docs/modules/chunk_upload_chunk_upload_sdk.html +88 -0
- package/dist/docs/modules/chunk_upload_chunked_file_upload_utilities.html +80 -0
- package/dist/docs/modules/constants.html +83 -1
- package/dist/docs/modules/utils.html +73 -1
- package/dist/docs/modules.html +80 -1
- package/dist/docs/variables/constants.CONTENT_TYPES.html +76 -0
- package/dist/docs/variables/constants.EXPRESSION_TYPE.html +104 -0
- package/dist/docs/variables/constants.HEADER_NAMES.html +102 -0
- package/dist/docs/variables/constants.HTTP_METHODS.html +84 -0
- package/dist/docs/variables/constants.ODATA_PARAMS.html +90 -0
- package/dist/docs/variables/constants.SF_PARAMS.html +84 -0
- package/dist/samples.html +237 -38
- package/dist/sitefinity-webservices-sdk.d.ts +0 -1
- package/dist/sitefinity-webservices-sdk.js +524 -119
- package/dist/sitefinity-webservices-sdk.js.map +1 -1
- package/dist/sitefinity-webservices-sdk.min.js +1 -2
- package/dist/src/Data.d.ts +10 -0
- package/dist/src/Data.spec.d.ts +1 -0
- package/dist/src/Query.d.ts +3 -3
- package/dist/src/Requests/ExecutableRequest.d.ts +3 -1
- package/dist/src/Requests/Request.d.ts +42 -0
- package/dist/src/Requests/RequestBase.d.ts +1 -2
- package/dist/src/Requests/RequestFactory.d.ts +3 -1
- package/dist/src/Requests/request.spec.d.ts +1 -0
- package/dist/src/Sitefinity.d.ts +2 -2
- package/dist/src/Sitefinity.spec.d.ts +1 -0
- package/dist/src/WhereQuery.d.ts +2 -2
- package/dist/src/chunk-upload/chunk-upload.sdk.d.ts +290 -0
- package/dist/src/chunk-upload/chunk-upload.sdk.spec.d.ts +1 -0
- package/dist/src/chunk-upload/chunked-file-upload.utilities.d.ts +13 -0
- package/dist/src/constants.d.ts +5 -0
- package/package.json +24 -22
- package/sitefinity-webservices-sdk.ts +0 -1
- package/src/Data.spec.ts +12 -12
- package/src/Data.ts +19 -4
- package/src/OrderProperty.ts +7 -7
- package/src/Query.ts +4 -4
- package/src/QueryBase.ts +4 -4
- package/src/QueryBuilder.ts +38 -38
- package/src/Requests/BatchRequest.ts +25 -25
- package/src/Requests/ExecutableRequest.ts +30 -24
- package/src/Requests/Request.ts +109 -2
- package/src/Requests/RequestBase.ts +3 -4
- package/src/Requests/RequestFactory.ts +9 -1
- package/src/Requests/request.spec.ts +10 -10
- package/src/Sitefinity.spec.ts +6 -6
- package/src/Sitefinity.ts +5 -5
- package/src/WhereQuery.ts +2 -2
- package/src/chunk-upload/chunk-upload.sdk.spec.ts +340 -0
- package/src/chunk-upload/chunk-upload.sdk.ts +436 -0
- package/src/chunk-upload/chunked-file-upload.utilities.ts +64 -0
- package/src/constants.ts +35 -30
- package/src/utils.ts +10 -10
- package/template.html +191 -38
- package/tsconfig.json +11 -3
- package/.npmignore +0 -92
- package/ci/pipelines/ci.yml +0 -219
- package/config/helpers.js +0 -10
- package/config/webpack.common.js +0 -39
- package/config/webpack.dev.js +0 -19
- package/config/webpack.prod.js +0 -25
- package/dist/docs/assets/icons.css +0 -1043
- package/dist/docs/assets/icons.png +0 -0
- package/dist/docs/assets/icons@2x.png +0 -0
- package/dist/docs/assets/widgets.png +0 -0
- package/dist/docs/assets/widgets@2x.png +0 -0
- package/dist/docs/classes/BlobBuilder.BlobBuilder-1.html +0 -7
- package/dist/docs/classes/Data.Data-1.html +0 -65
- package/dist/docs/classes/OrderProperty.OrderProperty-1.html +0 -1
- package/dist/docs/classes/Query.Query-1.html +0 -33
- package/dist/docs/classes/QueryBase.QueryBase-1.html +0 -7
- package/dist/docs/classes/QueryBuilder.QueryBuilder-1.html +0 -1
- package/dist/docs/classes/Sitefinity.Sitefinity-1.html +0 -5
- package/dist/docs/classes/WhereQuery.WhereQuery-1.html +0 -31
- package/dist/docs/classes/utils.utils-1.html +0 -1
- package/dist/sitefinity-webservices-sdk.min.js.LICENSE.txt +0 -14
- package/package-lock.json +0 -17487
- package/type.txt +0 -1
- package/version.txt +0 -1
package/src/Sitefinity.spec.ts
CHANGED
|
@@ -103,7 +103,7 @@ OData-Version: 4.0\r
|
|
|
103
103
|
sdk = new Sitefinity({
|
|
104
104
|
baseUrl: "http://www.mysite.com/api/default/v2/",
|
|
105
105
|
enableUnlimitedChoices: false
|
|
106
|
-
})
|
|
106
|
+
});
|
|
107
107
|
sdk.data({}).get({});
|
|
108
108
|
|
|
109
109
|
request = jasmine.Ajax.requests.mostRecent();
|
|
@@ -123,7 +123,7 @@ OData-Version: 4.0\r
|
|
|
123
123
|
sdk = new Sitefinity({
|
|
124
124
|
baseUrl: "http://www.mysite.com/api/default/v2/",
|
|
125
125
|
integrationMode: false
|
|
126
|
-
})
|
|
126
|
+
});
|
|
127
127
|
sdk.data({}).get({});
|
|
128
128
|
|
|
129
129
|
request = jasmine.Ajax.requests.mostRecent();
|
|
@@ -147,7 +147,7 @@ OData-Version: 4.0\r
|
|
|
147
147
|
const request = jasmine.Ajax.requests.mostRecent();
|
|
148
148
|
request.respondWith({
|
|
149
149
|
status: 200,
|
|
150
|
-
responseText:
|
|
150
|
+
responseText: "{\"message\":\"test\"}"
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
expect(successSpy).toHaveBeenCalledOnceWith({ message: "test" });
|
|
@@ -171,7 +171,7 @@ OData-Version: 4.0\r
|
|
|
171
171
|
const request = jasmine.Ajax.requests.mostRecent();
|
|
172
172
|
request.respondWith({
|
|
173
173
|
status: 400,
|
|
174
|
-
responseText:
|
|
174
|
+
responseText: "{\"message\":\"test\"}"
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
expect(failureSpy).toHaveBeenCalledOnceWith({ message: "test", status: 400 });
|
|
@@ -286,7 +286,7 @@ OData-Version: 4.0\r
|
|
|
286
286
|
}).get({});
|
|
287
287
|
|
|
288
288
|
const request = jasmine.Ajax.requests.mostRecent();
|
|
289
|
-
expect(request.url).toContain(
|
|
289
|
+
expect(request.url).toContain("p1=test1&p2=123");
|
|
290
290
|
});
|
|
291
291
|
});
|
|
292
292
|
|
|
@@ -366,7 +366,7 @@ OData-Version: 4.0\r
|
|
|
366
366
|
}).execute();
|
|
367
367
|
|
|
368
368
|
const request = jasmine.Ajax.requests.mostRecent();
|
|
369
|
-
expect(request.url).toContain(
|
|
369
|
+
expect(request.url).toContain("p1=test1&p2=123");
|
|
370
370
|
});
|
|
371
371
|
|
|
372
372
|
it("Verify successCb overrides global success handler from SDK options", () => {
|
package/src/Sitefinity.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RequestFactory } from
|
|
2
|
-
import { Data } from
|
|
3
|
-
import { Query } from
|
|
4
|
-
import { utils } from
|
|
1
|
+
import { RequestFactory } from "./Requests/RequestFactory";
|
|
2
|
+
import { Data } from "./Data";
|
|
3
|
+
import { Query } from "./Query";
|
|
4
|
+
import { utils } from "./utils";
|
|
5
5
|
import { ResponseHandlers } from "./Requests/ExecutableRequest";
|
|
6
6
|
import { BatchRequest } from "./Requests/BatchRequest";
|
|
7
7
|
|
|
@@ -29,7 +29,7 @@ export class Sitefinity {
|
|
|
29
29
|
siteId: options.siteId || this.siteId,
|
|
30
30
|
additionalQueryParams: options.additionalQueryParams,
|
|
31
31
|
entitySet: options.entitySet
|
|
32
|
-
}
|
|
32
|
+
};
|
|
33
33
|
|
|
34
34
|
return new Data(urlOptions, this.factory);
|
|
35
35
|
}
|
package/src/WhereQuery.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComplexExpression, BinaryExpression } from
|
|
1
|
+
import { ComplexExpression, BinaryExpression } from "./Expression";
|
|
2
2
|
import { EXPRESSION_TYPE } from "./constants";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -103,7 +103,7 @@ export class WhereQuery<QueryType> {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
* Ends the definition of the current WhereQuery. You need to call this method in order to continue with the definition of the parent {@link
|
|
106
|
+
* Ends the definition of the current WhereQuery. You need to call this method in order to continue with the definition of the parent {@link Query}. All other `WhereQuery` methods return the current instance of `WhereQuery` to allow chaining.
|
|
107
107
|
*/
|
|
108
108
|
done(): QueryType {
|
|
109
109
|
if (this.parent instanceof WhereQuery) {
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { Sitefinity, TypeOptions } from "../Sitefinity";
|
|
2
|
+
import { ChunkUploadInfoDTO, ChunkUploadResult, ChunkUploadSdk, CleanUpChunksRequestOptions, CommitChunksRequestOptions, GetChunkUploadInfoRequestOptions, UploadChunkRequestOptions } from "./chunk-upload.sdk";
|
|
3
|
+
import { FileUploadChunk } from "./chunked-file-upload.utilities";
|
|
4
|
+
|
|
5
|
+
const baseUrl = "http://www.mysite.com/api/default/";
|
|
6
|
+
const chunkSize10MegaBytes = 10000000;
|
|
7
|
+
const typeOptions: TypeOptions = {
|
|
8
|
+
entitySet: "images"
|
|
9
|
+
};
|
|
10
|
+
const mimeType = "image/jpeg";
|
|
11
|
+
const libraryId = "4dff7037-e3e4-4980-8cd2-333333333333";
|
|
12
|
+
const chunkedFileUploadSessionId = "4dff7037-e3e4-4980-8cd2-666666666666";
|
|
13
|
+
const blobStorageProviderName = "Database";
|
|
14
|
+
const itemId = "4dff7037-e3e4-4980-8cd2-999999999999";
|
|
15
|
+
const fileName = "fakeImage.jpeg";
|
|
16
|
+
const uploadProperties = {
|
|
17
|
+
"Title": "asd",
|
|
18
|
+
"UrlName": "asd"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe("Chunk upload tests", () => {
|
|
22
|
+
let sitefinity: Sitefinity;
|
|
23
|
+
let chunkUploadSdk: ChunkUploadSdk;
|
|
24
|
+
|
|
25
|
+
beforeAll(() => {
|
|
26
|
+
sitefinity = new Sitefinity({
|
|
27
|
+
baseUrl
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
chunkUploadSdk = sitefinity.data(typeOptions).chunkUpload;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
beforeEach(function () {
|
|
34
|
+
jasmine.Ajax.install();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(function () {
|
|
38
|
+
jasmine.Ajax.uninstall();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("chunkFile should take base64 string input and convert it successfully to a blob and produce expected chunks result", () => {
|
|
42
|
+
const result = chunkUploadSdk.chunkFile(getBase64Image713BytesInSize(), chunkSize10MegaBytes, mimeType);
|
|
43
|
+
|
|
44
|
+
// a bit of magic, but this is the size of the base64
|
|
45
|
+
expect(result.fileTotalSize).toEqual(713);
|
|
46
|
+
// there should be only 1 chunk since the chunk size is 10MB
|
|
47
|
+
expect(result.totalChunksCount).toBe(1);
|
|
48
|
+
|
|
49
|
+
expect(result.chunks[0].content instanceof Blob).toBeTrue();
|
|
50
|
+
expect(result.chunks[0].content.size).toEqual(713);
|
|
51
|
+
expect(result.chunks[0].content.type).toEqual(mimeType);
|
|
52
|
+
expect(result.chunks[0].ordinal).toEqual(0);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("chunkFile should generate correct number of chunks with correct size when the chunk size divides the files size with a remainder.", () => {
|
|
56
|
+
// if we have a file that is 713 bytes in size and we chunk it in parts with the size of
|
|
57
|
+
// 2 bytes, we should get 357 chunks, (713/2 = 356.5), thus there should be 356 chunks with
|
|
58
|
+
// size of 2 bytes and the 357th chunk should have a size of 1 byte.
|
|
59
|
+
const testFileSize = 713;
|
|
60
|
+
const chunkSize2Bytes = 2;
|
|
61
|
+
const expectedSizeOfLastChunk = testFileSize % chunkSize2Bytes;
|
|
62
|
+
const expectNumberOfChunks = Math.ceil(testFileSize / chunkSize2Bytes);
|
|
63
|
+
|
|
64
|
+
const result = chunkUploadSdk.chunkFile(getBase64Image713BytesInSize(), chunkSize2Bytes, mimeType);
|
|
65
|
+
|
|
66
|
+
expect(result.fileTotalSize).toEqual(testFileSize);
|
|
67
|
+
expect(result.totalChunksCount).toEqual(expectNumberOfChunks);
|
|
68
|
+
|
|
69
|
+
result.chunks.forEach((chunk, i) => {
|
|
70
|
+
expect(chunk.ordinal).toEqual(i);
|
|
71
|
+
expect(chunk.content.type).toEqual(mimeType);
|
|
72
|
+
|
|
73
|
+
if (i === result.totalChunksCount - 1) {
|
|
74
|
+
expect(chunk.content.size).toEqual(expectedSizeOfLastChunk);
|
|
75
|
+
} else {
|
|
76
|
+
expect(chunk.content.size).toEqual(chunkSize2Bytes);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("getChunkUploadInfo should set correct action name and parameter and be a GET request", () => {
|
|
83
|
+
const requestOptions: GetChunkUploadInfoRequestOptions = {
|
|
84
|
+
data: {
|
|
85
|
+
libraryId
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
chunkUploadSdk.getChunkUploadInfo(requestOptions);
|
|
90
|
+
|
|
91
|
+
const getChunkUploadInfoRequest = jasmine.Ajax.requests.mostRecent();
|
|
92
|
+
|
|
93
|
+
assertGetChunkUploadInfoRequest(getChunkUploadInfoRequest);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("cleanUpChunks should set correct action name and parameters and be a POST request", () => {
|
|
97
|
+
const cleanUpChunksRequestOptions: CleanUpChunksRequestOptions = {
|
|
98
|
+
data: {
|
|
99
|
+
chunkedFileUploadSessionId,
|
|
100
|
+
blobStorageProviderName
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
chunkUploadSdk.cleanUpChunks(cleanUpChunksRequestOptions);
|
|
105
|
+
|
|
106
|
+
const cleanUpChunksRequest = jasmine.Ajax.requests.mostRecent();
|
|
107
|
+
|
|
108
|
+
expect(cleanUpChunksRequest.url).toContain("Default.CleanUpChunks");
|
|
109
|
+
expect(cleanUpChunksRequest.params).toBe(JSON.stringify(cleanUpChunksRequestOptions.data));
|
|
110
|
+
expect(cleanUpChunksRequest.url).toContain(typeOptions.entitySet);
|
|
111
|
+
expect(cleanUpChunksRequest.method).toBe("POST");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("commitChunks should set correct action name and parameters and be a POST request", () => {
|
|
115
|
+
const fileTotalSize = 1000;
|
|
116
|
+
const numberOfChunks = Math.ceil(fileTotalSize / chunkSize10MegaBytes);
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
const commitChunksRequestOptions: CommitChunksRequestOptions = {
|
|
120
|
+
data: {
|
|
121
|
+
chunkedFileUploadSessionId,
|
|
122
|
+
contentType: mimeType,
|
|
123
|
+
fileTotalSize,
|
|
124
|
+
numberOfChunks,
|
|
125
|
+
name: fileName,
|
|
126
|
+
blobStorageProviderName,
|
|
127
|
+
itemId,
|
|
128
|
+
uploadProperties
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
chunkUploadSdk.commitChunks(commitChunksRequestOptions);
|
|
133
|
+
|
|
134
|
+
const commitChunksRequest = jasmine.Ajax.requests.mostRecent();
|
|
135
|
+
assertCommitChunksRequest(commitChunksRequest, commitChunksRequestOptions);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("uploadChunk should set correct url, headers, body to be a Blob and be a POST request", () => {
|
|
139
|
+
const result = chunkUploadSdk.chunkFile(getBase64Image713BytesInSize(), chunkSize10MegaBytes, mimeType);
|
|
140
|
+
|
|
141
|
+
const expectedChunksCount = Math.ceil(713 / chunkSize10MegaBytes);
|
|
142
|
+
|
|
143
|
+
expect(result.totalChunksCount).toEqual(expectedChunksCount);
|
|
144
|
+
|
|
145
|
+
result.chunks.forEach(chunk => {
|
|
146
|
+
const uploadChunkRequestOptions: UploadChunkRequestOptions = {
|
|
147
|
+
data: {
|
|
148
|
+
fileMimeType: mimeType,
|
|
149
|
+
chunkedFileUploadSessionId,
|
|
150
|
+
chunkSize: chunkSize10MegaBytes,
|
|
151
|
+
chunkOrdinal: chunk.ordinal,
|
|
152
|
+
numberOfChunks: result.totalChunksCount,
|
|
153
|
+
positionOfChunkInQueue: chunk.ordinal,
|
|
154
|
+
chunkBlob: chunk.content,
|
|
155
|
+
blobStorageProviderName: blobStorageProviderName
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
chunkUploadSdk.uploadChunk(uploadChunkRequestOptions);
|
|
160
|
+
|
|
161
|
+
const chunkUploadRequest = jasmine.Ajax.requests.mostRecent();
|
|
162
|
+
|
|
163
|
+
assertChunkUploadRequest(chunkUploadRequest, chunk);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("partially simulate chunk upload", () => {
|
|
168
|
+
const GET_CHUNK_UPLOAD_INFO_RESPONSE_MOCK = {
|
|
169
|
+
"@odata.context": "http://localhost:1337/sf/system/$metadata#Telerik.Sitefinity.Web.Api.OData.Operations.Media.Models.ChunkUploadInfo",
|
|
170
|
+
"ProviderSupportsChunkUpload": true,
|
|
171
|
+
"BlobStorageProviderName": "Database",
|
|
172
|
+
"ChunkedFileUploadSessionId": chunkedFileUploadSessionId,
|
|
173
|
+
"ChunkSize": chunkSize10MegaBytes,
|
|
174
|
+
"MaxRetryCountForChunk": 5,
|
|
175
|
+
"MaxSimultaneousChunkUploadRequestsPerSession": 10
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const CHUNK_UPLOAD_RESPONSE_MOCK = {
|
|
179
|
+
"SuccessfullyUploaded": true,
|
|
180
|
+
"ChunkedFileUploadSessionId": chunkedFileUploadSessionId
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const COMMIT_CHUNKS_RESPONSE_MOCK = {
|
|
184
|
+
"@odata.context": "http://localhost:1337/sf/system/$metadata#images/$entity", "Id": "e3dfab01-3e0b-4e60-9a38-934c640c937d", "LastModified": "2022-09-07T08:23:36Z", "PublicationDate": "2022-09-07T08:23:34Z", "Title": "christmas_pack", "Description": "", "DateCreated": "2022-09-07T08:23:34Z", "IncludeInSitemap": true, "SystemSourceKey": null, "Ordinal": -1, "UrlName": "christmas_pack", "ItemDefaultUrl": "/images/default-source/default-album/christmas_pack", "Author": "", "Extension": ".jpg", "MimeType": "image/jpeg", "TotalSize": 141429, "Tags": [], "Category": [], "Width": 600, "Height": 400, "AlternativeText": "", "FolderId": null, "ParentId": "4ba7ad46-f29b-4e65-be17-9bf7ce5ba1fb", "Urls": [], "MediaFileUrlName": "christmas_pack", "MediaFileUrls": [], "Provider": "OpenAccessDataProvider", "Url": "http://localhost:1337/images/default-source/default-album/christmas_pack.jpg?Status=Master&sfvrsn=4ed4e51c_1", "ThumbnailUrl": "http://localhost:1337/images/default-source/default-album/christmas_pack.tmb-0.jpg?Status=Master&Culture=en&sfvrsn=4ed4e51c_1", "IsDamMedia": false, "Breadcrumb": ["Default Library"], "CreatedBy": "stefan koserkov", "LastModifiedBy": "stefan koserkov", "AvailableLanguages": ["en"], "LibraryTitle": "Default Library", "Thumbnails": [{ "Title": "0", "Url": "http://localhost:1337/images/default-source/default-album/christmas_pack.tmb-0.jpg?Status=Master&Culture=en&sfvrsn=4ed4e51c_1", "Width": 240, "Height": 160, "MimeType": "image/jpeg" }], "LockedStatus": { "Date": "2022-09-07T08:23:34.503Z", "User": "User Not Found", "Id": "User Not Found" }, "DisplayStatus": [{ "Name": "Draft", "Source": "Lifecycle", "Label": "Draft", "DetailedLabel": "Saved as draft", "PublicationDate": null, "ExpirationDate": null, "Date": "2022-09-07T08:23:36.44Z", "User": "stefan koserkov", "Id": null, "Message": { "Title": null, "Description": null, "Operations": [] } }], "FirstPublished": null, "LastPublished": null
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const expectedChunksCount = Math.ceil(713 / GET_CHUNK_UPLOAD_INFO_RESPONSE_MOCK.ChunkSize);
|
|
188
|
+
let successfullyUploadedChunks = 0;
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
const getChunkUploadInfoOptions: GetChunkUploadInfoRequestOptions = {
|
|
192
|
+
data: {
|
|
193
|
+
libraryId
|
|
194
|
+
},
|
|
195
|
+
successCb: (dto: ChunkUploadInfoDTO) => {
|
|
196
|
+
const result = chunkUploadSdk.chunkFile(getBase64Image713BytesInSize(), chunkSize10MegaBytes, mimeType);
|
|
197
|
+
expect(result.totalChunksCount).toEqual(expectedChunksCount);
|
|
198
|
+
|
|
199
|
+
result.chunks.forEach(chunk => {
|
|
200
|
+
const uploadChunkRequestOptions: UploadChunkRequestOptions = {
|
|
201
|
+
data: {
|
|
202
|
+
fileMimeType: mimeType,
|
|
203
|
+
chunkedFileUploadSessionId: dto.ChunkedFileUploadSessionId,
|
|
204
|
+
chunkSize: dto.ChunkSize,
|
|
205
|
+
chunkOrdinal: chunk.ordinal,
|
|
206
|
+
numberOfChunks: result.totalChunksCount,
|
|
207
|
+
positionOfChunkInQueue: chunk.ordinal,
|
|
208
|
+
chunkBlob: chunk.content,
|
|
209
|
+
blobStorageProviderName: dto.BlobStorageProviderName
|
|
210
|
+
},
|
|
211
|
+
successCb: (chunkResult: ChunkUploadResult) => {
|
|
212
|
+
if (chunkResult.SuccessfullyUploaded) {
|
|
213
|
+
successfullyUploadedChunks++;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (successfullyUploadedChunks === result.totalChunksCount) {
|
|
217
|
+
const commitChunksRequestOptions: CommitChunksRequestOptions = {
|
|
218
|
+
data: {
|
|
219
|
+
chunkedFileUploadSessionId,
|
|
220
|
+
contentType: mimeType,
|
|
221
|
+
fileTotalSize: result.fileTotalSize,
|
|
222
|
+
numberOfChunks: result.totalChunksCount,
|
|
223
|
+
name: fileName,
|
|
224
|
+
blobStorageProviderName: dto.BlobStorageProviderName,
|
|
225
|
+
uploadProperties,
|
|
226
|
+
itemId: null
|
|
227
|
+
},
|
|
228
|
+
successCb: commitChunksResponse => {
|
|
229
|
+
expect(commitChunksResponse).toEqual(COMMIT_CHUNKS_RESPONSE_MOCK);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
chunkUploadSdk.commitChunks(commitChunksRequestOptions);
|
|
234
|
+
|
|
235
|
+
// responds to chunkUploadSdk.commitChunks
|
|
236
|
+
const commitChunksRequest = jasmine.Ajax.requests.mostRecent();
|
|
237
|
+
assertCommitChunksRequest(commitChunksRequest, commitChunksRequestOptions);
|
|
238
|
+
commitChunksRequest.respondWith({
|
|
239
|
+
status: 200,
|
|
240
|
+
responseText: JSON.stringify(COMMIT_CHUNKS_RESPONSE_MOCK)
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
chunkUploadSdk.uploadChunk(uploadChunkRequestOptions);
|
|
247
|
+
|
|
248
|
+
// responds to chunkUploadSdk.uploadChunk
|
|
249
|
+
const chunkUploadRequest = jasmine.Ajax.requests.mostRecent();
|
|
250
|
+
assertChunkUploadRequest(chunkUploadRequest, chunk);
|
|
251
|
+
chunkUploadRequest.respondWith({
|
|
252
|
+
status: 200,
|
|
253
|
+
responseText: JSON.stringify(CHUNK_UPLOAD_RESPONSE_MOCK)
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
chunkUploadSdk.getChunkUploadInfo(getChunkUploadInfoOptions);
|
|
260
|
+
|
|
261
|
+
// responds to chunkUploadSdk.getChunkUploadInfo
|
|
262
|
+
const getChunkUploadInfoRequest = jasmine.Ajax.requests.mostRecent();
|
|
263
|
+
assertGetChunkUploadInfoRequest(getChunkUploadInfoRequest);
|
|
264
|
+
getChunkUploadInfoRequest.respondWith({
|
|
265
|
+
status: 200,
|
|
266
|
+
responseText: JSON.stringify(GET_CHUNK_UPLOAD_INFO_RESPONSE_MOCK)
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
function assertCommitChunksRequest(commitChunksRequest: JasmineAjaxRequest, commitChunksRequestOptions: CommitChunksRequestOptions) {
|
|
272
|
+
const expectedPayload = {
|
|
273
|
+
commitChunksDto: {
|
|
274
|
+
chunkedFileUploadSessionId: commitChunksRequestOptions.data.chunkedFileUploadSessionId,
|
|
275
|
+
contentType: commitChunksRequestOptions.data.contentType,
|
|
276
|
+
fileTotalSize: commitChunksRequestOptions.data.fileTotalSize,
|
|
277
|
+
numberOfChunks: commitChunksRequestOptions.data.numberOfChunks,
|
|
278
|
+
fileName: commitChunksRequestOptions.data.name,
|
|
279
|
+
blobStorageProviderName: commitChunksRequestOptions.data.blobStorageProviderName,
|
|
280
|
+
itemId: commitChunksRequestOptions.data.itemId,
|
|
281
|
+
properties: commitChunksRequestOptions.data.uploadProperties
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
expect(commitChunksRequest.url).toContain("Default.CommitChunks");
|
|
286
|
+
expect(commitChunksRequest.params).toEqual(JSON.stringify(expectedPayload));
|
|
287
|
+
expect(commitChunksRequest.url).toContain(typeOptions.entitySet);
|
|
288
|
+
expect(commitChunksRequest.method).toEqual("POST");
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function assertChunkUploadRequest(chunkUploadRequest: JasmineAjaxRequest, chunk: FileUploadChunk) {
|
|
292
|
+
expect(chunkUploadRequest.url)
|
|
293
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should contain ${baseUrl}${typeOptions.entitySet}`)
|
|
294
|
+
.toEqual(`${baseUrl}${typeOptions.entitySet}`);
|
|
295
|
+
|
|
296
|
+
expect(chunkUploadRequest.method)
|
|
297
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should be a POST request`)
|
|
298
|
+
.toEqual("POST");
|
|
299
|
+
expect(chunkUploadRequest.params instanceof Blob)
|
|
300
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal} body must be of type Blob`)
|
|
301
|
+
.toBeTrue();
|
|
302
|
+
expect((chunkUploadRequest.params as Blob).size)
|
|
303
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should have size of ${chunk.content.size}`)
|
|
304
|
+
.toBe(chunk.content.size);
|
|
305
|
+
expect((chunkUploadRequest.params as Blob).type)
|
|
306
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal} body param should have a mime type of ${mimeType}`)
|
|
307
|
+
.toBe(mimeType);
|
|
308
|
+
expect(chunkUploadRequest.requestHeaders["Content-Encoding"])
|
|
309
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should have header "Content-Encoding" with value identity`)
|
|
310
|
+
.toEqual("identity");
|
|
311
|
+
expect(chunkUploadRequest.requestHeaders["Content-Type"])
|
|
312
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should have header "Content-type" with value ${mimeType}`)
|
|
313
|
+
.toEqual(mimeType);
|
|
314
|
+
expect(chunkUploadRequest.requestHeaders["X-SF-Blob-Storage-Provider-Name"])
|
|
315
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should have header "X-SF-Blob-Storage-Provider-Name" with value ${blobStorageProviderName}`)
|
|
316
|
+
.toEqual(blobStorageProviderName);
|
|
317
|
+
expect(chunkUploadRequest.requestHeaders["X-SF-Chunk-Ordinal"])
|
|
318
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should have header "X-SF-Chunk-Ordinal" with value ${chunk.ordinal}`)
|
|
319
|
+
.toEqual(chunk.ordinal.toString());
|
|
320
|
+
expect(chunkUploadRequest.requestHeaders["X-SF-Chunk-Size"])
|
|
321
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should have header "X-SF-Chunk-Size" with value ${chunkSize10MegaBytes}`)
|
|
322
|
+
.toEqual(chunkSize10MegaBytes.toString());
|
|
323
|
+
expect(chunkUploadRequest.requestHeaders["X-SF-Chunked-File-Upload-Session-Id"])
|
|
324
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should have header "X-SF-Chunked-File-Upload-Session-Id" with value ${chunkedFileUploadSessionId}`)
|
|
325
|
+
.toEqual(chunkedFileUploadSessionId);
|
|
326
|
+
expect(chunkUploadRequest.requestHeaders["X-SF-Service-Request"])
|
|
327
|
+
.withContext(`Chunk request for chunk number ${chunk.ordinal}, should have header "X-SF-Service-Request" with value true`)
|
|
328
|
+
.toEqual("true");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function assertGetChunkUploadInfoRequest(getChunkUploadInfoRequest: JasmineAjaxRequest) {
|
|
332
|
+
expect(getChunkUploadInfoRequest.url).toContain(`Default.GetChunkUploadInfo(libraryId=${libraryId})`);
|
|
333
|
+
expect(getChunkUploadInfoRequest.url).toContain(typeOptions.entitySet);
|
|
334
|
+
expect(getChunkUploadInfoRequest.method).toBe("GET");
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function getBase64Image713BytesInSize() {
|
|
338
|
+
// ! 713 Bytes
|
|
339
|
+
return "/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAAOAA4DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD91PFnxd8M+A/HXhXwxqusWun6944nubbQbKXPmanLb273MyR8YykMbuQSPlQ46V1FFFAH/9k=";
|
|
340
|
+
}
|