@progress/sitefinity-webservices-sdk 1.0.3 → 1.1.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.
- package/.eslintrc.js +30 -9
- 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 +17 -3
- package/dist/docs/assets/main.js +4 -2
- package/dist/docs/assets/search.js +1 -1
- package/dist/docs/assets/style.css +430 -619
- package/dist/docs/classes/BlobBuilder.BlobBuilder.html +135 -0
- package/dist/docs/classes/Data.Data.html +385 -0
- package/dist/docs/classes/Expression.BinaryExpression.html +184 -1
- package/dist/docs/classes/Expression.ComplexExpression.html +139 -1
- package/dist/docs/classes/Expression.ExpressionBase.html +125 -1
- package/dist/docs/classes/OrderProperty.OrderProperty.html +130 -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 +190 -0
- package/dist/docs/classes/Requests_BatchRequest.BatchRequest.html +731 -17
- package/dist/docs/classes/Requests_BatchRequest.Transaction.html +330 -17
- package/dist/docs/classes/Requests_ExecutableRequest.ExecutableRequest.html +342 -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 +309 -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 +300 -1
- package/dist/docs/classes/Requests_Request.GetByIdRequest.html +300 -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 +342 -1
- package/dist/docs/classes/Sitefinity.Sitefinity.html +186 -0
- package/dist/docs/classes/WhereQuery.WhereQuery.html +410 -0
- package/dist/docs/classes/chunk_upload_chunk_upload_sdk.ChunkUploadSdk.html +229 -0
- package/dist/docs/classes/chunk_upload_chunked_file_upload_utilities.ChunkedFileUploadUtilities.html +129 -0
- package/dist/docs/classes/utils.utils.html +301 -0
- package/dist/docs/index.html +56 -2
- package/dist/docs/interfaces/Data.CreateRelatedRequestOptions.html +157 -1
- package/dist/docs/interfaces/Data.CreateRequestOptions.html +155 -1
- package/dist/docs/interfaces/Data.OperationsRequestOptions.html +145 -1
- package/dist/docs/interfaces/Data.PropertyRequestOptions.html +151 -1
- package/dist/docs/interfaces/Data.RequestOptionsBase.html +136 -1
- package/dist/docs/interfaces/Data.SingleRelatedItemRequestOptions.html +157 -1
- package/dist/docs/interfaces/Data.UpdateRequestOptions.html +157 -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 +96 -5
- package/dist/docs/interfaces/Requests_Request.CommitChunksRequestOptionsExtended.html +215 -0
- package/dist/docs/interfaces/Requests_Request.PostRequestOptionsExtended.html +161 -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 +165 -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 +150 -1
- package/dist/docs/interfaces/Sitefinity.SDKOptions.html +128 -9
- package/dist/docs/interfaces/Sitefinity.Token.html +92 -1
- package/dist/docs/interfaces/Sitefinity.TypeOptions.html +144 -13
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.ChunkUploadInfoDTO.html +157 -0
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.ChunkUploadResult.html +109 -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 +99 -0
- package/dist/docs/interfaces/chunk_upload_chunked_file_upload_utilities.FileUploadChunk.html +92 -0
- package/dist/docs/modules/BlobBuilder.html +71 -1
- package/dist/docs/modules/Data.html +90 -1
- package/dist/docs/modules/Expression.html +75 -1
- package/dist/docs/modules/OrderProperty.html +71 -1
- package/dist/docs/modules/Query.html +71 -1
- package/dist/docs/modules/QueryBase.html +71 -1
- package/dist/docs/modules/QueryBuilder.html +71 -1
- package/dist/docs/modules/Requests_BatchRequest.html +92 -1
- package/dist/docs/modules/Requests_ExecutableRequest.html +76 -1
- package/dist/docs/modules/Requests_Request.html +112 -1
- package/dist/docs/modules/Requests_RequestBase.html +76 -1
- package/dist/docs/modules/Requests_RequestFactory.html +71 -1
- package/dist/docs/modules/Sitefinity.html +80 -1
- package/dist/docs/modules/WhereQuery.html +71 -1
- package/dist/docs/modules/chunk_upload_chunk_upload_sdk.html +86 -0
- package/dist/docs/modules/chunk_upload_chunked_file_upload_utilities.html +78 -0
- package/dist/docs/modules/constants.html +81 -1
- package/dist/docs/modules/utils.html +71 -1
- package/dist/docs/modules.html +78 -1
- package/dist/docs/variables/constants.CONTENT_TYPES.html +74 -0
- package/dist/docs/variables/constants.EXPRESSION_TYPE.html +102 -0
- package/dist/docs/variables/constants.HEADER_NAMES.html +100 -0
- package/dist/docs/variables/constants.HTTP_METHODS.html +82 -0
- package/dist/docs/variables/constants.ODATA_PARAMS.html +88 -0
- package/dist/docs/variables/constants.SF_PARAMS.html +82 -0
- package/dist/samples.html +235 -36
- package/dist/sitefinity-webservices-sdk.d.ts +0 -1
- package/dist/sitefinity-webservices-sdk.js +473 -117
- 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-lock.json +3166 -6687
- 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 +189 -36
- package/tsconfig.json +11 -3
- package/type.txt +1 -1
- package/config/helpers.js +0 -10
- package/config/webpack.common.js +0 -38
- 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/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/version.txt +0 -1
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { CreateRequestOptions } from "../Data";
|
|
2
|
+
import { CommitChunksRequestOptionsExtended } from "../Requests/Request";
|
|
3
|
+
import { RequestOptionsBaseExtended } from "../Requests/RequestBase";
|
|
4
|
+
import { RequestFactory } from "../Requests/RequestFactory";
|
|
5
|
+
import { TypeOptions } from "../Sitefinity";
|
|
6
|
+
import { ChunkedFileUploadUtilities, ChunkFileResult } from "./chunked-file-upload.utilities";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @description Entry point for all chunk upload related tasks
|
|
10
|
+
* @export
|
|
11
|
+
* @class ChunkUploadSdk
|
|
12
|
+
*/
|
|
13
|
+
export class ChunkUploadSdk {
|
|
14
|
+
private urlOptions: TypeOptions;
|
|
15
|
+
private factory: RequestFactory;
|
|
16
|
+
|
|
17
|
+
constructor(urlOptions: TypeOptions, factory: RequestFactory) {
|
|
18
|
+
this.urlOptions = urlOptions;
|
|
19
|
+
this.factory = factory;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @description Gets the needed information to start uploading chunks to the server
|
|
24
|
+
* @param {GetChunkUploadInfoRequestOptions} parameters
|
|
25
|
+
* @memberof ChunkUploadSdk
|
|
26
|
+
*/
|
|
27
|
+
getChunkUploadInfo(parameters: GetChunkUploadInfoRequestOptions) {
|
|
28
|
+
Guard.isNotNull(parameters, "parameters");
|
|
29
|
+
Guard.isNotNull(parameters.data, "parameters.data");
|
|
30
|
+
Guard.isNotNull(parameters.data.libraryId, "parameters.data.libraryId");
|
|
31
|
+
|
|
32
|
+
const options: RequestOptionsBaseExtended = {
|
|
33
|
+
urlOptions: this.urlOptions,
|
|
34
|
+
action: `Default.GetChunkUploadInfo(libraryId=${parameters.data.libraryId})`,
|
|
35
|
+
successCb: parameters.successCb,
|
|
36
|
+
failureCb: parameters.failureCb,
|
|
37
|
+
progressCb: parameters.progressCb,
|
|
38
|
+
fallbackProperties: parameters.fallbackProperties,
|
|
39
|
+
query: parameters.query
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const request = this.factory.get(options);
|
|
43
|
+
|
|
44
|
+
request.execute();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @description Sends a single chunk request to the server
|
|
49
|
+
* @param {UploadChunkRequestOptions} parameters
|
|
50
|
+
* @memberof ChunkUploadSdk
|
|
51
|
+
*/
|
|
52
|
+
uploadChunk(parameters: UploadChunkRequestOptions) {
|
|
53
|
+
Guard.isNotNull(parameters, "parameters");
|
|
54
|
+
Guard.isNotNull(parameters.data, "parameters.data");
|
|
55
|
+
Guard.isNotNull(parameters.data.fileMimeType, "parameters.data.fileMimeType");
|
|
56
|
+
Guard.isNotNull(parameters.data.chunkSize, "parameters.data.chunkSize");
|
|
57
|
+
Guard.isNotNull(parameters.data.chunkedFileUploadSessionId, "parameters.data.chunkedFileUploadSessionId");
|
|
58
|
+
Guard.isNotNull(parameters.data.chunkOrdinal, "parameters.data.chunkOrdinal");
|
|
59
|
+
Guard.isNotNull(parameters.data.numberOfChunks, "parameters.data.numberOfChunks");
|
|
60
|
+
Guard.isNotNull(parameters.data.chunkBlob, "parameters.data.chunkBlob");
|
|
61
|
+
Guard.isNotNull(parameters.data.blobStorageProviderName, "parameters.data.blobStorageProviderName");
|
|
62
|
+
|
|
63
|
+
const request = this.factory.uploadChunk({
|
|
64
|
+
urlOptions: this.urlOptions,
|
|
65
|
+
fileMimeType: parameters.data.fileMimeType,
|
|
66
|
+
chunkSize: parameters.data.chunkSize,
|
|
67
|
+
chunkedFileUploadSessionId: parameters.data.chunkedFileUploadSessionId,
|
|
68
|
+
chunkOrdinal: parameters.data.chunkOrdinal,
|
|
69
|
+
numberOfChunks: parameters.data.numberOfChunks,
|
|
70
|
+
chunkBlob: parameters.data.chunkBlob,
|
|
71
|
+
blobStorageProviderName: parameters.data.blobStorageProviderName,
|
|
72
|
+
// optional
|
|
73
|
+
positionOfChunkInQueue: parameters.data.positionOfChunkInQueue,
|
|
74
|
+
successCb: parameters.successCb,
|
|
75
|
+
failureCb: parameters.failureCb,
|
|
76
|
+
progressCb: parameters.progressCb,
|
|
77
|
+
fallbackProperties: parameters.fallbackProperties,
|
|
78
|
+
query: parameters.query
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
request.execute();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @description Sends the commit chunks request to the server
|
|
87
|
+
* @param {CommitChunksRequestOptions} parameters
|
|
88
|
+
* @memberof ChunkUploadSdk
|
|
89
|
+
*/
|
|
90
|
+
commitChunks(parameters: CommitChunksRequestOptions) {
|
|
91
|
+
Guard.isNotNull(parameters, "parameters");
|
|
92
|
+
Guard.isNotNull(parameters.data, "parameters.data");
|
|
93
|
+
Guard.isNotNull(parameters.data.chunkedFileUploadSessionId, "parameters.data.chunkedFileUploadSessionId");
|
|
94
|
+
Guard.isNotNull(parameters.data.contentType, "parameters.data.contentType");
|
|
95
|
+
Guard.isNotNull(parameters.data.name, "parameters.data.name");
|
|
96
|
+
Guard.isNotNull(parameters.data.uploadProperties, "parameters.data.uploadProperties");
|
|
97
|
+
Guard.isNotNull(parameters.data.numberOfChunks, "parameters.data.numberOfChunks");
|
|
98
|
+
Guard.isNotNull(parameters.data.fileTotalSize, "parameters.data.fileTotalSize");
|
|
99
|
+
Guard.isNotNull(parameters.data.blobStorageProviderName, "parameters.data.blobStorageProviderName");
|
|
100
|
+
|
|
101
|
+
const options: CommitChunksRequestOptionsExtended = {
|
|
102
|
+
urlOptions: this.urlOptions,
|
|
103
|
+
chunkedFileUploadSessionId: parameters.data.chunkedFileUploadSessionId,
|
|
104
|
+
contentType: parameters.data.contentType,
|
|
105
|
+
fileName: parameters.data.name,
|
|
106
|
+
uploadProperties: parameters.data.uploadProperties,
|
|
107
|
+
numberOfChunks: parameters.data.numberOfChunks,
|
|
108
|
+
fileTotalSize: parameters.data.fileTotalSize,
|
|
109
|
+
blobStorageProviderName: parameters.data.blobStorageProviderName,
|
|
110
|
+
// Optional: used for update, can be null for create
|
|
111
|
+
itemId: parameters.data.itemId,
|
|
112
|
+
successCb: parameters.successCb,
|
|
113
|
+
failureCb: parameters.failureCb,
|
|
114
|
+
progressCb: parameters.progressCb,
|
|
115
|
+
fallbackProperties: parameters.fallbackProperties,
|
|
116
|
+
query: parameters.query
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const request = this.factory.commitChunks(options);
|
|
120
|
+
request.execute();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @description This request is intended to be used when something in the chunk upload process fails to delete the sent chunks
|
|
125
|
+
* @param {CleanUpChunksRequestOptions} parameters
|
|
126
|
+
* @memberof ChunkUploadSdk
|
|
127
|
+
*/
|
|
128
|
+
cleanUpChunks(parameters: CleanUpChunksRequestOptions) {
|
|
129
|
+
Guard.isNotNull(parameters, "parameters");
|
|
130
|
+
Guard.isNotNull(parameters.data, "parameters.data");
|
|
131
|
+
Guard.isNotNull(parameters.data.chunkedFileUploadSessionId, "parameters.data.chunkedFileUploadSessionId");
|
|
132
|
+
Guard.isNotNull(parameters.data.blobStorageProviderName, "parameters.data.blobStorageProviderName");
|
|
133
|
+
|
|
134
|
+
const request = this.factory.create({
|
|
135
|
+
urlOptions: this.urlOptions,
|
|
136
|
+
action: "Default.CleanUpChunks",
|
|
137
|
+
data: {
|
|
138
|
+
chunkedFileUploadSessionId: parameters.data.chunkedFileUploadSessionId,
|
|
139
|
+
blobStorageProviderName: parameters.data.blobStorageProviderName
|
|
140
|
+
},
|
|
141
|
+
successCb: parameters.successCb,
|
|
142
|
+
failureCb: parameters.failureCb,
|
|
143
|
+
progressCb: parameters.progressCb,
|
|
144
|
+
fallbackProperties: parameters.fallbackProperties,
|
|
145
|
+
query: parameters.query
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
request.execute();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Chunks the provided file. If the file is a base64 string this method will convert it to a blob and then chunk it.
|
|
153
|
+
*
|
|
154
|
+
* @param {(Blob | string)} file
|
|
155
|
+
* @param {number} chunkSize
|
|
156
|
+
* @param {string} contentTypeMime
|
|
157
|
+
* @return {*} {ChunkFileResult}
|
|
158
|
+
* @memberof ChunkUploadService
|
|
159
|
+
*/
|
|
160
|
+
chunkFile(file: Blob | string, chunkSize: number, contentTypeMime: string): ChunkFileResult {
|
|
161
|
+
Guard.isNotNull(file, "file");
|
|
162
|
+
Guard.isNotNull(chunkSize, "chunkSize");
|
|
163
|
+
Guard.isNotNull(contentTypeMime, "contentTypeMime");
|
|
164
|
+
|
|
165
|
+
const utils = new ChunkedFileUploadUtilities();
|
|
166
|
+
return utils.chunkFile(file, chunkSize, contentTypeMime);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
class Guard {
|
|
171
|
+
static isNotNull<T>(value: T, parameterName: string) {
|
|
172
|
+
if (typeof(value) === "number") {
|
|
173
|
+
if (value === null || value === undefined) {
|
|
174
|
+
Guard.throwException(parameterName);
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!value) {
|
|
180
|
+
Guard.throwException(parameterName);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private static throwException(parameterName) {
|
|
185
|
+
throw `parameter ${parameterName} is required.`;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
//#region interfaces
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @description This interface shows the minimum data needed to create a single chunk upload request
|
|
193
|
+
* @export
|
|
194
|
+
* @interface UploadChunkRequestOptions
|
|
195
|
+
* @extends {CreateRequestOptions}
|
|
196
|
+
*/
|
|
197
|
+
export interface UploadChunkRequestOptions extends CreateRequestOptions {
|
|
198
|
+
/**
|
|
199
|
+
* @description the data needed to construct the request
|
|
200
|
+
* @type {{
|
|
201
|
+
* fileMimeType: string;
|
|
202
|
+
* chunkedFileUploadSessionId: string;
|
|
203
|
+
* chunkSize: number;
|
|
204
|
+
* chunkOrdinal: number;
|
|
205
|
+
* numberOfChunks: number;
|
|
206
|
+
* positionOfChunkInQueue?: number;
|
|
207
|
+
* chunkBlob: Blob;
|
|
208
|
+
* blobStorageProviderName: string;
|
|
209
|
+
* }}
|
|
210
|
+
* @memberof UploadChunkRequestOptions
|
|
211
|
+
*/
|
|
212
|
+
data: {
|
|
213
|
+
/**
|
|
214
|
+
* @description the file's mime type
|
|
215
|
+
* @type {string}
|
|
216
|
+
*/
|
|
217
|
+
fileMimeType: string;
|
|
218
|
+
/**
|
|
219
|
+
* @description the current chunk upload session Id
|
|
220
|
+
* @type {string}
|
|
221
|
+
*/
|
|
222
|
+
chunkedFileUploadSessionId: string;
|
|
223
|
+
/**
|
|
224
|
+
* @description the chunk size in bytes
|
|
225
|
+
* @type {number}
|
|
226
|
+
*/
|
|
227
|
+
chunkSize: number;
|
|
228
|
+
/**
|
|
229
|
+
* @description the chunk's ordinal
|
|
230
|
+
* @type {number}
|
|
231
|
+
*/
|
|
232
|
+
chunkOrdinal: number;
|
|
233
|
+
/**
|
|
234
|
+
* @description the total number of chunks
|
|
235
|
+
* @type {number}
|
|
236
|
+
*/
|
|
237
|
+
numberOfChunks: number;
|
|
238
|
+
/**
|
|
239
|
+
* @description Optional. The position of the chunk in the request queue, this property is used to calculate the progress of the upload
|
|
240
|
+
* @type {number}
|
|
241
|
+
*/
|
|
242
|
+
positionOfChunkInQueue?: number;
|
|
243
|
+
/**
|
|
244
|
+
* @description The chunk data
|
|
245
|
+
* @type {Blob}
|
|
246
|
+
*/
|
|
247
|
+
chunkBlob: Blob;
|
|
248
|
+
/**
|
|
249
|
+
* @description the target blob storage provider's name
|
|
250
|
+
* @type {string}
|
|
251
|
+
*/
|
|
252
|
+
blobStorageProviderName: string;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @description This interface shows the minimum data needed to create a commit chunks request
|
|
258
|
+
* @export
|
|
259
|
+
* @interface CommitChunksRequestOptions
|
|
260
|
+
* @extends {CreateRequestOptions}
|
|
261
|
+
*/
|
|
262
|
+
export interface CommitChunksRequestOptions extends CreateRequestOptions {
|
|
263
|
+
/**
|
|
264
|
+
* @description the data needed to construct the request
|
|
265
|
+
* @type {{
|
|
266
|
+
* chunkedFileUploadSessionId: string;
|
|
267
|
+
* contentType: string;
|
|
268
|
+
* fileTotalSize: number;
|
|
269
|
+
* numberOfChunks: number;
|
|
270
|
+
* name: string;
|
|
271
|
+
* blobStorageProviderName: string;
|
|
272
|
+
* uploadProperties: { [key: string]: string };
|
|
273
|
+
* itemId?: string;
|
|
274
|
+
* }}
|
|
275
|
+
* @memberof CommitChunksRequestOptions
|
|
276
|
+
*/
|
|
277
|
+
data: {
|
|
278
|
+
/**
|
|
279
|
+
* @description the current chunk upload session Id
|
|
280
|
+
* @type {string}
|
|
281
|
+
*/
|
|
282
|
+
chunkedFileUploadSessionId: string;
|
|
283
|
+
/**
|
|
284
|
+
* @description the file's mime type
|
|
285
|
+
* @type {string}
|
|
286
|
+
*/
|
|
287
|
+
contentType: string;
|
|
288
|
+
/**
|
|
289
|
+
* @description the total size of the file
|
|
290
|
+
* @type {number}
|
|
291
|
+
*/
|
|
292
|
+
fileTotalSize: number;
|
|
293
|
+
/**
|
|
294
|
+
* @description the total number of chunks
|
|
295
|
+
* @type {number}
|
|
296
|
+
*/
|
|
297
|
+
numberOfChunks: number;
|
|
298
|
+
/**
|
|
299
|
+
* @description the file's name
|
|
300
|
+
* @type {string}
|
|
301
|
+
*/
|
|
302
|
+
name: string;
|
|
303
|
+
/**
|
|
304
|
+
* @description the target blob storage provider's name
|
|
305
|
+
* @type {string}
|
|
306
|
+
*/
|
|
307
|
+
blobStorageProviderName: string;
|
|
308
|
+
/**
|
|
309
|
+
* @description the properties of the uploaded file like the Title, UrlName, etc
|
|
310
|
+
* @type {{ [key: string]: string }}
|
|
311
|
+
*/
|
|
312
|
+
uploadProperties: { [key: string]: string };
|
|
313
|
+
/**
|
|
314
|
+
* @description Optional. Used when updating a media item, can be null when used to create a new media file.
|
|
315
|
+
* @type {string}
|
|
316
|
+
*/
|
|
317
|
+
itemId?: string;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @description This interface shows the minimum data needed to create request to get the chunk upload information for the current library from the server
|
|
323
|
+
* @export
|
|
324
|
+
* @interface GetChunkUploadInfoRequestOptions
|
|
325
|
+
* @extends {CreateRequestOptions}
|
|
326
|
+
*/
|
|
327
|
+
export interface GetChunkUploadInfoRequestOptions extends CreateRequestOptions {
|
|
328
|
+
/**
|
|
329
|
+
* @description the data needed to construct the request
|
|
330
|
+
* @type {{
|
|
331
|
+
* libraryId: string;
|
|
332
|
+
* }}
|
|
333
|
+
* @memberof GetChunkUploadInfoRequestOptions
|
|
334
|
+
*/
|
|
335
|
+
data: {
|
|
336
|
+
/**
|
|
337
|
+
* @description the parent library (not folder) in which the file will be uploaded to
|
|
338
|
+
* @type {string}
|
|
339
|
+
*/
|
|
340
|
+
libraryId: string;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* @description This interface show the minimum data needed to create a request to delete all chunk from a chunk upload session
|
|
346
|
+
* @export
|
|
347
|
+
* @interface CleanUpChunksRequestOptions
|
|
348
|
+
* @extends {CreateRequestOptions}
|
|
349
|
+
*/
|
|
350
|
+
export interface CleanUpChunksRequestOptions extends CreateRequestOptions {
|
|
351
|
+
/**
|
|
352
|
+
* @description the data needed to construct the request
|
|
353
|
+
* @type {{
|
|
354
|
+
* chunkedFileUploadSessionId: string;
|
|
355
|
+
* blobStorageProviderName: string;
|
|
356
|
+
* }}
|
|
357
|
+
* @memberof CleanUpChunksRequestOptions
|
|
358
|
+
*/
|
|
359
|
+
data: {
|
|
360
|
+
/**
|
|
361
|
+
* @description the current chunk upload session Id
|
|
362
|
+
* @type {string}
|
|
363
|
+
*/
|
|
364
|
+
chunkedFileUploadSessionId: string;
|
|
365
|
+
/**
|
|
366
|
+
* @description the target blob storage provider's name
|
|
367
|
+
* @type {string}
|
|
368
|
+
*/
|
|
369
|
+
blobStorageProviderName: string;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* @description This is a data transfer object that shows the information provided by the getChunkUploadInfo request
|
|
375
|
+
* @export
|
|
376
|
+
* @interface ChunkUploadInfoDTO
|
|
377
|
+
*/
|
|
378
|
+
export interface ChunkUploadInfoDTO {
|
|
379
|
+
/**
|
|
380
|
+
* @description shows wether the current blob storage provider supports uploading in chunks
|
|
381
|
+
* @type {boolean}
|
|
382
|
+
* @memberof ChunkUploadInfoDTO
|
|
383
|
+
*/
|
|
384
|
+
ProviderSupportsChunkUpload: boolean;
|
|
385
|
+
/**
|
|
386
|
+
* @description the target blob storage provider's name
|
|
387
|
+
* @type {string}
|
|
388
|
+
* @memberof ChunkUploadInfoDTO
|
|
389
|
+
*/
|
|
390
|
+
BlobStorageProviderName: string;
|
|
391
|
+
/**
|
|
392
|
+
* @description the current chunk upload session Id
|
|
393
|
+
* @type {string}
|
|
394
|
+
* @memberof ChunkUploadInfoDTO
|
|
395
|
+
*/
|
|
396
|
+
ChunkedFileUploadSessionId: string,
|
|
397
|
+
/**
|
|
398
|
+
* @description the chunk size in bytes
|
|
399
|
+
* @type {number}
|
|
400
|
+
* @memberof ChunkUploadInfoDTO
|
|
401
|
+
*/
|
|
402
|
+
ChunkSize: number,
|
|
403
|
+
/**
|
|
404
|
+
* @description the maximum amount of time a chunk should be retired
|
|
405
|
+
* @type {number}
|
|
406
|
+
* @memberof ChunkUploadInfoDTO
|
|
407
|
+
*/
|
|
408
|
+
MaxRetryCountForChunk: number,
|
|
409
|
+
/**
|
|
410
|
+
* @description the maximum simultaneous requests that should be sent to the server
|
|
411
|
+
* @type {number}
|
|
412
|
+
* @memberof ChunkUploadInfoDTO
|
|
413
|
+
*/
|
|
414
|
+
MaxSimultaneousChunkUploadRequestsPerSession: number
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* @description A DTO containing the data that the server responds with when a chunk is uploaded
|
|
419
|
+
* @export
|
|
420
|
+
* @interface ChunkUploadResult
|
|
421
|
+
*/
|
|
422
|
+
export interface ChunkUploadResult {
|
|
423
|
+
/**
|
|
424
|
+
* @description indicates whether the chunk has been successfully uploaded
|
|
425
|
+
* @type {boolean}
|
|
426
|
+
* @memberof ChunkUploadResult
|
|
427
|
+
*/
|
|
428
|
+
SuccessfullyUploaded: boolean,
|
|
429
|
+
/**
|
|
430
|
+
* @description the current chunk upload session Id
|
|
431
|
+
* @type {string}
|
|
432
|
+
* @memberof ChunkUploadResult
|
|
433
|
+
*/
|
|
434
|
+
ChunkedFileUploadSessionId: string
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class ChunkedFileUploadUtilities {
|
|
2
|
+
chunkFile(file: Blob | string, chunkSize: number, contentTypeMime: string): ChunkFileResult {
|
|
3
|
+
let fileInternal: Blob;
|
|
4
|
+
|
|
5
|
+
if (typeof file === "string")
|
|
6
|
+
fileInternal = this.base64ToBlob(file, chunkSize, contentTypeMime);
|
|
7
|
+
else {
|
|
8
|
+
fileInternal = file as Blob;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const fileSize = fileInternal.size;
|
|
12
|
+
const result: Array<FileUploadChunk> = [];
|
|
13
|
+
let chunkOrdinal = 0;
|
|
14
|
+
let offset = 0;
|
|
15
|
+
let currentOffset = chunkSize;
|
|
16
|
+
|
|
17
|
+
while (offset <= fileSize) {
|
|
18
|
+
const chunk = fileInternal.slice(offset, currentOffset, contentTypeMime);
|
|
19
|
+
offset = currentOffset;
|
|
20
|
+
currentOffset = currentOffset + chunkSize;
|
|
21
|
+
|
|
22
|
+
result.push({
|
|
23
|
+
ordinal: chunkOrdinal,
|
|
24
|
+
content: chunk
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
chunkOrdinal++;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
chunks: result,
|
|
32
|
+
totalChunksCount: result.length,
|
|
33
|
+
fileTotalSize: fileSize
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private base64ToBlob(base64String, chunkSize, contentType = ""): Blob {
|
|
38
|
+
const byteCharacters = atob(base64String);
|
|
39
|
+
const byteArrays = [];
|
|
40
|
+
for (let offset = 0; offset < byteCharacters.length; offset += chunkSize) {
|
|
41
|
+
const slice = byteCharacters.slice(offset, offset + chunkSize);
|
|
42
|
+
const byteNumbers = new Array(slice.length);
|
|
43
|
+
for (let i = 0; i < slice.length; i++) {
|
|
44
|
+
byteNumbers[i] = slice.charCodeAt(i);
|
|
45
|
+
}
|
|
46
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
47
|
+
byteArrays.push(byteArray);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const blob = new Blob(byteArrays, { type: contentType });
|
|
51
|
+
return blob;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface FileUploadChunk {
|
|
56
|
+
ordinal: number,
|
|
57
|
+
content: Blob
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ChunkFileResult {
|
|
61
|
+
chunks: Array<FileUploadChunk>,
|
|
62
|
+
totalChunksCount: number,
|
|
63
|
+
fileTotalSize: number
|
|
64
|
+
}
|
package/src/constants.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
export const EXPRESSION_TYPE = {
|
|
2
2
|
query: 1,
|
|
3
3
|
where: 100,
|
|
4
|
-
and:
|
|
5
|
-
or:
|
|
6
|
-
not:
|
|
7
|
-
eq:
|
|
8
|
-
ne:
|
|
9
|
-
lt:
|
|
10
|
-
le:
|
|
11
|
-
gt:
|
|
12
|
-
ge:
|
|
13
|
-
any:
|
|
14
|
-
contains:
|
|
15
|
-
startsWith:
|
|
16
|
-
endsWith:
|
|
17
|
-
}
|
|
4
|
+
and: "and",
|
|
5
|
+
or: "or",
|
|
6
|
+
not: "not",
|
|
7
|
+
eq: "eq",
|
|
8
|
+
ne: "ne",
|
|
9
|
+
lt: "lt",
|
|
10
|
+
le: "le",
|
|
11
|
+
gt: "gt",
|
|
12
|
+
ge: "ge",
|
|
13
|
+
any: "any",
|
|
14
|
+
contains: "contains",
|
|
15
|
+
startsWith: "startsWith",
|
|
16
|
+
endsWith: "endsWith"
|
|
17
|
+
};
|
|
18
18
|
|
|
19
19
|
export const ODATA_PARAMS = {
|
|
20
|
-
$filter:
|
|
21
|
-
$select:
|
|
22
|
-
$expand:
|
|
23
|
-
$orderby:
|
|
24
|
-
$skip:
|
|
25
|
-
$top:
|
|
26
|
-
$count:
|
|
27
|
-
$search:
|
|
28
|
-
}
|
|
20
|
+
$filter: "$filter",
|
|
21
|
+
$select: "$select",
|
|
22
|
+
$expand: "$expand",
|
|
23
|
+
$orderby: "$orderby",
|
|
24
|
+
$skip: "$skip",
|
|
25
|
+
$top: "$top",
|
|
26
|
+
$count: "$count",
|
|
27
|
+
$search: "$search"
|
|
28
|
+
};
|
|
29
29
|
|
|
30
30
|
export const SF_PARAMS = {
|
|
31
|
-
provider:
|
|
32
|
-
culture:
|
|
33
|
-
siteId:
|
|
31
|
+
provider: "sf_provider",
|
|
32
|
+
culture: "sf_culture",
|
|
33
|
+
siteId: "sf_site",
|
|
34
34
|
fallbackParams: "sf_fallback_prop_names",
|
|
35
35
|
parentId: "parentId"
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
37
|
|
|
38
38
|
export const HEADER_NAMES = {
|
|
39
39
|
contentType: "Content-Type",
|
|
@@ -44,8 +44,13 @@ export const HEADER_NAMES = {
|
|
|
44
44
|
fileName: "X-File-Name",
|
|
45
45
|
serviceRequest: "X-SF-Service-Request",
|
|
46
46
|
choicesBinaryRepresentation: "X-SF-Binary-Choice-Representation",
|
|
47
|
-
integrationMode: "X-SF-Integration-Mode"
|
|
48
|
-
|
|
47
|
+
integrationMode: "X-SF-Integration-Mode",
|
|
48
|
+
chunkOrdinal: "X-SF-Chunk-Ordinal",
|
|
49
|
+
chunkSize: "X-SF-Chunk-Size",
|
|
50
|
+
fileSize: "X-SF-File-Size",
|
|
51
|
+
chunkedFileUploadSessionId: "X-SF-Chunked-File-Upload-Session-Id",
|
|
52
|
+
blobStorageProviderName: "X-SF-Blob-Storage-Provider-Name"
|
|
53
|
+
};
|
|
49
54
|
|
|
50
55
|
export const HTTP_METHODS = {
|
|
51
56
|
get: "GET",
|
|
@@ -57,4 +62,4 @@ export const HTTP_METHODS = {
|
|
|
57
62
|
|
|
58
63
|
export const CONTENT_TYPES = {
|
|
59
64
|
json: "application/json"
|
|
60
|
-
}
|
|
65
|
+
};
|
package/src/utils.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export class utils {
|
|
2
2
|
static isString(obj: any): boolean {
|
|
3
|
-
return typeof (obj) ===
|
|
3
|
+
return typeof (obj) === "string" || obj instanceof String;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
static isBoolean(obj: any): boolean {
|
|
7
|
-
return typeof (obj) ===
|
|
7
|
+
return typeof (obj) === "boolean";
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
static isBlob(obj: any): boolean {
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
static isNumber(value: any): boolean {
|
|
15
|
-
return typeof value ===
|
|
15
|
+
return typeof value === "number" && isFinite(value);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
static isFunction(func: any): boolean {
|
|
19
|
-
return typeof func ===
|
|
19
|
+
return typeof func === "function";
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
static serializeToJSON(data): string {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
|
|
71
71
|
static addTrailingSlash(url: string): string {
|
|
72
72
|
url = utils.removeSlashes(url);
|
|
73
|
-
url +=
|
|
73
|
+
url += "/";
|
|
74
74
|
return url;
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
let ret = url;
|
|
79
79
|
|
|
80
80
|
const lastChar = ret.substr(-1);
|
|
81
|
-
if (lastChar ==
|
|
81
|
+
if (lastChar == "/")
|
|
82
82
|
ret = ret.substr(0, ret.length - 1);
|
|
83
83
|
|
|
84
84
|
return ret;
|
|
@@ -89,14 +89,14 @@
|
|
|
89
89
|
to = {};
|
|
90
90
|
|
|
91
91
|
for (const property in from) {
|
|
92
|
-
if (from[property] && from[property].constructor && from[property].constructor === Object && typeof from[property] ==
|
|
93
|
-
to[property] = to[property]|| {
|
|
92
|
+
if (from[property] && from[property].constructor && from[property].constructor === Object && typeof from[property] == "function") {
|
|
93
|
+
to[property] = to[property] || {};
|
|
94
94
|
arguments.callee(to[property], from[property]);
|
|
95
95
|
} else {
|
|
96
96
|
to[property] = from[property];
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
if (typeof action ===
|
|
99
|
+
if (typeof action === "function")
|
|
100
100
|
action(to);
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
|
|
106
106
|
private static _parseDateProperties(data) {
|
|
107
107
|
for (const obj in data) {
|
|
108
|
-
|
|
108
|
+
// TODO
|
|
109
109
|
if (data[obj] instanceof Array || (data[obj] instanceof Object && <any>!data[obj] instanceof Function))
|
|
110
110
|
this._parseDateProperties(data[obj]);
|
|
111
111
|
else
|