@progress/sitefinity-webservices-sdk 1.1.16 → 2.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.
- package/README.md +84 -51
- package/esm/chunks/chunk-2ID24RPE.mjs +179 -0
- package/esm/chunks/chunk-2ID24RPE.mjs.map +7 -0
- package/esm/chunks/chunk-AHDZ2CWQ.mjs +93 -0
- package/esm/chunks/chunk-AHDZ2CWQ.mjs.map +7 -0
- package/esm/chunks/chunk-BFLQBM7R.mjs +136 -0
- package/esm/chunks/chunk-BFLQBM7R.mjs.map +7 -0
- package/esm/chunks/chunk-CMGV26CS.mjs +66 -0
- package/esm/chunks/chunk-CMGV26CS.mjs.map +7 -0
- package/esm/chunks/chunk-DHWDJAGV.mjs +180 -0
- package/esm/chunks/chunk-DHWDJAGV.mjs.map +7 -0
- package/esm/chunks/chunk-EH4CERVO.mjs +82 -0
- package/esm/chunks/chunk-EH4CERVO.mjs.map +7 -0
- package/esm/chunks/chunk-F4CWOE7M.mjs +57 -0
- package/esm/chunks/chunk-F4CWOE7M.mjs.map +7 -0
- package/esm/chunks/chunk-FUFBYOIF.mjs +98 -0
- package/esm/chunks/chunk-FUFBYOIF.mjs.map +7 -0
- package/esm/chunks/chunk-J2B7UDVZ.mjs +132 -0
- package/esm/chunks/chunk-J2B7UDVZ.mjs.map +7 -0
- package/esm/chunks/chunk-L3IMDFA5.mjs +1 -0
- package/esm/chunks/chunk-L3IMDFA5.mjs.map +7 -0
- package/esm/chunks/chunk-NNYY2VBC.mjs +383 -0
- package/esm/chunks/chunk-NNYY2VBC.mjs.map +7 -0
- package/esm/chunks/chunk-PI55MBSL.mjs +256 -0
- package/esm/chunks/chunk-PI55MBSL.mjs.map +7 -0
- package/esm/chunks/chunk-PXPK2IV6.mjs +568 -0
- package/esm/chunks/chunk-PXPK2IV6.mjs.map +7 -0
- package/esm/chunks/chunk-QPSEKUOI.mjs +35 -0
- package/esm/chunks/chunk-QPSEKUOI.mjs.map +7 -0
- package/esm/chunks/chunk-RQAAYOY6.mjs +72 -0
- package/esm/chunks/chunk-RQAAYOY6.mjs.map +7 -0
- package/esm/chunks/chunk-TTVNTTW5.mjs +145 -0
- package/esm/chunks/chunk-TTVNTTW5.mjs.map +7 -0
- package/esm/chunks/chunk-VLDX2FH2.mjs +235 -0
- package/esm/chunks/chunk-VLDX2FH2.mjs.map +7 -0
- package/esm/chunks/chunk-VWT2RJET.mjs +102 -0
- package/esm/chunks/chunk-VWT2RJET.mjs.map +7 -0
- package/esm/chunks/chunk-W2OWM3L7.mjs +19 -0
- package/esm/chunks/chunk-W2OWM3L7.mjs.map +7 -0
- package/esm/chunks/chunk-WX5J7F5D.mjs +43 -0
- package/esm/chunks/chunk-WX5J7F5D.mjs.map +7 -0
- package/esm/chunks/chunk-YB2LMPUX.mjs +54 -0
- package/esm/chunks/chunk-YB2LMPUX.mjs.map +7 -0
- package/package.json +67 -36
- package/sitefinity-webservices-sdk.cjs +2761 -0
- package/sitefinity-webservices-sdk.cjs.map +7 -0
- package/sitefinity-webservices-sdk.d.mts +1 -0
- package/{dist/sitefinity-webservices-sdk.d.ts → sitefinity-webservices-sdk.d.ts} +6 -0
- package/sitefinity-webservices-sdk.global.d.ts +5 -0
- package/sitefinity-webservices-sdk.js +2764 -0
- package/sitefinity-webservices-sdk.js.map +7 -0
- package/sitefinity-webservices-sdk.min.js +3 -0
- package/sitefinity-webservices-sdk.mjs +124 -0
- package/sitefinity-webservices-sdk.mjs.map +7 -0
- package/src/BlobBuilder.d.ts +12 -0
- package/src/Data.d.ts +259 -0
- package/src/Expression.d.ts +37 -0
- package/src/OrderProperty.d.ts +24 -0
- package/src/Query.d.ts +104 -0
- package/src/QueryBase.d.ts +40 -0
- package/src/QueryBuilder.d.ts +29 -0
- package/src/Requests/BatchRequest.d.ts +174 -0
- package/src/Requests/ExecutableRequest.d.ts +43 -0
- package/src/Requests/Request.d.ts +225 -0
- package/src/Requests/RequestBase.d.ts +58 -0
- package/{dist/src → src}/Requests/RequestFactory.d.ts +24 -2
- package/src/Sitefinity.d.ts +141 -0
- package/src/Transport/FetchTransport.d.ts +17 -0
- package/src/Transport/HttpTransport.d.ts +69 -0
- package/src/Transport/XhrTransport.d.ts +8 -0
- package/src/WhereQuery.d.ts +88 -0
- package/src/chunk-upload/chunk-upload.sdk.d.ts +305 -0
- package/src/chunk-upload/chunked-file-upload.utilities.d.ts +58 -0
- package/{dist/src → src}/constants.d.ts +21 -0
- package/src/utils.d.ts +103 -0
- package/.editorconfig +0 -29
- package/.eslintignore +0 -4
- package/.eslintrc.js +0 -40
- package/.github/copilot-instructions.md +0 -72
- package/.github/instructions/sitefinity-webservices-sdk.instructions.md +0 -53
- package/config/helpers.ts +0 -8
- package/config/webpack.common.ts +0 -39
- package/config/webpack.dev.ts +0 -37
- package/config/webpack.prod.ts +0 -17
- package/dist/docs/.nojekyll +0 -1
- package/dist/docs/assets/highlight.css +0 -71
- package/dist/docs/assets/main.js +0 -58
- package/dist/docs/assets/search.js +0 -1
- package/dist/docs/assets/style.css +0 -1280
- package/dist/docs/classes/BlobBuilder.BlobBuilder.html +0 -137
- package/dist/docs/classes/Data.Data.html +0 -387
- package/dist/docs/classes/Expression.BinaryExpression.html +0 -184
- package/dist/docs/classes/Expression.ComplexExpression.html +0 -146
- package/dist/docs/classes/Expression.ExpressionBase.html +0 -125
- package/dist/docs/classes/OrderProperty.OrderProperty.html +0 -151
- package/dist/docs/classes/Query.Query.html +0 -353
- package/dist/docs/classes/QueryBase.QueryBase.html +0 -185
- package/dist/docs/classes/QueryBuilder.QueryBuilder.html +0 -206
- package/dist/docs/classes/Requests_BatchRequest.BatchRequest.html +0 -731
- package/dist/docs/classes/Requests_BatchRequest.Transaction.html +0 -332
- package/dist/docs/classes/Requests_ExecutableRequest.ExecutableRequest.html +0 -340
- package/dist/docs/classes/Requests_Request.CommitChunksRequest.html +0 -303
- package/dist/docs/classes/Requests_Request.CreateRelatedRequest.html +0 -310
- package/dist/docs/classes/Requests_Request.CreateRequest.html +0 -307
- package/dist/docs/classes/Requests_Request.DeleteRelatedByIdRequest.html +0 -309
- package/dist/docs/classes/Requests_Request.DeleteRelatedRequest.html +0 -302
- package/dist/docs/classes/Requests_Request.DeleteRequest.html +0 -298
- package/dist/docs/classes/Requests_Request.GetByIdRequest.html +0 -298
- package/dist/docs/classes/Requests_Request.GetRelatedByIdRequest.html +0 -309
- package/dist/docs/classes/Requests_Request.GetRelatedRequest.html +0 -302
- package/dist/docs/classes/Requests_Request.GetRequest.html +0 -295
- package/dist/docs/classes/Requests_Request.UpdateRequest.html +0 -309
- package/dist/docs/classes/Requests_Request.UploadChunkRequest.html +0 -359
- package/dist/docs/classes/Requests_Request.UploadRequest.html +0 -329
- package/dist/docs/classes/Requests_RequestBase.RequestBase.html +0 -275
- package/dist/docs/classes/Requests_RequestFactory.RequestFactory.html +0 -344
- package/dist/docs/classes/Sitefinity.Sitefinity.html +0 -188
- package/dist/docs/classes/WhereQuery.WhereQuery.html +0 -436
- package/dist/docs/classes/chunk_upload_chunk_upload_sdk.ChunkUploadSdk.html +0 -231
- package/dist/docs/classes/chunk_upload_chunked_file_upload_utilities.ChunkedFileUploadUtilities.html +0 -131
- package/dist/docs/classes/utils.utils.html +0 -303
- package/dist/docs/index.html +0 -129
- package/dist/docs/interfaces/Data.CreateRelatedRequestOptions.html +0 -155
- package/dist/docs/interfaces/Data.CreateRequestOptions.html +0 -153
- package/dist/docs/interfaces/Data.OperationsRequestOptions.html +0 -145
- package/dist/docs/interfaces/Data.PropertyRequestOptions.html +0 -149
- package/dist/docs/interfaces/Data.RequestOptionsBase.html +0 -136
- package/dist/docs/interfaces/Data.SingleRelatedItemRequestOptions.html +0 -155
- package/dist/docs/interfaces/Data.UpdateRequestOptions.html +0 -155
- package/dist/docs/interfaces/Data.UploadRequestOptions.html +0 -169
- package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRelatedRequestOptions.html +0 -161
- package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRequestOptions.html +0 -153
- package/dist/docs/interfaces/Requests_BatchRequest.BatchPropertyRequestOptions.html +0 -153
- package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsBase.html +0 -145
- package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsExtended.html +0 -153
- package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleItemRequestOptions.html +0 -145
- package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleRelatedItemRequestOptions.html +0 -161
- package/dist/docs/interfaces/Requests_BatchRequest.BatchUpdateRequestOptions.html +0 -161
- package/dist/docs/interfaces/Requests_ExecutableRequest.ResponseHandlers.html +0 -98
- package/dist/docs/interfaces/Requests_Request.CommitChunksRequestOptionsExtended.html +0 -215
- package/dist/docs/interfaces/Requests_Request.PostRequestOptionsExtended.html +0 -159
- package/dist/docs/interfaces/Requests_Request.PutRequestOptionsExtended.html +0 -161
- package/dist/docs/interfaces/Requests_Request.RelatedByIdRequestOptionsExtended.html +0 -169
- package/dist/docs/interfaces/Requests_Request.RelatedRequestOptionsExtended.html +0 -163
- package/dist/docs/interfaces/Requests_Request.UploadChunkRequestOptionsExtended.html +0 -217
- package/dist/docs/interfaces/Requests_Request.UploadRequestOptionsExtended.html +0 -180
- package/dist/docs/interfaces/Requests_RequestBase.RequestOptionsBaseExtended.html +0 -148
- package/dist/docs/interfaces/Sitefinity.SDKOptions.html +0 -128
- package/dist/docs/interfaces/Sitefinity.Token.html +0 -94
- package/dist/docs/interfaces/Sitefinity.TypeOptions.html +0 -160
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.ChunkUploadInfoDTO.html +0 -159
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.ChunkUploadResult.html +0 -111
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.CleanUpChunksRequestOptions.html +0 -171
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.CommitChunksRequestOptions.html +0 -204
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.GetChunkUploadInfoRequestOptions.html +0 -166
- package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.UploadChunkRequestOptions.html +0 -206
- package/dist/docs/interfaces/chunk_upload_chunked_file_upload_utilities.ChunkFileResult.html +0 -101
- package/dist/docs/interfaces/chunk_upload_chunked_file_upload_utilities.FileUploadChunk.html +0 -94
- package/dist/docs/modules/BlobBuilder.html +0 -73
- package/dist/docs/modules/Data.html +0 -92
- package/dist/docs/modules/Expression.html +0 -77
- package/dist/docs/modules/OrderProperty.html +0 -73
- package/dist/docs/modules/Query.html +0 -73
- package/dist/docs/modules/QueryBase.html +0 -73
- package/dist/docs/modules/QueryBuilder.html +0 -73
- package/dist/docs/modules/Requests_BatchRequest.html +0 -94
- package/dist/docs/modules/Requests_ExecutableRequest.html +0 -78
- package/dist/docs/modules/Requests_Request.html +0 -114
- package/dist/docs/modules/Requests_RequestBase.html +0 -78
- package/dist/docs/modules/Requests_RequestFactory.html +0 -73
- package/dist/docs/modules/Sitefinity.html +0 -82
- package/dist/docs/modules/WhereQuery.html +0 -73
- package/dist/docs/modules/chunk_upload_chunk_upload_sdk.html +0 -88
- package/dist/docs/modules/chunk_upload_chunked_file_upload_utilities.html +0 -80
- package/dist/docs/modules/constants.html +0 -83
- package/dist/docs/modules/utils.html +0 -73
- package/dist/docs/modules.html +0 -80
- package/dist/docs/variables/constants.CONTENT_TYPES.html +0 -76
- package/dist/docs/variables/constants.EXPRESSION_TYPE.html +0 -106
- package/dist/docs/variables/constants.HEADER_NAMES.html +0 -102
- package/dist/docs/variables/constants.HTTP_METHODS.html +0 -84
- package/dist/docs/variables/constants.ODATA_PARAMS.html +0 -90
- package/dist/docs/variables/constants.SF_PARAMS.html +0 -84
- package/dist/samples.html +0 -625
- package/dist/sitefinity-webservices-sdk.js +0 -3243
- package/dist/sitefinity-webservices-sdk.js.map +0 -1
- package/dist/sitefinity-webservices-sdk.min.js +0 -1
- package/dist/src/BlobBuilder.d.ts +0 -14
- package/dist/src/Data.d.ts +0 -154
- package/dist/src/Data.spec.d.ts +0 -1
- package/dist/src/Expression.d.ts +0 -19
- package/dist/src/OrderProperty.d.ts +0 -8
- package/dist/src/Query.d.ts +0 -59
- package/dist/src/QueryBase.d.ts +0 -18
- package/dist/src/QueryBuilder.d.ts +0 -13
- package/dist/src/Requests/BatchRequest.d.ts +0 -146
- package/dist/src/Requests/ExecutableRequest.d.ts +0 -22
- package/dist/src/Requests/Request.d.ts +0 -132
- package/dist/src/Requests/RequestBase.d.ts +0 -27
- package/dist/src/Requests/request.spec.d.ts +0 -1
- package/dist/src/Sitefinity.d.ts +0 -75
- package/dist/src/Sitefinity.spec.d.ts +0 -1
- package/dist/src/WhereQuery.d.ts +0 -72
- package/dist/src/chunk-upload/chunk-upload.sdk.d.ts +0 -295
- package/dist/src/chunk-upload/chunk-upload.sdk.spec.d.ts +0 -1
- package/dist/src/chunk-upload/chunked-file-upload.utilities.d.ts +0 -13
- package/dist/src/utils.d.ts +0 -16
- package/karma.conf.js +0 -29
- package/sitefinity-webservices-sdk.ts +0 -15
- package/src/BlobBuilder.ts +0 -20
- package/src/Data.spec.ts +0 -160
- package/src/Data.ts +0 -418
- package/src/Expression.ts +0 -36
- package/src/OrderProperty.ts +0 -39
- package/src/Query.ts +0 -106
- package/src/QueryBase.ts +0 -57
- package/src/QueryBuilder.ts +0 -180
- package/src/Requests/BatchRequest.ts +0 -807
- package/src/Requests/ExecutableRequest.ts +0 -117
- package/src/Requests/Request.ts +0 -327
- package/src/Requests/RequestBase.ts +0 -163
- package/src/Requests/RequestFactory.ts +0 -75
- package/src/Requests/request.spec.ts +0 -154
- package/src/Sitefinity.spec.ts +0 -483
- package/src/Sitefinity.ts +0 -125
- package/src/WhereQuery.ts +0 -145
- package/src/chunk-upload/chunk-upload.sdk.spec.ts +0 -347
- package/src/chunk-upload/chunk-upload.sdk.ts +0 -439
- package/src/chunk-upload/chunked-file-upload.utilities.ts +0 -64
- package/src/constants.ts +0 -66
- package/src/utils.ts +0 -125
- package/template.html +0 -625
- package/tsconfig.json +0 -38
|
@@ -0,0 +1,2764 @@
|
|
|
1
|
+
/*! @progress/sitefinity-webservices-sdk v2.0.0 | MIT */
|
|
2
|
+
var Sitefinity = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// sitefinity-webservices-sdk.ts
|
|
22
|
+
var sitefinity_webservices_sdk_exports = {};
|
|
23
|
+
__export(sitefinity_webservices_sdk_exports, {
|
|
24
|
+
BatchRequest: () => BatchRequest,
|
|
25
|
+
BinaryExpression: () => BinaryExpression,
|
|
26
|
+
BlobBuilder: () => BlobBuilder,
|
|
27
|
+
CONTENT_TYPES: () => CONTENT_TYPES,
|
|
28
|
+
ChunkUploadSdk: () => ChunkUploadSdk,
|
|
29
|
+
ChunkedFileUploadUtilities: () => ChunkedFileUploadUtilities,
|
|
30
|
+
CommitChunksRequest: () => CommitChunksRequest,
|
|
31
|
+
ComplexExpression: () => ComplexExpression,
|
|
32
|
+
CreateRelatedRequest: () => CreateRelatedRequest,
|
|
33
|
+
CreateRequest: () => CreateRequest,
|
|
34
|
+
Data: () => Data,
|
|
35
|
+
DeleteRelatedByIdRequest: () => DeleteRelatedByIdRequest,
|
|
36
|
+
DeleteRelatedRequest: () => DeleteRelatedRequest,
|
|
37
|
+
DeleteRequest: () => DeleteRequest,
|
|
38
|
+
EXPRESSION_TYPE: () => EXPRESSION_TYPE,
|
|
39
|
+
ExecutableRequest: () => ExecutableRequest,
|
|
40
|
+
ExpressionBase: () => ExpressionBase,
|
|
41
|
+
FetchTransport: () => FetchTransport,
|
|
42
|
+
GetByIdRequest: () => GetByIdRequest,
|
|
43
|
+
GetRelatedByIdRequest: () => GetRelatedByIdRequest,
|
|
44
|
+
GetRelatedRequest: () => GetRelatedRequest,
|
|
45
|
+
GetRequest: () => GetRequest,
|
|
46
|
+
HEADER_NAMES: () => HEADER_NAMES,
|
|
47
|
+
HTTP_METHODS: () => HTTP_METHODS,
|
|
48
|
+
ODATA_PARAMS: () => ODATA_PARAMS,
|
|
49
|
+
OrderProperty: () => OrderProperty,
|
|
50
|
+
Query: () => Query,
|
|
51
|
+
QueryBase: () => QueryBase,
|
|
52
|
+
QueryBuilder: () => QueryBuilder,
|
|
53
|
+
RequestBase: () => RequestBase,
|
|
54
|
+
RequestFactory: () => RequestFactory,
|
|
55
|
+
SF_PARAMS: () => SF_PARAMS,
|
|
56
|
+
Sitefinity: () => Sitefinity,
|
|
57
|
+
Transaction: () => Transaction,
|
|
58
|
+
UpdateRequest: () => UpdateRequest,
|
|
59
|
+
UploadChunkRequest: () => UploadChunkRequest,
|
|
60
|
+
UploadRequest: () => UploadRequest,
|
|
61
|
+
WhereQuery: () => WhereQuery,
|
|
62
|
+
XhrTransport: () => XhrTransport,
|
|
63
|
+
utils: () => utils
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// src/BlobBuilder.ts
|
|
67
|
+
var BlobBuilder = class {
|
|
68
|
+
constructor() {
|
|
69
|
+
this.blob = new Blob();
|
|
70
|
+
}
|
|
71
|
+
/** Appends a value to the blob being built. */
|
|
72
|
+
append(value) {
|
|
73
|
+
this.blob = new Blob([this.blob, value]);
|
|
74
|
+
}
|
|
75
|
+
/** Returns the accumulated blob content. */
|
|
76
|
+
build() {
|
|
77
|
+
return this.blob;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/constants.ts
|
|
82
|
+
var EXPRESSION_TYPE = {
|
|
83
|
+
query: 1,
|
|
84
|
+
where: 100,
|
|
85
|
+
and: "and",
|
|
86
|
+
or: "or",
|
|
87
|
+
not: "not",
|
|
88
|
+
eq: "eq",
|
|
89
|
+
ne: "ne",
|
|
90
|
+
lt: "lt",
|
|
91
|
+
le: "le",
|
|
92
|
+
gt: "gt",
|
|
93
|
+
ge: "ge",
|
|
94
|
+
any: "any",
|
|
95
|
+
in: "in",
|
|
96
|
+
contains: "contains",
|
|
97
|
+
startsWith: "startsWith",
|
|
98
|
+
endsWith: "endsWith"
|
|
99
|
+
};
|
|
100
|
+
var ODATA_PARAMS = {
|
|
101
|
+
$filter: "$filter",
|
|
102
|
+
$select: "$select",
|
|
103
|
+
$expand: "$expand",
|
|
104
|
+
$orderby: "$orderby",
|
|
105
|
+
$skip: "$skip",
|
|
106
|
+
$top: "$top",
|
|
107
|
+
$count: "$count",
|
|
108
|
+
$search: "$search"
|
|
109
|
+
};
|
|
110
|
+
var SF_PARAMS = {
|
|
111
|
+
provider: "sf_provider",
|
|
112
|
+
culture: "sf_culture",
|
|
113
|
+
siteId: "sf_site",
|
|
114
|
+
fallbackParams: "sf_fallback_prop_names",
|
|
115
|
+
parentId: "parentId"
|
|
116
|
+
};
|
|
117
|
+
var HEADER_NAMES = {
|
|
118
|
+
contentType: "Content-Type",
|
|
119
|
+
authorization: "Authorization",
|
|
120
|
+
contentEncoding: "Content-Encoding",
|
|
121
|
+
operation: "X-Operation",
|
|
122
|
+
properties: "X-Sf-Properties",
|
|
123
|
+
fileName: "X-File-Name",
|
|
124
|
+
serviceRequest: "X-SF-Service-Request",
|
|
125
|
+
choicesBinaryRepresentation: "X-SF-Binary-Choice-Representation",
|
|
126
|
+
integrationMode: "X-SF-Integration-Mode",
|
|
127
|
+
chunkOrdinal: "X-SF-Chunk-Ordinal",
|
|
128
|
+
chunkSize: "X-SF-Chunk-Size",
|
|
129
|
+
fileSize: "X-SF-File-Size",
|
|
130
|
+
chunkedFileUploadSessionId: "X-SF-Chunked-File-Upload-Session-Id",
|
|
131
|
+
blobStorageProviderName: "X-SF-Blob-Storage-Provider-Name"
|
|
132
|
+
};
|
|
133
|
+
var HTTP_METHODS = {
|
|
134
|
+
get: "GET",
|
|
135
|
+
put: "PUT",
|
|
136
|
+
post: "POST",
|
|
137
|
+
patch: "PATCH",
|
|
138
|
+
delete: "DELETE"
|
|
139
|
+
};
|
|
140
|
+
var CONTENT_TYPES = {
|
|
141
|
+
json: "application/json"
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/utils.ts
|
|
145
|
+
var utils = class _utils {
|
|
146
|
+
/**
|
|
147
|
+
* Determines whether a value is a primitive or boxed string.
|
|
148
|
+
*
|
|
149
|
+
* @param obj Value to inspect.
|
|
150
|
+
* @returns `true` when the value is a string.
|
|
151
|
+
*/
|
|
152
|
+
static isString(obj) {
|
|
153
|
+
return typeof obj === "string" || obj instanceof String;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Determines whether a value is a boolean.
|
|
157
|
+
*
|
|
158
|
+
* @param obj Value to inspect.
|
|
159
|
+
* @returns `true` for primitive boolean values.
|
|
160
|
+
*/
|
|
161
|
+
static isBoolean(obj) {
|
|
162
|
+
return typeof obj === "boolean";
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Determines whether a value is a {@link Blob}.
|
|
166
|
+
*
|
|
167
|
+
* @param obj Value to inspect.
|
|
168
|
+
* @returns `true` when the value is a `Blob`.
|
|
169
|
+
*/
|
|
170
|
+
static isBlob(obj) {
|
|
171
|
+
return obj instanceof Blob;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Determines whether a value is a finite number.
|
|
175
|
+
*
|
|
176
|
+
* @param value Value to inspect.
|
|
177
|
+
* @returns `true` for finite numeric values.
|
|
178
|
+
*/
|
|
179
|
+
static isNumber(value) {
|
|
180
|
+
return typeof value === "number" && isFinite(value);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Determines whether a value is callable.
|
|
184
|
+
*
|
|
185
|
+
* @param func Value to inspect.
|
|
186
|
+
* @returns `true` when the value is a function.
|
|
187
|
+
*/
|
|
188
|
+
static isFunction(func) {
|
|
189
|
+
return typeof func === "function";
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Converts request data to its wire representation.
|
|
193
|
+
*
|
|
194
|
+
* Strings and blobs are returned unchanged. Other values are serialized with `JSON.stringify`.
|
|
195
|
+
*
|
|
196
|
+
* @param data Request body value.
|
|
197
|
+
* @returns The original string or blob, or a JSON string for other values.
|
|
198
|
+
*/
|
|
199
|
+
static serializeToJSON(data) {
|
|
200
|
+
if (!_utils.isString(data) && !this.isBlob(data)) {
|
|
201
|
+
return JSON.stringify(data);
|
|
202
|
+
}
|
|
203
|
+
return data;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Parses a response string as a number or JSON value.
|
|
207
|
+
*
|
|
208
|
+
* ISO 8601 date strings in parsed objects and arrays are converted to {@link Date} instances.
|
|
209
|
+
* Non-JSON text returns `null`.
|
|
210
|
+
*
|
|
211
|
+
* @param data Response text to parse.
|
|
212
|
+
* @returns The parsed value, or `null` when the input is empty or not valid JSON.
|
|
213
|
+
*/
|
|
214
|
+
static parseStringToJson(data) {
|
|
215
|
+
if (!data) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const number = Number(data);
|
|
219
|
+
if (!isNaN(number)) {
|
|
220
|
+
return number;
|
|
221
|
+
}
|
|
222
|
+
let result = null;
|
|
223
|
+
try {
|
|
224
|
+
result = JSON.parse(data);
|
|
225
|
+
result = _utils._parseDateProperties(result);
|
|
226
|
+
} catch (e) {
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Converts top-level {@link Date} properties to ISO 8601 strings in place.
|
|
232
|
+
*
|
|
233
|
+
* @param data Object that will be sent in a request.
|
|
234
|
+
* @returns The same object instance after conversion.
|
|
235
|
+
*/
|
|
236
|
+
static convertDateFieldToISOString(data) {
|
|
237
|
+
for (const obj in data) {
|
|
238
|
+
if (data[obj] instanceof Date) {
|
|
239
|
+
data[obj] = data[obj].toISOString();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return data;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Generates a four-character hexadecimal segment.
|
|
246
|
+
*
|
|
247
|
+
* @returns A pseudo-random lowercase hexadecimal string.
|
|
248
|
+
*/
|
|
249
|
+
static hex16() {
|
|
250
|
+
return Math.floor((1 + Math.random()) * 65536).toString(16).substr(1);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Ensures that a URL ends with exactly one slash.
|
|
254
|
+
*
|
|
255
|
+
* @param url URL to normalize.
|
|
256
|
+
* @returns The normalized URL.
|
|
257
|
+
*/
|
|
258
|
+
static addTrailingSlash(url) {
|
|
259
|
+
url = _utils.removeSlashes(url);
|
|
260
|
+
url += "/";
|
|
261
|
+
return url;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Removes one trailing slash from a URL.
|
|
265
|
+
*
|
|
266
|
+
* @param url URL to normalize.
|
|
267
|
+
* @returns The URL without a trailing slash.
|
|
268
|
+
*/
|
|
269
|
+
static removeSlashes(url) {
|
|
270
|
+
let ret = url;
|
|
271
|
+
const lastChar = ret.substr(-1);
|
|
272
|
+
if (lastChar == "/")
|
|
273
|
+
ret = ret.substr(0, ret.length - 1);
|
|
274
|
+
return ret;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Performs the SDK's backward-compatible shallow clone operation.
|
|
278
|
+
*
|
|
279
|
+
* The optional action is called while properties are copied and is used by fluent query
|
|
280
|
+
* objects to update the cloned instance.
|
|
281
|
+
*
|
|
282
|
+
* @param from Source object.
|
|
283
|
+
* @param to Optional target object.
|
|
284
|
+
* @param action Optional callback invoked with the target during copying.
|
|
285
|
+
* @returns The populated target object.
|
|
286
|
+
*/
|
|
287
|
+
static clone(from, to = {}, action = null) {
|
|
288
|
+
if (!to)
|
|
289
|
+
to = {};
|
|
290
|
+
for (const property in from) {
|
|
291
|
+
if (from[property] && from[property].constructor && from[property].constructor === Object && typeof from[property] == "function") {
|
|
292
|
+
to[property] = to[property] || {};
|
|
293
|
+
arguments.callee(to[property], from[property]);
|
|
294
|
+
} else {
|
|
295
|
+
to[property] = from[property];
|
|
296
|
+
}
|
|
297
|
+
if (typeof action === "function")
|
|
298
|
+
action(to);
|
|
299
|
+
}
|
|
300
|
+
return to;
|
|
301
|
+
}
|
|
302
|
+
static _parseDateProperties(data) {
|
|
303
|
+
for (const obj in data) {
|
|
304
|
+
if (data[obj] instanceof Array || data[obj] instanceof Object && !(data[obj] instanceof Function))
|
|
305
|
+
this._parseDateProperties(data[obj]);
|
|
306
|
+
else
|
|
307
|
+
data[obj] = _utils._tryFormatFieldToDate(data[obj]);
|
|
308
|
+
}
|
|
309
|
+
return data;
|
|
310
|
+
}
|
|
311
|
+
static _tryFormatFieldToDate(date) {
|
|
312
|
+
if (/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/.test(date)) {
|
|
313
|
+
date = new Date(date);
|
|
314
|
+
}
|
|
315
|
+
return date;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// src/Expression.ts
|
|
320
|
+
var ExpressionBase = class {
|
|
321
|
+
/** Creates an expression node with the specified operator or logical type. */
|
|
322
|
+
constructor(type) {
|
|
323
|
+
this.type = type;
|
|
324
|
+
}
|
|
325
|
+
/** Returns this expression's operator or logical type. */
|
|
326
|
+
getType() {
|
|
327
|
+
return this.type;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
var BinaryExpression = class extends ExpressionBase {
|
|
331
|
+
/**
|
|
332
|
+
* Creates a comparison expression.
|
|
333
|
+
*
|
|
334
|
+
* @param type Supported comparison operator, such as `eq`, `ne`, or `contains`.
|
|
335
|
+
* @param parameter Property being tested.
|
|
336
|
+
* @param constant Value compared with the property.
|
|
337
|
+
* @param caseSensitive Whether string functions should preserve case.
|
|
338
|
+
*/
|
|
339
|
+
constructor(type, parameter, constant, caseSensitive = true) {
|
|
340
|
+
super(type);
|
|
341
|
+
this.parameter = parameter;
|
|
342
|
+
this.constant = constant;
|
|
343
|
+
this.caseSensitive = caseSensitive;
|
|
344
|
+
}
|
|
345
|
+
/** Returns the property being compared. */
|
|
346
|
+
getParameter() {
|
|
347
|
+
return this.parameter;
|
|
348
|
+
}
|
|
349
|
+
/** Returns the comparison value. */
|
|
350
|
+
getConstant() {
|
|
351
|
+
return this.constant;
|
|
352
|
+
}
|
|
353
|
+
/** Returns whether string matching preserves case. */
|
|
354
|
+
isCaseSensitive() {
|
|
355
|
+
return this.caseSensitive;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
var ComplexExpression = class extends ExpressionBase {
|
|
359
|
+
/** Creates a logical expression containing the supplied child nodes. */
|
|
360
|
+
constructor(type, expressions) {
|
|
361
|
+
super(type);
|
|
362
|
+
this.expressions = expressions;
|
|
363
|
+
}
|
|
364
|
+
/** Returns the child expressions in their current order. */
|
|
365
|
+
getExpressions() {
|
|
366
|
+
return this.expressions;
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// src/WhereQuery.ts
|
|
371
|
+
var WhereQuery = class _WhereQuery {
|
|
372
|
+
/** Creates a logical group attached to the supplied parent. */
|
|
373
|
+
constructor(parent, type = EXPRESSION_TYPE.and) {
|
|
374
|
+
this.parent = parent;
|
|
375
|
+
this.expression = new ComplexExpression(type, []);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Starts a nested `and` group.
|
|
379
|
+
* @returns A nested builder whose `done()` returns this group.
|
|
380
|
+
*/
|
|
381
|
+
and() {
|
|
382
|
+
return new _WhereQuery(this, EXPRESSION_TYPE.and);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Starts a nested `or` group.
|
|
386
|
+
* @returns A nested builder whose `done()` returns this group.
|
|
387
|
+
*/
|
|
388
|
+
or() {
|
|
389
|
+
return new _WhereQuery(this, EXPRESSION_TYPE.or);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Starts an OData `any` group for collection-valued properties.
|
|
393
|
+
* @returns A nested builder whose `done()` returns this group.
|
|
394
|
+
*/
|
|
395
|
+
any() {
|
|
396
|
+
return new _WhereQuery(this, EXPRESSION_TYPE.any);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Starts a negated group.
|
|
400
|
+
* @returns A nested builder whose `done()` returns this group.
|
|
401
|
+
* @throws Error If more than one direct condition is added to the group.
|
|
402
|
+
*/
|
|
403
|
+
not() {
|
|
404
|
+
return new _WhereQuery(this, EXPRESSION_TYPE.not);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Adds an equality condition.
|
|
408
|
+
* @param parameter Property name.
|
|
409
|
+
* @param constant Value to compare with.
|
|
410
|
+
* @returns This filter builder.
|
|
411
|
+
*/
|
|
412
|
+
eq(parameter, constant) {
|
|
413
|
+
return this.simple(EXPRESSION_TYPE.eq, parameter, constant);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Adds an inequality condition.
|
|
417
|
+
* @param parameter Property name.
|
|
418
|
+
* @param constant Value to compare with.
|
|
419
|
+
* @returns This filter builder.
|
|
420
|
+
*/
|
|
421
|
+
ne(parameter, constant) {
|
|
422
|
+
return this.simple(EXPRESSION_TYPE.ne, parameter, constant);
|
|
423
|
+
}
|
|
424
|
+
/** Adds a greater-than condition for number, string, or date values. */
|
|
425
|
+
gt(parameter, constant) {
|
|
426
|
+
return this.simple(EXPRESSION_TYPE.gt, parameter, constant);
|
|
427
|
+
}
|
|
428
|
+
/** Adds a greater-than-or-equal condition for number, string, or date values. */
|
|
429
|
+
gte(parameter, constant) {
|
|
430
|
+
return this.simple(EXPRESSION_TYPE.ge, parameter, constant);
|
|
431
|
+
}
|
|
432
|
+
/** Adds a less-than condition for number, string, or date values. */
|
|
433
|
+
lt(parameter, constant) {
|
|
434
|
+
return this.simple(EXPRESSION_TYPE.lt, parameter, constant);
|
|
435
|
+
}
|
|
436
|
+
/** Adds a less-than-or-equal condition for number, string, or date values. */
|
|
437
|
+
lte(parameter, constant) {
|
|
438
|
+
return this.simple(EXPRESSION_TYPE.le, parameter, constant);
|
|
439
|
+
}
|
|
440
|
+
/** Adds a string-prefix condition, optionally using case-insensitive matching. */
|
|
441
|
+
startsWith(parameter, constant, caseSensitive = true) {
|
|
442
|
+
return this.simple(EXPRESSION_TYPE.startsWith, parameter, constant, caseSensitive);
|
|
443
|
+
}
|
|
444
|
+
/** Adds a string-contains condition, optionally using case-insensitive matching. */
|
|
445
|
+
contains(parameter, constant, caseSensitive = true) {
|
|
446
|
+
return this.simple(EXPRESSION_TYPE.contains, parameter, constant, caseSensitive);
|
|
447
|
+
}
|
|
448
|
+
/** Adds a string-suffix condition, optionally using case-insensitive matching. */
|
|
449
|
+
endsWith(parameter, constant, caseSensitive = true) {
|
|
450
|
+
return this.simple(EXPRESSION_TYPE.endsWith, parameter, constant, caseSensitive);
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Adds an OData `in` condition.
|
|
454
|
+
*
|
|
455
|
+
* The constant must be an array; otherwise `build()` throws an error.
|
|
456
|
+
*/
|
|
457
|
+
in(parameter, constant) {
|
|
458
|
+
return this.simple(EXPRESSION_TYPE.in, parameter, constant);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Completes this group and returns its parent.
|
|
462
|
+
*
|
|
463
|
+
* Call once for the root filter to return to `Query`, and once for each
|
|
464
|
+
* nested group to continue the surrounding chain.
|
|
465
|
+
*
|
|
466
|
+
* @returns The parent query or enclosing filter group.
|
|
467
|
+
*/
|
|
468
|
+
done() {
|
|
469
|
+
if (this.parent instanceof _WhereQuery) {
|
|
470
|
+
this.parent.addComplexExpression(this);
|
|
471
|
+
if (this.expression.getType() === EXPRESSION_TYPE.not)
|
|
472
|
+
return this.parent;
|
|
473
|
+
}
|
|
474
|
+
return this.parent;
|
|
475
|
+
}
|
|
476
|
+
/** Returns the expression tree represented by this filter group. */
|
|
477
|
+
getExpression() {
|
|
478
|
+
return this.expression;
|
|
479
|
+
}
|
|
480
|
+
simple(type, parameter, constant, caseSensitive = true) {
|
|
481
|
+
const currentExpr = new BinaryExpression(type, parameter, constant, caseSensitive);
|
|
482
|
+
const subExpressions = this.expression.getExpressions();
|
|
483
|
+
subExpressions.push(currentExpr);
|
|
484
|
+
if (this.expression.getType() === EXPRESSION_TYPE.not && subExpressions.length > 1)
|
|
485
|
+
throw new Error("Invalid operators count!");
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
addComplexExpression(subQuery) {
|
|
489
|
+
const subExpression = subQuery.getExpression();
|
|
490
|
+
this.expression.getExpressions().push(subExpression);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// src/Requests/RequestBase.ts
|
|
495
|
+
var RequestBase = class {
|
|
496
|
+
/**
|
|
497
|
+
* Creates a low-level request from its URL, query, callback, and entity options.
|
|
498
|
+
*
|
|
499
|
+
* @param options Request options used to build and execute the request.
|
|
500
|
+
*/
|
|
501
|
+
constructor(options) {
|
|
502
|
+
this.successCb = options.successCb;
|
|
503
|
+
this.failureCb = options.failureCb;
|
|
504
|
+
this.progressCb = options.progressCb;
|
|
505
|
+
this.urlOptions = options.urlOptions;
|
|
506
|
+
this.key = options.key;
|
|
507
|
+
this.action = options.action;
|
|
508
|
+
this.fallbackProperties = options.fallbackProperties;
|
|
509
|
+
this.query = options.query;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Builds the encoded OData and Sitefinity query string for the request.
|
|
513
|
+
*
|
|
514
|
+
* @param urlOptions URL options whose provider, culture, site, and extra parameters are included.
|
|
515
|
+
* @param query OData query options to include.
|
|
516
|
+
* @returns A query string beginning with `?`, or `null` when no parameters apply.
|
|
517
|
+
*/
|
|
518
|
+
getQueryString(urlOptions, query) {
|
|
519
|
+
const paramDictionary = {};
|
|
520
|
+
this.getQueryParameters(paramDictionary, urlOptions, query);
|
|
521
|
+
const keys = Object.keys(paramDictionary);
|
|
522
|
+
if (keys.length == 0)
|
|
523
|
+
return null;
|
|
524
|
+
let queryString = "?";
|
|
525
|
+
for (const prop in paramDictionary) {
|
|
526
|
+
queryString += prop + "=" + paramDictionary[prop] + "&";
|
|
527
|
+
}
|
|
528
|
+
queryString = queryString.substring(0, queryString.length - 1);
|
|
529
|
+
return queryString;
|
|
530
|
+
}
|
|
531
|
+
/** Returns the request body. Subclasses override this for requests with content. */
|
|
532
|
+
getBody() {
|
|
533
|
+
return void 0;
|
|
534
|
+
}
|
|
535
|
+
/** Returns the HTTP method used by the request. */
|
|
536
|
+
getMethod() {
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
/** Returns the headers used by the request, including a JSON content type by default. */
|
|
540
|
+
getHeaders() {
|
|
541
|
+
const headers = this.urlOptions.additionalHeaders ?? {};
|
|
542
|
+
if (headers[HEADER_NAMES.contentType] == void 0) {
|
|
543
|
+
headers[HEADER_NAMES.contentType] = CONTENT_TYPES.json;
|
|
544
|
+
}
|
|
545
|
+
return headers;
|
|
546
|
+
}
|
|
547
|
+
/** Builds the request URL, including the entity key, action, count path, and query string. */
|
|
548
|
+
buildUrl() {
|
|
549
|
+
let url = this.urlOptions.baseUrl + (this.urlOptions.entitySet || "");
|
|
550
|
+
url += this.key !== void 0 && this.key !== null ? "(" + this.key + ")" : "";
|
|
551
|
+
if (this.action) {
|
|
552
|
+
url += url.endsWith("/") ? "" : "/";
|
|
553
|
+
url += this.action;
|
|
554
|
+
}
|
|
555
|
+
if (this.query) {
|
|
556
|
+
const getCount = this.query.build().$count;
|
|
557
|
+
if (utils.isBoolean(getCount) && !getCount) {
|
|
558
|
+
url += "/$count";
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return this.addQueryParameters(url);
|
|
562
|
+
}
|
|
563
|
+
parseResponse(response) {
|
|
564
|
+
const data = utils.parseStringToJson(response.body);
|
|
565
|
+
if (data) {
|
|
566
|
+
if (response.status >= 400 && data.error) {
|
|
567
|
+
return data.error;
|
|
568
|
+
}
|
|
569
|
+
return data;
|
|
570
|
+
}
|
|
571
|
+
return response.body;
|
|
572
|
+
}
|
|
573
|
+
addQueryParameters(url) {
|
|
574
|
+
let queryString = this.getQueryString(this.urlOptions, this.query);
|
|
575
|
+
if (queryString) {
|
|
576
|
+
if (url.indexOf("?") > -1 && queryString[0] == "?") {
|
|
577
|
+
queryString = "&" + queryString.substring(1);
|
|
578
|
+
}
|
|
579
|
+
url += queryString;
|
|
580
|
+
}
|
|
581
|
+
return url;
|
|
582
|
+
}
|
|
583
|
+
getQueryParameters(paramDictionary, urlOptions, query) {
|
|
584
|
+
if (query) {
|
|
585
|
+
const builtQuery = query.build();
|
|
586
|
+
if (utils.isString(builtQuery.$filter))
|
|
587
|
+
paramDictionary[ODATA_PARAMS.$filter] = builtQuery.$filter;
|
|
588
|
+
if (utils.isString(builtQuery.$select))
|
|
589
|
+
paramDictionary[ODATA_PARAMS.$select] = builtQuery.$select;
|
|
590
|
+
if (utils.isString(builtQuery.$expand))
|
|
591
|
+
paramDictionary[ODATA_PARAMS.$expand] = builtQuery.$expand;
|
|
592
|
+
if (utils.isString(builtQuery.$orderby))
|
|
593
|
+
paramDictionary[ODATA_PARAMS.$orderby] = builtQuery.$orderby;
|
|
594
|
+
if (utils.isNumber(builtQuery.$skip))
|
|
595
|
+
paramDictionary[ODATA_PARAMS.$skip] = builtQuery.$skip;
|
|
596
|
+
if (utils.isNumber(builtQuery.$top))
|
|
597
|
+
paramDictionary[ODATA_PARAMS.$top] = builtQuery.$top;
|
|
598
|
+
if (utils.isString(builtQuery.$search))
|
|
599
|
+
paramDictionary[ODATA_PARAMS.$search] = builtQuery.$search;
|
|
600
|
+
if (utils.isBoolean(builtQuery.$count) && builtQuery.$count)
|
|
601
|
+
paramDictionary[ODATA_PARAMS.$count] = builtQuery.$count;
|
|
602
|
+
}
|
|
603
|
+
if (urlOptions.provider) {
|
|
604
|
+
paramDictionary[SF_PARAMS.provider] = urlOptions.provider;
|
|
605
|
+
}
|
|
606
|
+
if (urlOptions.culture) {
|
|
607
|
+
paramDictionary[SF_PARAMS.culture] = urlOptions.culture;
|
|
608
|
+
}
|
|
609
|
+
if (urlOptions.siteId) {
|
|
610
|
+
paramDictionary[SF_PARAMS.siteId] = urlOptions.siteId;
|
|
611
|
+
}
|
|
612
|
+
if (this.fallbackProperties) {
|
|
613
|
+
paramDictionary[SF_PARAMS.fallbackParams] = this.fallbackProperties.join();
|
|
614
|
+
}
|
|
615
|
+
if (urlOptions.additionalQueryParams) {
|
|
616
|
+
for (const key in urlOptions.additionalQueryParams) {
|
|
617
|
+
if (urlOptions.additionalQueryParams.hasOwnProperty(key)) {
|
|
618
|
+
paramDictionary[key] = urlOptions.additionalQueryParams[key];
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// src/Transport/XhrTransport.ts
|
|
626
|
+
var XMLHttpRequestDone = 4;
|
|
627
|
+
var XhrTransport = class {
|
|
628
|
+
/** Sends the request with a new `XMLHttpRequest` and reports its final state. */
|
|
629
|
+
send(request, onComplete) {
|
|
630
|
+
const xhr = new XMLHttpRequest();
|
|
631
|
+
xhr.onreadystatechange = () => {
|
|
632
|
+
if (xhr.readyState === XMLHttpRequestDone) {
|
|
633
|
+
onComplete({
|
|
634
|
+
status: xhr.status,
|
|
635
|
+
body: xhr.responseText,
|
|
636
|
+
// Parsed on demand: only $batch reads the headers, and minimal XHR fakes may not implement them.
|
|
637
|
+
get headers() {
|
|
638
|
+
return parseResponseHeaders(xhr.getAllResponseHeaders());
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
if (request.onUploadProgress && xhr.upload) {
|
|
644
|
+
xhr.upload.onprogress = request.onUploadProgress;
|
|
645
|
+
}
|
|
646
|
+
xhr.open(request.method, request.url, true);
|
|
647
|
+
for (const name of Object.keys(request.headers)) {
|
|
648
|
+
xhr.setRequestHeader(name, request.headers[name]);
|
|
649
|
+
}
|
|
650
|
+
xhr.send(request.body);
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
function parseResponseHeaders(raw) {
|
|
654
|
+
const headers = {};
|
|
655
|
+
for (const line of (raw ?? "").split(/\r?\n/)) {
|
|
656
|
+
const separator = line.indexOf(":");
|
|
657
|
+
if (separator > 0) {
|
|
658
|
+
headers[line.substring(0, separator).trim().toLowerCase()] = line.substring(separator + 1).trim();
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
return headers;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/Requests/ExecutableRequest.ts
|
|
665
|
+
var defaultTransport = new XhrTransport();
|
|
666
|
+
var ExecutableRequest = class extends RequestBase {
|
|
667
|
+
/**
|
|
668
|
+
* Creates an executable request with authentication and SDK-wide execution options.
|
|
669
|
+
*
|
|
670
|
+
* @param requestOptions Request URL, query, data, and callback options.
|
|
671
|
+
* @param token Optional bearer token or legacy authorization header value.
|
|
672
|
+
* @param sdkOptions SDK-wide handlers and request behavior options.
|
|
673
|
+
*/
|
|
674
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
675
|
+
super(requestOptions);
|
|
676
|
+
this.token = token;
|
|
677
|
+
this.successCb = this.successCb || sdkOptions.handlers?.successCb;
|
|
678
|
+
this.failureCb = this.failureCb || sdkOptions.handlers?.failureCb;
|
|
679
|
+
this.enableUnlimitedChoices = sdkOptions.enableUnlimitedChoices;
|
|
680
|
+
this.integrationMode = sdkOptions.integrationMode;
|
|
681
|
+
this.transport = sdkOptions.transport ?? defaultTransport;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Sends the request asynchronously.
|
|
685
|
+
*
|
|
686
|
+
* Successful responses are passed to `successCb`; HTTP errors are normalized and passed to
|
|
687
|
+
* `failureCb`. The method returns immediately and does not return a promise or response value.
|
|
688
|
+
*/
|
|
689
|
+
execute() {
|
|
690
|
+
this.transport.send(
|
|
691
|
+
{
|
|
692
|
+
method: this.getMethod(),
|
|
693
|
+
url: this.buildUrl(),
|
|
694
|
+
headers: this.buildHeaders(),
|
|
695
|
+
body: utils.serializeToJSON(this.getBody()),
|
|
696
|
+
onUploadProgress: utils.isFunction(this.progressCb) ? (event) => this.progressCb(this.getProgressPayload(event)) : void 0
|
|
697
|
+
},
|
|
698
|
+
(response) => this.handleResponse(response)
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
/** Maps the transport's upload progress event to the value passed to `progressCb`. */
|
|
702
|
+
getProgressPayload(event) {
|
|
703
|
+
return event;
|
|
704
|
+
}
|
|
705
|
+
handleResponse(response) {
|
|
706
|
+
if (response.status > 0) {
|
|
707
|
+
let data = this.parseResponse(response);
|
|
708
|
+
if (response.status >= 200 && response.status <= 206) {
|
|
709
|
+
if (this.successCb && utils.isFunction(this.successCb)) {
|
|
710
|
+
this.successCb(data);
|
|
711
|
+
}
|
|
712
|
+
} else if (response.status >= 400) {
|
|
713
|
+
if (utils.isString(data)) {
|
|
714
|
+
data = {
|
|
715
|
+
message: data
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
data.status = response.status;
|
|
719
|
+
if (this.failureCb && utils.isFunction(this.failureCb)) {
|
|
720
|
+
this.failureCb(data);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
buildHeaders() {
|
|
726
|
+
const headers = { ...this.getHeaders() };
|
|
727
|
+
if (this.token) {
|
|
728
|
+
if (typeof this.token === "string") {
|
|
729
|
+
headers[HEADER_NAMES.authorization] = this.token;
|
|
730
|
+
} else {
|
|
731
|
+
headers[HEADER_NAMES.authorization] = this.token.type + " " + this.token.value;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (this.enableUnlimitedChoices) {
|
|
735
|
+
headers[HEADER_NAMES.choicesBinaryRepresentation] = "true";
|
|
736
|
+
}
|
|
737
|
+
if (this.integrationMode) {
|
|
738
|
+
headers[HEADER_NAMES.integrationMode] = "true";
|
|
739
|
+
}
|
|
740
|
+
headers[HEADER_NAMES.serviceRequest] = "true";
|
|
741
|
+
return headers;
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
// src/Requests/Request.ts
|
|
746
|
+
var GetRequest = class extends ExecutableRequest {
|
|
747
|
+
/** Creates a collection GET request. */
|
|
748
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
749
|
+
super(requestOptions, token, sdkOptions);
|
|
750
|
+
}
|
|
751
|
+
/** Returns `GET`, the HTTP method used by this request. */
|
|
752
|
+
getMethod() {
|
|
753
|
+
return HTTP_METHODS.get;
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
var GetByIdRequest = class extends ExecutableRequest {
|
|
757
|
+
/** Creates a single-item GET request. */
|
|
758
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
759
|
+
super(requestOptions, token, sdkOptions);
|
|
760
|
+
}
|
|
761
|
+
/** Returns `GET`, the HTTP method used by this request. */
|
|
762
|
+
getMethod() {
|
|
763
|
+
return HTTP_METHODS.get;
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
var DeleteRequest = class extends ExecutableRequest {
|
|
767
|
+
/** Creates a DELETE request. */
|
|
768
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
769
|
+
super(requestOptions, token, sdkOptions);
|
|
770
|
+
}
|
|
771
|
+
/** Returns `DELETE`, the HTTP method used by this request. */
|
|
772
|
+
getMethod() {
|
|
773
|
+
return HTTP_METHODS.delete;
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
var UpdateRequest = class extends ExecutableRequest {
|
|
777
|
+
/** Creates an update request, optionally using the Sitefinity temporary-save operation. */
|
|
778
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
779
|
+
super(requestOptions, token, sdkOptions);
|
|
780
|
+
this.data = requestOptions.data;
|
|
781
|
+
this.saveTemp = requestOptions.saveTemp;
|
|
782
|
+
}
|
|
783
|
+
/** Returns `PATCH`, the HTTP method used by this request. */
|
|
784
|
+
getMethod() {
|
|
785
|
+
return HTTP_METHODS.patch;
|
|
786
|
+
}
|
|
787
|
+
/** Returns the update payload after converting date values to ISO strings. */
|
|
788
|
+
getBody() {
|
|
789
|
+
const body = utils.convertDateFieldToISOString(this.data);
|
|
790
|
+
return body;
|
|
791
|
+
}
|
|
792
|
+
getHeaders() {
|
|
793
|
+
const headers = super.getHeaders();
|
|
794
|
+
if (this.saveTemp) {
|
|
795
|
+
headers[HEADER_NAMES.operation] = "SaveTemp";
|
|
796
|
+
}
|
|
797
|
+
return headers;
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
var CreateRequest = class extends ExecutableRequest {
|
|
801
|
+
/** Creates a request containing the item data to post. */
|
|
802
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
803
|
+
super(requestOptions, token, sdkOptions);
|
|
804
|
+
this.data = requestOptions.data;
|
|
805
|
+
}
|
|
806
|
+
/** Returns `POST`, the HTTP method used by this request. */
|
|
807
|
+
getMethod() {
|
|
808
|
+
return HTTP_METHODS.post;
|
|
809
|
+
}
|
|
810
|
+
/** Returns the create payload after converting date values to ISO strings. */
|
|
811
|
+
getBody() {
|
|
812
|
+
if (!(this.data instanceof File)) {
|
|
813
|
+
return utils.convertDateFieldToISOString(this.data);
|
|
814
|
+
}
|
|
815
|
+
return this.data;
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
var GetRelatedRequest = class extends GetByIdRequest {
|
|
819
|
+
/** Creates a related-property GET request. */
|
|
820
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
821
|
+
super(requestOptions, token, sdkOptions);
|
|
822
|
+
this.property = requestOptions.property;
|
|
823
|
+
}
|
|
824
|
+
buildUrl() {
|
|
825
|
+
const url = this.urlOptions.baseUrl + this.urlOptions.entitySet + "(" + this.key + ")/" + this.property;
|
|
826
|
+
return this.addQueryParameters(url);
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
var GetRelatedByIdRequest = class extends GetByIdRequest {
|
|
830
|
+
/** Creates a related-item GET request. */
|
|
831
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
832
|
+
super(requestOptions, token, sdkOptions);
|
|
833
|
+
this.property = requestOptions.property;
|
|
834
|
+
this.relatedId = requestOptions.relatedId;
|
|
835
|
+
}
|
|
836
|
+
buildUrl() {
|
|
837
|
+
const url = this.urlOptions.baseUrl + this.urlOptions.entitySet + "(" + this.key + ")/" + this.property + "(" + this.relatedId + ")";
|
|
838
|
+
return this.addQueryParameters(url);
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
var DeleteRelatedRequest = class extends DeleteRequest {
|
|
842
|
+
/** Creates a related-property DELETE request. */
|
|
843
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
844
|
+
super(requestOptions, token, sdkOptions);
|
|
845
|
+
this.property = requestOptions.property;
|
|
846
|
+
}
|
|
847
|
+
buildUrl() {
|
|
848
|
+
const url = this.urlOptions.baseUrl + this.urlOptions.entitySet + "(" + this.key + ")/" + this.property + "/$ref";
|
|
849
|
+
return this.addQueryParameters(url);
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
var DeleteRelatedByIdRequest = class extends DeleteRequest {
|
|
853
|
+
/** Creates a related-item DELETE request. */
|
|
854
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
855
|
+
super(requestOptions, token, sdkOptions);
|
|
856
|
+
this.property = requestOptions.property;
|
|
857
|
+
this.relatedId = requestOptions.relatedId;
|
|
858
|
+
}
|
|
859
|
+
buildUrl() {
|
|
860
|
+
const url = this.urlOptions.baseUrl + this.urlOptions.entitySet + "(" + this.key + ")/" + this.property + "(" + this.relatedId + ")/$ref";
|
|
861
|
+
return this.addQueryParameters(url);
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
var CreateRelatedRequest = class extends CreateRequest {
|
|
865
|
+
/** Creates a related-property POST request. */
|
|
866
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
867
|
+
super(requestOptions, token, sdkOptions);
|
|
868
|
+
this.property = requestOptions.property;
|
|
869
|
+
this.key = requestOptions.key;
|
|
870
|
+
}
|
|
871
|
+
buildUrl() {
|
|
872
|
+
const url = this.urlOptions.baseUrl + this.urlOptions.entitySet + "(" + this.key + ")/" + this.property + "/$ref";
|
|
873
|
+
return this.addQueryParameters(url);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
var UploadRequest = class extends CreateRequest {
|
|
877
|
+
/** Creates an upload request with MIME type, file name, and upload properties. */
|
|
878
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
879
|
+
super(requestOptions, token, sdkOptions);
|
|
880
|
+
this.fileName = requestOptions.fileName;
|
|
881
|
+
this.uploadProperties = requestOptions.uploadProperties;
|
|
882
|
+
this.contentType = requestOptions.contentType;
|
|
883
|
+
}
|
|
884
|
+
/** Returns upload headers, including the MIME type, encoded file name, and properties. */
|
|
885
|
+
getHeaders() {
|
|
886
|
+
const headers = super.getHeaders();
|
|
887
|
+
headers[HEADER_NAMES.contentType] = this.contentType || "application/octet-stream";
|
|
888
|
+
headers[HEADER_NAMES.fileName] = encodeURIComponent(this.fileName);
|
|
889
|
+
headers[HEADER_NAMES.properties] = JSON.stringify(this.uploadProperties);
|
|
890
|
+
headers[HEADER_NAMES.contentEncoding] = "identity";
|
|
891
|
+
return headers;
|
|
892
|
+
}
|
|
893
|
+
/** Returns the binary upload payload without JSON date conversion. */
|
|
894
|
+
getBody() {
|
|
895
|
+
return this.data;
|
|
896
|
+
}
|
|
897
|
+
/** Returns `POST` for new files or `PATCH` when updating an existing item. */
|
|
898
|
+
getMethod() {
|
|
899
|
+
if (this.key) {
|
|
900
|
+
return HTTP_METHODS.patch;
|
|
901
|
+
}
|
|
902
|
+
return HTTP_METHODS.post;
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
var UploadChunkRequest = class extends CreateRequest {
|
|
906
|
+
/** Creates a chunk upload request. */
|
|
907
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
908
|
+
super(requestOptions, token, sdkOptions);
|
|
909
|
+
this.contentType = requestOptions.fileMimeType;
|
|
910
|
+
this.chunkOrdinal = requestOptions.chunkOrdinal;
|
|
911
|
+
this.chunkedFileUploadSessionId = requestOptions.chunkedFileUploadSessionId;
|
|
912
|
+
this.chunkSize = requestOptions.chunkSize;
|
|
913
|
+
this.numberOfChunks = requestOptions.numberOfChunks;
|
|
914
|
+
this.positionInQueue = requestOptions.positionOfChunkInQueue;
|
|
915
|
+
this.blobStorageProviderName = requestOptions.blobStorageProviderName;
|
|
916
|
+
this.data = requestOptions.chunkBlob;
|
|
917
|
+
this.fileName = requestOptions.fileName;
|
|
918
|
+
}
|
|
919
|
+
/** Returns chunk headers required by the Sitefinity chunk upload service. */
|
|
920
|
+
getHeaders() {
|
|
921
|
+
const headers = super.getHeaders();
|
|
922
|
+
headers[HEADER_NAMES.contentEncoding] = "identity";
|
|
923
|
+
headers[HEADER_NAMES.contentType] = this.contentType || "application/octet-stream";
|
|
924
|
+
headers[HEADER_NAMES.chunkOrdinal] = this.chunkOrdinal.toString();
|
|
925
|
+
headers[HEADER_NAMES.chunkedFileUploadSessionId] = this.chunkedFileUploadSessionId;
|
|
926
|
+
headers[HEADER_NAMES.chunkSize] = this.chunkSize.toString();
|
|
927
|
+
headers[HEADER_NAMES.blobStorageProviderName] = this.blobStorageProviderName.toString();
|
|
928
|
+
headers[HEADER_NAMES.fileName] = encodeURIComponent(this.fileName);
|
|
929
|
+
return headers;
|
|
930
|
+
}
|
|
931
|
+
/** Returns the binary content of this chunk. */
|
|
932
|
+
getBody() {
|
|
933
|
+
return this.data;
|
|
934
|
+
}
|
|
935
|
+
/** Returns `POST`, the HTTP method used for a chunk. */
|
|
936
|
+
getMethod() {
|
|
937
|
+
return HTTP_METHODS.post;
|
|
938
|
+
}
|
|
939
|
+
/** Reports chunk progress as the position in the upload queue rather than bytes sent. */
|
|
940
|
+
getProgressPayload() {
|
|
941
|
+
return {
|
|
942
|
+
lengthComputable: true,
|
|
943
|
+
loaded: this.positionInQueue,
|
|
944
|
+
total: this.numberOfChunks
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
var CommitChunksRequest = class extends CreateRequest {
|
|
949
|
+
/** Creates a chunk-commit request and its server operation payload. */
|
|
950
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
951
|
+
super(requestOptions, token, sdkOptions);
|
|
952
|
+
this.action = "Default.CommitChunks";
|
|
953
|
+
this.data = {
|
|
954
|
+
// ! this must be the param name that the operation provider on the server accepts
|
|
955
|
+
commitChunksDto: {
|
|
956
|
+
chunkedFileUploadSessionId: requestOptions.chunkedFileUploadSessionId,
|
|
957
|
+
contentType: requestOptions.contentType,
|
|
958
|
+
fileTotalSize: requestOptions.fileTotalSize,
|
|
959
|
+
numberOfChunks: requestOptions.numberOfChunks,
|
|
960
|
+
fileName: requestOptions.fileName,
|
|
961
|
+
blobStorageProviderName: requestOptions.blobStorageProviderName,
|
|
962
|
+
itemId: requestOptions.itemId || null,
|
|
963
|
+
// ! must be named properties
|
|
964
|
+
properties: requestOptions.uploadProperties
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
/** Returns `POST`, the HTTP method used to commit the upload. */
|
|
969
|
+
getMethod() {
|
|
970
|
+
return HTTP_METHODS.post;
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
// src/Requests/BatchRequest.ts
|
|
975
|
+
var Transaction = class {
|
|
976
|
+
/** Creates an empty transaction using the batch URL options and request factory. */
|
|
977
|
+
constructor(urlOptions, factory) {
|
|
978
|
+
this.urlOptions = urlOptions;
|
|
979
|
+
this.factory = factory;
|
|
980
|
+
this.requests = [];
|
|
981
|
+
this.counter = 0;
|
|
982
|
+
}
|
|
983
|
+
/** Adds a file upload and returns its batch-local request ID. */
|
|
984
|
+
upload(parameters) {
|
|
985
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
986
|
+
const options = {
|
|
987
|
+
urlOptions,
|
|
988
|
+
data: parameters.data,
|
|
989
|
+
contentType: parameters.contentType,
|
|
990
|
+
fileName: parameters.fileName,
|
|
991
|
+
key: parameters.key,
|
|
992
|
+
uploadProperties: parameters.uploadProperties
|
|
993
|
+
};
|
|
994
|
+
const request = this.factory.upload(options);
|
|
995
|
+
return this.addRequest(request);
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Adds a create request and returns its batch-local request ID.
|
|
999
|
+
*
|
|
1000
|
+
* @throws When `entitySet` is missing.
|
|
1001
|
+
*/
|
|
1002
|
+
create(parameters) {
|
|
1003
|
+
if (!parameters?.entitySet)
|
|
1004
|
+
throw "entitySet is required!";
|
|
1005
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1006
|
+
const options = {
|
|
1007
|
+
key: parameters.key,
|
|
1008
|
+
action: parameters.action,
|
|
1009
|
+
urlOptions,
|
|
1010
|
+
data: parameters.data
|
|
1011
|
+
};
|
|
1012
|
+
const request = this.factory.create(options);
|
|
1013
|
+
return this.addRequest(request);
|
|
1014
|
+
}
|
|
1015
|
+
// TODO: Remove
|
|
1016
|
+
/** Adds an operation request. Validation errors are thrown when required values are missing. */
|
|
1017
|
+
operation(parameters) {
|
|
1018
|
+
if (!parameters?.entitySet || parameters.key === void 0 || parameters.key === null || !parameters.data)
|
|
1019
|
+
throw "parameters: entitySet, key and data are required!";
|
|
1020
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1021
|
+
const options = {
|
|
1022
|
+
urlOptions,
|
|
1023
|
+
key: parameters.key,
|
|
1024
|
+
action: "operation",
|
|
1025
|
+
data: parameters.data
|
|
1026
|
+
};
|
|
1027
|
+
const request = this.factory.create(options);
|
|
1028
|
+
this.overrideUrlGeneration(request, parameters.key, "operation", options.urlOptions, options.query);
|
|
1029
|
+
this.addRequest(request);
|
|
1030
|
+
}
|
|
1031
|
+
/** Adds an update request. Validation errors are thrown when required values are missing. */
|
|
1032
|
+
update(parameters) {
|
|
1033
|
+
if (!parameters?.entitySet || parameters.key === void 0 || parameters.key === null || !parameters.data)
|
|
1034
|
+
throw "parameters: entitySet, key and data are required!";
|
|
1035
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1036
|
+
const options = {
|
|
1037
|
+
urlOptions,
|
|
1038
|
+
saveTemp: parameters.saveTemp,
|
|
1039
|
+
key: parameters.key,
|
|
1040
|
+
data: parameters.data
|
|
1041
|
+
};
|
|
1042
|
+
const request = this.factory.update(options);
|
|
1043
|
+
this.overrideUrlGeneration(request, parameters.key, void 0, options.urlOptions, options.query);
|
|
1044
|
+
this.addRequest(request);
|
|
1045
|
+
}
|
|
1046
|
+
/** Adds a delete request. Validation errors are thrown when required values are missing. */
|
|
1047
|
+
destroy(parameters) {
|
|
1048
|
+
if (!parameters?.entitySet || parameters.key === void 0 || parameters.key === null)
|
|
1049
|
+
throw "parameters: entitySet and key are required!";
|
|
1050
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1051
|
+
const options = {
|
|
1052
|
+
urlOptions,
|
|
1053
|
+
key: parameters.key
|
|
1054
|
+
};
|
|
1055
|
+
const request = this.factory.destroy(options);
|
|
1056
|
+
this.overrideUrlGeneration(request, parameters.key, void 0, options.urlOptions, options.query);
|
|
1057
|
+
this.addRequest(request);
|
|
1058
|
+
}
|
|
1059
|
+
/** Adds a request that removes all links in a related property. */
|
|
1060
|
+
destroyRelated(parameters) {
|
|
1061
|
+
if (!parameters?.entitySet || parameters.key === void 0 || parameters.key === null || !parameters.property)
|
|
1062
|
+
throw "parameters: entitySet, key and property are required!";
|
|
1063
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1064
|
+
const options = {
|
|
1065
|
+
urlOptions,
|
|
1066
|
+
key: parameters.key,
|
|
1067
|
+
property: parameters.property
|
|
1068
|
+
};
|
|
1069
|
+
const request = this.factory.destroyRelated(options);
|
|
1070
|
+
const propertyURL = request.property + "/$ref";
|
|
1071
|
+
this.overrideUrlGeneration(request, parameters.key, propertyURL, options.urlOptions, options.query);
|
|
1072
|
+
this.addRequest(request);
|
|
1073
|
+
}
|
|
1074
|
+
/** Adds a request that removes one related link by key. */
|
|
1075
|
+
destroyRelatedById(parameters) {
|
|
1076
|
+
if (!parameters?.entitySet || parameters.key === void 0 || parameters.key === null || parameters.relatedId === void 0 || parameters.relatedId === null || !parameters.property)
|
|
1077
|
+
throw "parameters: entitySet, key, relatedId and property are required!";
|
|
1078
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1079
|
+
const options = {
|
|
1080
|
+
urlOptions,
|
|
1081
|
+
key: parameters.key,
|
|
1082
|
+
relatedId: parameters.relatedId,
|
|
1083
|
+
property: parameters.property
|
|
1084
|
+
};
|
|
1085
|
+
const request = this.factory.destroyRelatedById(options);
|
|
1086
|
+
this.addRequest(request);
|
|
1087
|
+
}
|
|
1088
|
+
/** Adds a related-link request and returns its batch-local request ID. */
|
|
1089
|
+
createRelated(parameters) {
|
|
1090
|
+
if (!parameters?.entitySet || parameters.key === void 0 || parameters.key === null || parameters.link === void 0 || parameters.link === null || !parameters.property)
|
|
1091
|
+
throw "parameters: entitySet, key, link and property are required!";
|
|
1092
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1093
|
+
for (let index = 0; index < this.requests.length; index += 1) {
|
|
1094
|
+
if (this.requests[index].id == parameters.link) {
|
|
1095
|
+
parameters.link = "$" + this.requests[index].id;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
const data = {
|
|
1099
|
+
"@odata.id": parameters.link
|
|
1100
|
+
};
|
|
1101
|
+
const options = {
|
|
1102
|
+
urlOptions,
|
|
1103
|
+
key: parameters.key,
|
|
1104
|
+
property: parameters.property,
|
|
1105
|
+
data
|
|
1106
|
+
};
|
|
1107
|
+
const request = this.factory.createRelated(options);
|
|
1108
|
+
const propertyURL = request.property + "/$ref";
|
|
1109
|
+
this.overrideUrlGeneration(request, parameters.key, propertyURL, options.urlOptions, options.query);
|
|
1110
|
+
return this.addRequest(request);
|
|
1111
|
+
}
|
|
1112
|
+
overrideUrlGeneration(request, key, additionalPropertyURL, urlOptions, query) {
|
|
1113
|
+
for (let index = 0; index < this.requests.length; index += 1) {
|
|
1114
|
+
if (this.requests[index].id == key) {
|
|
1115
|
+
request.buildUrl = function() {
|
|
1116
|
+
let uri = "$" + key;
|
|
1117
|
+
if (additionalPropertyURL !== void 0) {
|
|
1118
|
+
uri = uri + "/" + additionalPropertyURL;
|
|
1119
|
+
}
|
|
1120
|
+
if (urlOptions) {
|
|
1121
|
+
const queryString = request.getQueryString(urlOptions, query);
|
|
1122
|
+
if (queryString) {
|
|
1123
|
+
uri = uri + queryString;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return uri;
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
addRequest(request) {
|
|
1132
|
+
this.requests.push({ id: this.counter, request });
|
|
1133
|
+
return this.counter++;
|
|
1134
|
+
}
|
|
1135
|
+
urlParametersClone(entitySet) {
|
|
1136
|
+
const options = utils.clone(this.urlOptions);
|
|
1137
|
+
options.entitySet = entitySet;
|
|
1138
|
+
return options;
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
var _BatchRequest = class _BatchRequest extends ExecutableRequest {
|
|
1142
|
+
/** Creates an empty batch request. */
|
|
1143
|
+
constructor(requestOptions, token, sdkOptions) {
|
|
1144
|
+
super(requestOptions, token, sdkOptions);
|
|
1145
|
+
this.factory = requestOptions.factory;
|
|
1146
|
+
this.requests = [];
|
|
1147
|
+
this.counter = 0;
|
|
1148
|
+
this.boundary = this.createBoundary("sf_batch_");
|
|
1149
|
+
this.responseHeaderRegex = /^([^()<>@,;:\\"\/[\]?={} \t]+)\s?:\s?(.*)/;
|
|
1150
|
+
this.responseStatusRegex = /^HTTP\/1\.\d (\d{3}) (.*)$/i;
|
|
1151
|
+
}
|
|
1152
|
+
/** Adds a collection GET request. Validation errors are thrown for missing `entitySet`. */
|
|
1153
|
+
get(parameters) {
|
|
1154
|
+
if (!parameters?.entitySet)
|
|
1155
|
+
throw "entitySet is required!";
|
|
1156
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1157
|
+
const options = {
|
|
1158
|
+
urlOptions,
|
|
1159
|
+
action: parameters.action,
|
|
1160
|
+
query: parameters.query,
|
|
1161
|
+
fallbackProperties: parameters.fallbackProperties
|
|
1162
|
+
};
|
|
1163
|
+
const request = this.factory.get(options);
|
|
1164
|
+
this.addRequest(request);
|
|
1165
|
+
}
|
|
1166
|
+
/** Adds a single-item GET request. Validation errors are thrown for missing keys. */
|
|
1167
|
+
getSingle(parameters) {
|
|
1168
|
+
if (!parameters || !parameters.entitySet || parameters.key === null || parameters.key === void 0)
|
|
1169
|
+
throw "parameters: entitySet and key are required!";
|
|
1170
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1171
|
+
const options = {
|
|
1172
|
+
urlOptions,
|
|
1173
|
+
action: parameters.action,
|
|
1174
|
+
key: parameters.key,
|
|
1175
|
+
query: parameters.query
|
|
1176
|
+
};
|
|
1177
|
+
const request = this.factory.getSingle(options);
|
|
1178
|
+
this.addRequest(request);
|
|
1179
|
+
}
|
|
1180
|
+
/** Adds a related-property GET request. */
|
|
1181
|
+
getProperty(parameters) {
|
|
1182
|
+
if (!parameters || !parameters.entitySet || parameters.key === null || parameters.key === void 0 || !parameters.property)
|
|
1183
|
+
throw "parameters: entitySet, key and property are required!";
|
|
1184
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1185
|
+
const options = {
|
|
1186
|
+
urlOptions,
|
|
1187
|
+
key: parameters.key,
|
|
1188
|
+
property: parameters.property
|
|
1189
|
+
};
|
|
1190
|
+
const request = this.factory.getProperty(options);
|
|
1191
|
+
this.addRequest(request);
|
|
1192
|
+
}
|
|
1193
|
+
/** Adds a related-items GET request. */
|
|
1194
|
+
getRelated(parameters) {
|
|
1195
|
+
if (!parameters || !parameters.entitySet || parameters.key === null || parameters.key === void 0 || !parameters.property)
|
|
1196
|
+
throw "parameters: entitySet, key and property are required!";
|
|
1197
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1198
|
+
const options = {
|
|
1199
|
+
urlOptions,
|
|
1200
|
+
key: parameters.key,
|
|
1201
|
+
property: parameters.property
|
|
1202
|
+
};
|
|
1203
|
+
const request = this.factory.getRelated(options);
|
|
1204
|
+
this.addRequest(request);
|
|
1205
|
+
}
|
|
1206
|
+
/** Adds a GET request for one related item by key. */
|
|
1207
|
+
getRelatedById(parameters) {
|
|
1208
|
+
if (!parameters?.entitySet || parameters.key === void 0 || parameters.key === null || parameters.relatedId === void 0 || parameters.relatedId === null || !parameters.property)
|
|
1209
|
+
throw "parameters: entitySet, key, relatedId and property are required!";
|
|
1210
|
+
const urlOptions = this.urlParametersClone(parameters.entitySet);
|
|
1211
|
+
const options = {
|
|
1212
|
+
urlOptions,
|
|
1213
|
+
key: parameters.key,
|
|
1214
|
+
relatedId: parameters.relatedId,
|
|
1215
|
+
property: parameters.property
|
|
1216
|
+
};
|
|
1217
|
+
const request = this.factory.getRelatedById(options);
|
|
1218
|
+
this.addRequest(request);
|
|
1219
|
+
}
|
|
1220
|
+
/** Starts an atomic transaction changeset to add to this batch. */
|
|
1221
|
+
beginTransaction() {
|
|
1222
|
+
const option = utils.clone(this.urlOptions);
|
|
1223
|
+
const newTransaction = new Transaction(option, this.factory);
|
|
1224
|
+
newTransaction.id = ++this.counter;
|
|
1225
|
+
return newTransaction;
|
|
1226
|
+
}
|
|
1227
|
+
/** Adds a transaction changeset to the batch. Empty transactions are omitted from the body. */
|
|
1228
|
+
endTransaction(transaction) {
|
|
1229
|
+
this.requests.push({
|
|
1230
|
+
id: transaction.id,
|
|
1231
|
+
request: transaction
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
/** Builds the multipart MIME body sent to the `$batch` endpoint. */
|
|
1235
|
+
getBody() {
|
|
1236
|
+
return this.buildRequestBody();
|
|
1237
|
+
}
|
|
1238
|
+
/** Returns `POST`, the HTTP method used for the `$batch` endpoint. */
|
|
1239
|
+
getMethod() {
|
|
1240
|
+
return HTTP_METHODS.post;
|
|
1241
|
+
}
|
|
1242
|
+
/** Returns headers with the generated multipart MIME content type. */
|
|
1243
|
+
getHeaders() {
|
|
1244
|
+
const headers = this.urlOptions.additionalHeaders ?? {};
|
|
1245
|
+
const contentType = "multipart/mixed; boundary=" + this.boundary;
|
|
1246
|
+
headers[HEADER_NAMES.contentType] = contentType;
|
|
1247
|
+
return headers;
|
|
1248
|
+
}
|
|
1249
|
+
/** Builds the `$batch` URL and appends any configured query parameters. */
|
|
1250
|
+
buildUrl() {
|
|
1251
|
+
let url = this.urlOptions.baseUrl + "$batch";
|
|
1252
|
+
const queryString = this.getQueryString(this.urlOptions, this.query);
|
|
1253
|
+
if (queryString) {
|
|
1254
|
+
url += queryString;
|
|
1255
|
+
}
|
|
1256
|
+
return url;
|
|
1257
|
+
}
|
|
1258
|
+
parseResponse(response) {
|
|
1259
|
+
const context = {
|
|
1260
|
+
position: 0,
|
|
1261
|
+
boundaries: []
|
|
1262
|
+
};
|
|
1263
|
+
const partContentType = this.contentType(response.headers["content-type"]);
|
|
1264
|
+
if (partContentType && partContentType.mediaType == "multipart/mixed") {
|
|
1265
|
+
context.boundaries.push(partContentType.properties.boundary);
|
|
1266
|
+
}
|
|
1267
|
+
const batchResponse = this.parseBatchResponse(response.body, context);
|
|
1268
|
+
const responseParsed = [];
|
|
1269
|
+
for (let i = 0; i < batchResponse.length; i++) {
|
|
1270
|
+
try {
|
|
1271
|
+
const currentRequest = this.requests[i];
|
|
1272
|
+
let finalResult = null;
|
|
1273
|
+
let key = null;
|
|
1274
|
+
const singleResponse = batchResponse[i];
|
|
1275
|
+
const changesets = singleResponse.__changeResponses;
|
|
1276
|
+
if (changesets) {
|
|
1277
|
+
finalResult = [];
|
|
1278
|
+
const currentRequests = currentRequest ? currentRequest.request.requests : [];
|
|
1279
|
+
for (let j = 0; j < changesets.length; j++) {
|
|
1280
|
+
key = currentRequests[j] ? currentRequests[j].request.key : null;
|
|
1281
|
+
const changeset = changesets[j];
|
|
1282
|
+
const response2 = changeset.response;
|
|
1283
|
+
const responseResult = this.getResponseResult(response2, key);
|
|
1284
|
+
finalResult.push(responseResult);
|
|
1285
|
+
}
|
|
1286
|
+
} else {
|
|
1287
|
+
key = currentRequest ? currentRequest.request.key : null;
|
|
1288
|
+
const response2 = singleResponse.response;
|
|
1289
|
+
finalResult = this.getResponseResult(response2, key);
|
|
1290
|
+
}
|
|
1291
|
+
const statusCodeCheck = function(r) {
|
|
1292
|
+
return r.statusCode >= 400;
|
|
1293
|
+
};
|
|
1294
|
+
const responseCheck = function(r) {
|
|
1295
|
+
let success = true;
|
|
1296
|
+
if (r.data && r.data.hasOwnProperty("Success")) {
|
|
1297
|
+
success = r.data.Success;
|
|
1298
|
+
}
|
|
1299
|
+
return success;
|
|
1300
|
+
};
|
|
1301
|
+
const isSuccessful = Array.isArray(finalResult) ? finalResult.filter(statusCodeCheck).length === 0 && finalResult.filter(responseCheck).length === finalResult.length : !statusCodeCheck(finalResult) && responseCheck(finalResult);
|
|
1302
|
+
responseParsed.push({ isSuccessful, response: finalResult });
|
|
1303
|
+
} catch (e) {
|
|
1304
|
+
continue;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
const isSuccessfulCheck = (r) => {
|
|
1308
|
+
return !r.isSuccessful;
|
|
1309
|
+
};
|
|
1310
|
+
const batchIsSuccessful = responseParsed.filter(isSuccessfulCheck).length === 0;
|
|
1311
|
+
return { data: responseParsed, isSuccessful: batchIsSuccessful };
|
|
1312
|
+
}
|
|
1313
|
+
parseBatchResponse(text, context) {
|
|
1314
|
+
const delimiter = "--" + this.currentBoundary(context);
|
|
1315
|
+
this.readTo(text, delimiter, context);
|
|
1316
|
+
this.readLine(text, context);
|
|
1317
|
+
const responses = [];
|
|
1318
|
+
let partEnd;
|
|
1319
|
+
while (partEnd !== "--" && context.position < text.length) {
|
|
1320
|
+
const partHeaders = this.readHeaders(text, context);
|
|
1321
|
+
const partContentType = this.contentType(partHeaders["content-type"]);
|
|
1322
|
+
let changeResponses;
|
|
1323
|
+
if (partContentType && partContentType.mediaType === "multipart/mixed") {
|
|
1324
|
+
context.boundaries.push(partContentType.properties.boundary);
|
|
1325
|
+
try {
|
|
1326
|
+
changeResponses = this.parseBatchResponse(text, context);
|
|
1327
|
+
} catch (e) {
|
|
1328
|
+
e.response = this.readResponse(text, context, delimiter);
|
|
1329
|
+
changeResponses = [e];
|
|
1330
|
+
}
|
|
1331
|
+
responses.push({ __changeResponses: changeResponses });
|
|
1332
|
+
context.boundaries.pop();
|
|
1333
|
+
this.readTo(text, "--" + this.currentBoundary(context), context);
|
|
1334
|
+
} else {
|
|
1335
|
+
if (!partContentType || partContentType.mediaType !== "application/http") {
|
|
1336
|
+
throw { message: "invalid MIME part type " };
|
|
1337
|
+
}
|
|
1338
|
+
this.readLine(text, context);
|
|
1339
|
+
let response = this.readResponse(text, context, delimiter);
|
|
1340
|
+
try {
|
|
1341
|
+
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
|
1342
|
+
response = { message: response.statusCode + " Http request is OK", response };
|
|
1343
|
+
} else {
|
|
1344
|
+
response = { message: "HTTP request failed", response };
|
|
1345
|
+
}
|
|
1346
|
+
} catch (e) {
|
|
1347
|
+
response = e;
|
|
1348
|
+
}
|
|
1349
|
+
responses.push(response);
|
|
1350
|
+
}
|
|
1351
|
+
partEnd = text.substr(context.position, 2);
|
|
1352
|
+
this.readLine(text, context);
|
|
1353
|
+
}
|
|
1354
|
+
return responses;
|
|
1355
|
+
}
|
|
1356
|
+
getResponseResult(response, key) {
|
|
1357
|
+
const responseBody = response.body;
|
|
1358
|
+
const data = utils.parseStringToJson(responseBody);
|
|
1359
|
+
return {
|
|
1360
|
+
key,
|
|
1361
|
+
data,
|
|
1362
|
+
statusCode: response.statusCode,
|
|
1363
|
+
headers: response.headers
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
currentBoundary(context) {
|
|
1367
|
+
const boundaries = context.boundaries;
|
|
1368
|
+
return boundaries[boundaries.length - 1];
|
|
1369
|
+
}
|
|
1370
|
+
contentType(str) {
|
|
1371
|
+
if (!str) {
|
|
1372
|
+
return null;
|
|
1373
|
+
}
|
|
1374
|
+
const contentTypeParts = str.split(";");
|
|
1375
|
+
const properties = {};
|
|
1376
|
+
let i, len;
|
|
1377
|
+
for (i = 1, len = contentTypeParts.length; i < len; i++) {
|
|
1378
|
+
const contentTypeParams = contentTypeParts[i].split("=");
|
|
1379
|
+
properties[contentTypeParams[0].replace(/^\s+|\s+$/g, "")] = contentTypeParams[1];
|
|
1380
|
+
}
|
|
1381
|
+
return { mediaType: contentTypeParts[0].replace(/^\s+|\s+$/g, ""), properties };
|
|
1382
|
+
}
|
|
1383
|
+
readTo(text, str, context) {
|
|
1384
|
+
const start = context.position || 0;
|
|
1385
|
+
let end = text.length;
|
|
1386
|
+
if (str) {
|
|
1387
|
+
end = text.indexOf(str, start);
|
|
1388
|
+
if (end === -1) {
|
|
1389
|
+
return null;
|
|
1390
|
+
}
|
|
1391
|
+
context.position = end + str.length;
|
|
1392
|
+
} else {
|
|
1393
|
+
context.position = end;
|
|
1394
|
+
}
|
|
1395
|
+
return text.substring(start, end);
|
|
1396
|
+
}
|
|
1397
|
+
readLine(text, context) {
|
|
1398
|
+
return this.readTo(text, _BatchRequest.constants.newLine, context);
|
|
1399
|
+
}
|
|
1400
|
+
readHeaders(text, context) {
|
|
1401
|
+
const headers = {};
|
|
1402
|
+
let parts;
|
|
1403
|
+
let line;
|
|
1404
|
+
let pos;
|
|
1405
|
+
do {
|
|
1406
|
+
pos = context.position;
|
|
1407
|
+
line = this.readLine(text, context);
|
|
1408
|
+
parts = this.responseHeaderRegex.exec(line);
|
|
1409
|
+
if (parts !== null) {
|
|
1410
|
+
headers[parts[1].toLowerCase()] = parts[2];
|
|
1411
|
+
} else {
|
|
1412
|
+
context.position = pos;
|
|
1413
|
+
}
|
|
1414
|
+
} while (line && parts);
|
|
1415
|
+
return headers;
|
|
1416
|
+
}
|
|
1417
|
+
readResponse(text, context, delimiter) {
|
|
1418
|
+
const pos = context.position;
|
|
1419
|
+
const match = this.responseStatusRegex.exec(this.readLine(text, context));
|
|
1420
|
+
let statusCode;
|
|
1421
|
+
let statusText;
|
|
1422
|
+
let headers;
|
|
1423
|
+
if (match) {
|
|
1424
|
+
statusCode = match[1];
|
|
1425
|
+
statusText = match[2];
|
|
1426
|
+
headers = this.readHeaders(text, context);
|
|
1427
|
+
this.readLine(text, context);
|
|
1428
|
+
} else {
|
|
1429
|
+
context.position = pos;
|
|
1430
|
+
}
|
|
1431
|
+
return {
|
|
1432
|
+
statusCode,
|
|
1433
|
+
statusText,
|
|
1434
|
+
headers,
|
|
1435
|
+
body: this.readTo(text, _BatchRequest.constants.newLine + delimiter, context)
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
buildRequestBody() {
|
|
1439
|
+
const builder = new BlobBuilder();
|
|
1440
|
+
builder.append("");
|
|
1441
|
+
for (let index = 0; index < this.requests.length; index += 1) {
|
|
1442
|
+
const request = this.requests[index].request;
|
|
1443
|
+
if (request instanceof Transaction && request.requests.length === 0) {
|
|
1444
|
+
continue;
|
|
1445
|
+
}
|
|
1446
|
+
if (index != 0)
|
|
1447
|
+
builder.append(_BatchRequest.constants.newLine + _BatchRequest.constants.newLine);
|
|
1448
|
+
builder.append("--" + this.boundary);
|
|
1449
|
+
if (request instanceof Transaction) {
|
|
1450
|
+
builder.append(this.buildTransaction(request));
|
|
1451
|
+
} else {
|
|
1452
|
+
builder.append(this.buildRequest(request));
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
builder.append(this.createDelimeter(this.boundary, true));
|
|
1456
|
+
return builder.build();
|
|
1457
|
+
}
|
|
1458
|
+
buildRequest(request) {
|
|
1459
|
+
const builder = new BlobBuilder();
|
|
1460
|
+
builder.append(_BatchRequest.constants.newLine + "Content-Type: application/http" + _BatchRequest.constants.newLine + "Content-Transfer-Encoding: binary" + _BatchRequest.constants.newLine + _BatchRequest.constants.newLine + request.getMethod() + " " + request.buildUrl() + " HTTP/1.1");
|
|
1461
|
+
return builder.build();
|
|
1462
|
+
}
|
|
1463
|
+
buildTransaction(transaction) {
|
|
1464
|
+
if (transaction.requests.length == 0)
|
|
1465
|
+
return;
|
|
1466
|
+
const builder = new BlobBuilder();
|
|
1467
|
+
builder.append(_BatchRequest.constants.newLine);
|
|
1468
|
+
const changeset = this.createBoundary("sf_changeset_");
|
|
1469
|
+
builder.append("Content-Type: multipart/mixed; boundary=" + changeset);
|
|
1470
|
+
const changesetRequests = transaction.requests;
|
|
1471
|
+
for (let index = 0; index < changesetRequests.length; index += 1) {
|
|
1472
|
+
const currentRequest = changesetRequests[index].request;
|
|
1473
|
+
const shouldAddSingleNewLine = index != 0 && utils.isBlob(changesetRequests[index - 1].request.getBody());
|
|
1474
|
+
builder.append(this.createDelimeter(changeset, false, shouldAddSingleNewLine) + _BatchRequest.constants.newLine + "Content-Type: application/http" + _BatchRequest.constants.newLine + "Content-Transfer-Encoding: binary" + _BatchRequest.constants.newLine + "Content-ID: " + changesetRequests[index].id);
|
|
1475
|
+
const requestUrl = currentRequest.buildUrl();
|
|
1476
|
+
builder.append(_BatchRequest.constants.newLine + _BatchRequest.constants.newLine + currentRequest.getMethod() + " " + requestUrl + " HTTP/1.1");
|
|
1477
|
+
const headers = currentRequest.getHeaders();
|
|
1478
|
+
const headerNames = Object.keys(headers);
|
|
1479
|
+
for (let i = 0; i < headerNames.length; i++) {
|
|
1480
|
+
const headerName = headerNames[i];
|
|
1481
|
+
builder.append(_BatchRequest.constants.newLine + headerName + ": " + headers[headerName]);
|
|
1482
|
+
}
|
|
1483
|
+
const body = utils.serializeToJSON(currentRequest.getBody());
|
|
1484
|
+
if (body) {
|
|
1485
|
+
builder.append(_BatchRequest.constants.newLine + _BatchRequest.constants.newLine);
|
|
1486
|
+
builder.append(body);
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
builder.append(this.createDelimeter(changeset, true));
|
|
1490
|
+
return builder.build();
|
|
1491
|
+
}
|
|
1492
|
+
createDelimeter(boundary, close, shouldAddSingleNewLine = false) {
|
|
1493
|
+
let result = _BatchRequest.constants.newLine;
|
|
1494
|
+
if (!shouldAddSingleNewLine) {
|
|
1495
|
+
result += _BatchRequest.constants.newLine;
|
|
1496
|
+
}
|
|
1497
|
+
result += "--" + boundary;
|
|
1498
|
+
if (close) {
|
|
1499
|
+
result += "--";
|
|
1500
|
+
result += _BatchRequest.constants.newLine;
|
|
1501
|
+
}
|
|
1502
|
+
return result;
|
|
1503
|
+
}
|
|
1504
|
+
createBoundary(prefix) {
|
|
1505
|
+
return prefix + utils.hex16() + "-" + utils.hex16() + "-" + utils.hex16();
|
|
1506
|
+
}
|
|
1507
|
+
addRequest(request) {
|
|
1508
|
+
this.requests.push({ id: this.counter, request });
|
|
1509
|
+
return this.counter++;
|
|
1510
|
+
}
|
|
1511
|
+
urlParametersClone(entitySet) {
|
|
1512
|
+
const options = utils.clone(this.urlOptions);
|
|
1513
|
+
options.entitySet = entitySet;
|
|
1514
|
+
return options;
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
/** Protocol constants used when constructing multipart MIME content. */
|
|
1518
|
+
_BatchRequest.constants = {
|
|
1519
|
+
newLine: "\r\n"
|
|
1520
|
+
};
|
|
1521
|
+
var BatchRequest = _BatchRequest;
|
|
1522
|
+
|
|
1523
|
+
// src/Requests/RequestFactory.ts
|
|
1524
|
+
var RequestFactory = class {
|
|
1525
|
+
/** Creates a request factory using the supplied SDK-wide options. */
|
|
1526
|
+
constructor(options) {
|
|
1527
|
+
this.options = options;
|
|
1528
|
+
}
|
|
1529
|
+
/** Creates a request for retrieving a collection. */
|
|
1530
|
+
get(parameters) {
|
|
1531
|
+
return new GetRequest(parameters, this.token, this.options);
|
|
1532
|
+
}
|
|
1533
|
+
/** Creates a request for retrieving one item by key. */
|
|
1534
|
+
getSingle(parameters) {
|
|
1535
|
+
return new GetByIdRequest(parameters, this.token, this.options);
|
|
1536
|
+
}
|
|
1537
|
+
/** Creates a request for creating one item. */
|
|
1538
|
+
create(parameters) {
|
|
1539
|
+
return new CreateRequest(parameters, this.token, this.options);
|
|
1540
|
+
}
|
|
1541
|
+
/** Creates a request for updating one item. */
|
|
1542
|
+
update(parameters) {
|
|
1543
|
+
return new UpdateRequest(parameters, this.token, this.options);
|
|
1544
|
+
}
|
|
1545
|
+
/** Creates a request for deleting one item. */
|
|
1546
|
+
destroy(parameters) {
|
|
1547
|
+
return new DeleteRequest(parameters, this.token, this.options);
|
|
1548
|
+
}
|
|
1549
|
+
/** Creates a request for retrieving a related property value. */
|
|
1550
|
+
getProperty(parameters) {
|
|
1551
|
+
return new GetRelatedRequest(parameters, this.token, this.options);
|
|
1552
|
+
}
|
|
1553
|
+
/** Creates a request for retrieving related items. */
|
|
1554
|
+
getRelated(parameters) {
|
|
1555
|
+
return new GetRelatedRequest(parameters, this.token, this.options);
|
|
1556
|
+
}
|
|
1557
|
+
/** Creates a request for retrieving one related item by key. */
|
|
1558
|
+
getRelatedById(parameters) {
|
|
1559
|
+
return new GetRelatedByIdRequest(parameters, this.token, this.options);
|
|
1560
|
+
}
|
|
1561
|
+
/** Creates a request for removing all related links for a property. */
|
|
1562
|
+
destroyRelated(parameters) {
|
|
1563
|
+
return new DeleteRelatedRequest(parameters, this.token, this.options);
|
|
1564
|
+
}
|
|
1565
|
+
/** Creates a request for removing one related link by key. */
|
|
1566
|
+
destroyRelatedById(parameters) {
|
|
1567
|
+
return new DeleteRelatedByIdRequest(parameters, this.token, this.options);
|
|
1568
|
+
}
|
|
1569
|
+
/** Creates a request for adding a related link. */
|
|
1570
|
+
createRelated(parameters) {
|
|
1571
|
+
return new CreateRelatedRequest(parameters, this.token, this.options);
|
|
1572
|
+
}
|
|
1573
|
+
/** Creates a request for uploading a file or binary payload. */
|
|
1574
|
+
upload(parameters) {
|
|
1575
|
+
return new UploadRequest(parameters, this.token, this.options);
|
|
1576
|
+
}
|
|
1577
|
+
/** Creates a request for uploading one file chunk. */
|
|
1578
|
+
uploadChunk(parameters) {
|
|
1579
|
+
return new UploadChunkRequest(parameters, this.token, this.options);
|
|
1580
|
+
}
|
|
1581
|
+
/** Creates a request that commits an uploaded chunk session. */
|
|
1582
|
+
commitChunks(parameters) {
|
|
1583
|
+
return new CommitChunksRequest(parameters, this.token, this.options);
|
|
1584
|
+
}
|
|
1585
|
+
/** Creates a multipart batch request; call its methods to add operations, then call `execute()`. */
|
|
1586
|
+
batch(parameters) {
|
|
1587
|
+
const batchParams = parameters;
|
|
1588
|
+
batchParams.factory = this;
|
|
1589
|
+
return new BatchRequest(batchParams, this.token, this.options);
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
|
|
1593
|
+
// src/chunk-upload/chunked-file-upload.utilities.ts
|
|
1594
|
+
var ChunkedFileUploadUtilities = class {
|
|
1595
|
+
/**
|
|
1596
|
+
* Splits a `Blob` or base64-encoded binary string into sequential chunks.
|
|
1597
|
+
*
|
|
1598
|
+
* Blob input is sliced directly. A base64 string is decoded with `atob`
|
|
1599
|
+
* into a Blob using `contentTypeMime` before it is sliced. Chunk ordinals
|
|
1600
|
+
* start at zero; the final chunk can be smaller than `chunkSize`.
|
|
1601
|
+
*
|
|
1602
|
+
* @param file Blob data or a base64-encoded binary string.
|
|
1603
|
+
* @param chunkSize Maximum size of each chunk in bytes.
|
|
1604
|
+
* @param contentTypeMime MIME type assigned to each chunk and decoded Blob.
|
|
1605
|
+
* @returns The chunks, their total count, and the original file size in bytes.
|
|
1606
|
+
*
|
|
1607
|
+
* @example
|
|
1608
|
+
* ```ts
|
|
1609
|
+
* const result = new ChunkedFileUploadUtilities().chunkFile(
|
|
1610
|
+
* base64File,
|
|
1611
|
+
* 5 * 1024 * 1024,
|
|
1612
|
+
* "image/jpeg"
|
|
1613
|
+
* );
|
|
1614
|
+
*
|
|
1615
|
+
* result.chunks.forEach(({ ordinal, content }) => {
|
|
1616
|
+
* console.log(`Chunk ${ordinal}: ${content.size} bytes`);
|
|
1617
|
+
* });
|
|
1618
|
+
* ```
|
|
1619
|
+
*/
|
|
1620
|
+
chunkFile(file, chunkSize, contentTypeMime) {
|
|
1621
|
+
let fileInternal;
|
|
1622
|
+
if (typeof file === "string")
|
|
1623
|
+
fileInternal = this.base64ToBlob(file, chunkSize, contentTypeMime);
|
|
1624
|
+
else {
|
|
1625
|
+
fileInternal = file;
|
|
1626
|
+
}
|
|
1627
|
+
const fileSize = fileInternal.size;
|
|
1628
|
+
const result = [];
|
|
1629
|
+
let chunkOrdinal = 0;
|
|
1630
|
+
let offset = 0;
|
|
1631
|
+
let currentOffset = chunkSize;
|
|
1632
|
+
while (offset <= fileSize) {
|
|
1633
|
+
const chunk = fileInternal.slice(offset, currentOffset, contentTypeMime);
|
|
1634
|
+
offset = currentOffset;
|
|
1635
|
+
currentOffset = currentOffset + chunkSize;
|
|
1636
|
+
result.push({
|
|
1637
|
+
ordinal: chunkOrdinal,
|
|
1638
|
+
content: chunk
|
|
1639
|
+
});
|
|
1640
|
+
chunkOrdinal++;
|
|
1641
|
+
}
|
|
1642
|
+
return {
|
|
1643
|
+
chunks: result,
|
|
1644
|
+
totalChunksCount: result.length,
|
|
1645
|
+
fileTotalSize: fileSize
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Converts base64 binary content to a Blob before chunking.
|
|
1650
|
+
*
|
|
1651
|
+
* The input must contain the base64 payload expected by `atob`; a data URL
|
|
1652
|
+
* prefix is not removed automatically.
|
|
1653
|
+
*/
|
|
1654
|
+
base64ToBlob(base64String, chunkSize, contentType = "") {
|
|
1655
|
+
const byteCharacters = atob(base64String);
|
|
1656
|
+
const byteArrays = [];
|
|
1657
|
+
for (let offset = 0; offset < byteCharacters.length; offset += chunkSize) {
|
|
1658
|
+
const slice = byteCharacters.slice(offset, offset + chunkSize);
|
|
1659
|
+
const byteNumbers = new Array(slice.length);
|
|
1660
|
+
for (let i = 0; i < slice.length; i++) {
|
|
1661
|
+
byteNumbers[i] = slice.charCodeAt(i);
|
|
1662
|
+
}
|
|
1663
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
1664
|
+
byteArrays.push(byteArray);
|
|
1665
|
+
}
|
|
1666
|
+
const blob = new Blob(byteArrays, { type: contentType });
|
|
1667
|
+
return blob;
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
|
|
1671
|
+
// src/chunk-upload/chunk-upload.sdk.ts
|
|
1672
|
+
var ChunkUploadSdk = class {
|
|
1673
|
+
constructor(urlOptions, factory) {
|
|
1674
|
+
this.urlOptions = urlOptions;
|
|
1675
|
+
this.factory = factory;
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Gets the session, provider, and chunk settings required to start an upload.
|
|
1679
|
+
*
|
|
1680
|
+
* The `data.libraryId` field must identify the parent library, not a library
|
|
1681
|
+
* folder. The inherited callbacks and query options are optional.
|
|
1682
|
+
*
|
|
1683
|
+
* @param parameters Request data and optional callbacks.
|
|
1684
|
+
* @param parameters.data.libraryId Parent library identifier.
|
|
1685
|
+
* @param parameters.successCb Receives a {@link ChunkUploadInfoDTO} on success.
|
|
1686
|
+
* @param parameters.failureCb Receives the server error response on failure.
|
|
1687
|
+
* @param parameters.progressCb Receives upload progress events when supported.
|
|
1688
|
+
*/
|
|
1689
|
+
getChunkUploadInfo(parameters) {
|
|
1690
|
+
Guard.isNotNull(parameters, "parameters");
|
|
1691
|
+
Guard.isNotNull(parameters.data, "parameters.data");
|
|
1692
|
+
Guard.isNotNull(parameters.data.libraryId, "parameters.data.libraryId");
|
|
1693
|
+
const options = {
|
|
1694
|
+
urlOptions: this.urlOptions,
|
|
1695
|
+
action: `Default.GetChunkUploadInfo(libraryId=${parameters.data.libraryId})`,
|
|
1696
|
+
successCb: parameters.successCb,
|
|
1697
|
+
failureCb: parameters.failureCb,
|
|
1698
|
+
progressCb: parameters.progressCb,
|
|
1699
|
+
fallbackProperties: parameters.fallbackProperties,
|
|
1700
|
+
query: parameters.query
|
|
1701
|
+
};
|
|
1702
|
+
const request = this.factory.get(options);
|
|
1703
|
+
request.execute();
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Sends one chunk to the server.
|
|
1707
|
+
*
|
|
1708
|
+
* Upload chunks in ordinal order from `0` through `numberOfChunks - 1`.
|
|
1709
|
+
* `chunkSize` is the chunk size in bytes, while `chunkBlob` contains the
|
|
1710
|
+
* current chunk and may be smaller for the final chunk. The session,
|
|
1711
|
+
* provider, ordinal, count, size, and blob fields are required.
|
|
1712
|
+
*
|
|
1713
|
+
* @param parameters Chunk data and optional callbacks.
|
|
1714
|
+
* @param parameters.data.fileMimeType MIME type of the complete file.
|
|
1715
|
+
* @param parameters.data.fileName File name sent with the chunk.
|
|
1716
|
+
* @param parameters.data.chunkedFileUploadSessionId Session from
|
|
1717
|
+
* `getChunkUploadInfo`.
|
|
1718
|
+
* @param parameters.data.chunkSize Size of this chunk in bytes.
|
|
1719
|
+
* @param parameters.data.chunkOrdinal Zero-based ordinal of this chunk.
|
|
1720
|
+
* @param parameters.data.numberOfChunks Total chunks in the upload.
|
|
1721
|
+
* @param parameters.data.positionOfChunkInQueue Optional queue position used
|
|
1722
|
+
* to calculate progress for concurrent uploads.
|
|
1723
|
+
* @param parameters.data.chunkBlob Bytes for this chunk.
|
|
1724
|
+
* @param parameters.data.blobStorageProviderName Provider from the upload info.
|
|
1725
|
+
* @param parameters.successCb Receives a {@link ChunkUploadResult} on success.
|
|
1726
|
+
* @param parameters.failureCb Receives the server error response on failure.
|
|
1727
|
+
* @param parameters.progressCb Receives upload progress events when supported.
|
|
1728
|
+
*/
|
|
1729
|
+
uploadChunk(parameters) {
|
|
1730
|
+
Guard.isNotNull(parameters, "parameters");
|
|
1731
|
+
Guard.isNotNull(parameters.data, "parameters.data");
|
|
1732
|
+
Guard.isNotNull(parameters.data.chunkSize, "parameters.data.chunkSize");
|
|
1733
|
+
Guard.isNotNull(parameters.data.chunkedFileUploadSessionId, "parameters.data.chunkedFileUploadSessionId");
|
|
1734
|
+
Guard.isNotNull(parameters.data.chunkOrdinal, "parameters.data.chunkOrdinal");
|
|
1735
|
+
Guard.isNotNull(parameters.data.numberOfChunks, "parameters.data.numberOfChunks");
|
|
1736
|
+
Guard.isNotNull(parameters.data.chunkBlob, "parameters.data.chunkBlob");
|
|
1737
|
+
Guard.isNotNull(parameters.data.blobStorageProviderName, "parameters.data.blobStorageProviderName");
|
|
1738
|
+
const request = this.factory.uploadChunk({
|
|
1739
|
+
urlOptions: this.urlOptions,
|
|
1740
|
+
fileMimeType: parameters.data.fileMimeType,
|
|
1741
|
+
chunkSize: parameters.data.chunkSize,
|
|
1742
|
+
chunkedFileUploadSessionId: parameters.data.chunkedFileUploadSessionId,
|
|
1743
|
+
chunkOrdinal: parameters.data.chunkOrdinal,
|
|
1744
|
+
numberOfChunks: parameters.data.numberOfChunks,
|
|
1745
|
+
chunkBlob: parameters.data.chunkBlob,
|
|
1746
|
+
blobStorageProviderName: parameters.data.blobStorageProviderName,
|
|
1747
|
+
fileName: parameters.data.fileName,
|
|
1748
|
+
// optional
|
|
1749
|
+
positionOfChunkInQueue: parameters.data.positionOfChunkInQueue,
|
|
1750
|
+
successCb: parameters.successCb,
|
|
1751
|
+
failureCb: parameters.failureCb,
|
|
1752
|
+
progressCb: parameters.progressCb,
|
|
1753
|
+
fallbackProperties: parameters.fallbackProperties,
|
|
1754
|
+
query: parameters.query
|
|
1755
|
+
});
|
|
1756
|
+
request.execute();
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Commits all uploaded chunks as one media file.
|
|
1760
|
+
*
|
|
1761
|
+
* Call this only after every ordinal has uploaded successfully. The server
|
|
1762
|
+
* validates `numberOfChunks` and `fileTotalSize` before assembling the file.
|
|
1763
|
+
* Set `data.itemId` when replacing an existing media item; omit it when
|
|
1764
|
+
* creating a new item. A successful commit completes the upload session.
|
|
1765
|
+
*
|
|
1766
|
+
* @param parameters Commit data and optional callbacks.
|
|
1767
|
+
* @param parameters.data.chunkedFileUploadSessionId Session used by the chunks.
|
|
1768
|
+
* @param parameters.data.contentType MIME type of the complete file.
|
|
1769
|
+
* @param parameters.data.fileTotalSize Complete file size in bytes.
|
|
1770
|
+
* @param parameters.data.numberOfChunks Number of uploaded chunks.
|
|
1771
|
+
* @param parameters.data.name File name.
|
|
1772
|
+
* @param parameters.data.blobStorageProviderName Provider used for the chunks.
|
|
1773
|
+
* @param parameters.data.uploadProperties Media item properties such as
|
|
1774
|
+
* `Title` and `UrlName`.
|
|
1775
|
+
* @param parameters.data.itemId Optional existing item identifier for updates.
|
|
1776
|
+
* @param parameters.successCb Receives the commit response on success.
|
|
1777
|
+
* @param parameters.failureCb Receives the server error response on failure.
|
|
1778
|
+
* @param parameters.progressCb Receives upload progress events when supported.
|
|
1779
|
+
*/
|
|
1780
|
+
commitChunks(parameters) {
|
|
1781
|
+
Guard.isNotNull(parameters, "parameters");
|
|
1782
|
+
Guard.isNotNull(parameters.data, "parameters.data");
|
|
1783
|
+
Guard.isNotNull(parameters.data.chunkedFileUploadSessionId, "parameters.data.chunkedFileUploadSessionId");
|
|
1784
|
+
Guard.isNotNull(parameters.data.name, "parameters.data.name");
|
|
1785
|
+
Guard.isNotNull(parameters.data.uploadProperties, "parameters.data.uploadProperties");
|
|
1786
|
+
Guard.isNotNull(parameters.data.numberOfChunks, "parameters.data.numberOfChunks");
|
|
1787
|
+
Guard.isNotNull(parameters.data.fileTotalSize, "parameters.data.fileTotalSize");
|
|
1788
|
+
Guard.isNotNull(parameters.data.blobStorageProviderName, "parameters.data.blobStorageProviderName");
|
|
1789
|
+
const options = {
|
|
1790
|
+
urlOptions: this.urlOptions,
|
|
1791
|
+
chunkedFileUploadSessionId: parameters.data.chunkedFileUploadSessionId,
|
|
1792
|
+
contentType: parameters.data.contentType,
|
|
1793
|
+
fileName: parameters.data.name,
|
|
1794
|
+
uploadProperties: parameters.data.uploadProperties,
|
|
1795
|
+
numberOfChunks: parameters.data.numberOfChunks,
|
|
1796
|
+
fileTotalSize: parameters.data.fileTotalSize,
|
|
1797
|
+
blobStorageProviderName: parameters.data.blobStorageProviderName,
|
|
1798
|
+
// Optional: used for update, can be null for create
|
|
1799
|
+
itemId: parameters.data.itemId,
|
|
1800
|
+
successCb: parameters.successCb,
|
|
1801
|
+
failureCb: parameters.failureCb,
|
|
1802
|
+
progressCb: parameters.progressCb,
|
|
1803
|
+
fallbackProperties: parameters.fallbackProperties,
|
|
1804
|
+
query: parameters.query
|
|
1805
|
+
};
|
|
1806
|
+
const request = this.factory.commitChunks(options);
|
|
1807
|
+
request.execute();
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Deletes all chunks associated with an incomplete upload session.
|
|
1811
|
+
*
|
|
1812
|
+
* Call this after a failed chunk upload or failed commit when the session
|
|
1813
|
+
* should not be resumed. Cleanup does not commit a file and requires the
|
|
1814
|
+
* session and provider used by the upload.
|
|
1815
|
+
*
|
|
1816
|
+
* @param parameters Session data and optional callbacks.
|
|
1817
|
+
* @param parameters.data.chunkedFileUploadSessionId Session to clean up.
|
|
1818
|
+
* @param parameters.data.blobStorageProviderName Provider holding the chunks.
|
|
1819
|
+
* @param parameters.successCb Called after cleanup succeeds.
|
|
1820
|
+
* @param parameters.failureCb Receives the server error response on failure.
|
|
1821
|
+
* @param parameters.progressCb Receives request progress events when supported.
|
|
1822
|
+
*/
|
|
1823
|
+
cleanUpChunks(parameters) {
|
|
1824
|
+
Guard.isNotNull(parameters, "parameters");
|
|
1825
|
+
Guard.isNotNull(parameters.data, "parameters.data");
|
|
1826
|
+
Guard.isNotNull(parameters.data.chunkedFileUploadSessionId, "parameters.data.chunkedFileUploadSessionId");
|
|
1827
|
+
Guard.isNotNull(parameters.data.blobStorageProviderName, "parameters.data.blobStorageProviderName");
|
|
1828
|
+
const request = this.factory.create({
|
|
1829
|
+
urlOptions: this.urlOptions,
|
|
1830
|
+
action: "Default.CleanUpChunks",
|
|
1831
|
+
data: {
|
|
1832
|
+
chunkedFileUploadSessionId: parameters.data.chunkedFileUploadSessionId,
|
|
1833
|
+
blobStorageProviderName: parameters.data.blobStorageProviderName
|
|
1834
|
+
},
|
|
1835
|
+
successCb: parameters.successCb,
|
|
1836
|
+
failureCb: parameters.failureCb,
|
|
1837
|
+
progressCb: parameters.progressCb,
|
|
1838
|
+
fallbackProperties: parameters.fallbackProperties,
|
|
1839
|
+
query: parameters.query
|
|
1840
|
+
});
|
|
1841
|
+
request.execute();
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* Splits a file into uploadable chunks.
|
|
1845
|
+
*
|
|
1846
|
+
* A `Blob` is sliced directly. A base64 string is decoded with `atob` into
|
|
1847
|
+
* a `Blob` using `contentTypeMime`, then sliced. Each returned chunk has a
|
|
1848
|
+
* zero-based ordinal, and the last chunk can be smaller than `chunkSize`.
|
|
1849
|
+
*
|
|
1850
|
+
* @param file Source `Blob` or base64-encoded binary string.
|
|
1851
|
+
* @param chunkSize Maximum chunk size in bytes.
|
|
1852
|
+
* @param contentTypeMime MIME type assigned to the chunks and decoded Blob.
|
|
1853
|
+
* @returns Chunk blobs, their zero-based ordinals, total count, and file size.
|
|
1854
|
+
*
|
|
1855
|
+
* @example
|
|
1856
|
+
* ```ts
|
|
1857
|
+
* const upload = sitefinity.data(typeOptions).chunkUpload;
|
|
1858
|
+
* const result = upload.chunkFile(file, 5 * 1024 * 1024, "image/jpeg");
|
|
1859
|
+
*
|
|
1860
|
+
* for (const chunk of result.chunks) {
|
|
1861
|
+
* upload.uploadChunk({
|
|
1862
|
+
* data: {
|
|
1863
|
+
* fileMimeType: "image/jpeg",
|
|
1864
|
+
* chunkedFileUploadSessionId: sessionId,
|
|
1865
|
+
* chunkSize: chunk.content.size,
|
|
1866
|
+
* chunkOrdinal: chunk.ordinal,
|
|
1867
|
+
* numberOfChunks: result.totalChunksCount,
|
|
1868
|
+
* chunkBlob: chunk.content,
|
|
1869
|
+
* blobStorageProviderName: providerName
|
|
1870
|
+
* },
|
|
1871
|
+
* successCb: onChunkUploaded,
|
|
1872
|
+
* failureCb: onUploadFailed
|
|
1873
|
+
* });
|
|
1874
|
+
* }
|
|
1875
|
+
* ```
|
|
1876
|
+
*/
|
|
1877
|
+
chunkFile(file, chunkSize, contentTypeMime) {
|
|
1878
|
+
Guard.isNotNull(file, "file");
|
|
1879
|
+
Guard.isNotNull(chunkSize, "chunkSize");
|
|
1880
|
+
const utils2 = new ChunkedFileUploadUtilities();
|
|
1881
|
+
return utils2.chunkFile(file, chunkSize, contentTypeMime);
|
|
1882
|
+
}
|
|
1883
|
+
};
|
|
1884
|
+
var Guard = class _Guard {
|
|
1885
|
+
static isNotNull(value, parameterName) {
|
|
1886
|
+
if (typeof value === "number") {
|
|
1887
|
+
return;
|
|
1888
|
+
}
|
|
1889
|
+
if (!value) {
|
|
1890
|
+
_Guard.throwException(parameterName);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
static throwException(parameterName) {
|
|
1894
|
+
throw `parameter ${parameterName} is required.`;
|
|
1895
|
+
}
|
|
1896
|
+
};
|
|
1897
|
+
|
|
1898
|
+
// src/Data.ts
|
|
1899
|
+
var Data = class {
|
|
1900
|
+
/**
|
|
1901
|
+
* Creates an entity-set data client.
|
|
1902
|
+
*
|
|
1903
|
+
* @param urlOptions Entity-set and request URL options.
|
|
1904
|
+
* @param factory Internal request factory used to create SDK requests.
|
|
1905
|
+
*/
|
|
1906
|
+
constructor(urlOptions, factory) {
|
|
1907
|
+
this.urlOptions = urlOptions;
|
|
1908
|
+
this.factory = factory;
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Returns the chunk-upload service for this entity set.
|
|
1912
|
+
*
|
|
1913
|
+
* Use it for uploads that must be sent in chunks and committed after all chunks
|
|
1914
|
+
* complete. A new service instance is returned for each access.
|
|
1915
|
+
*
|
|
1916
|
+
* @returns The chunk-upload service.
|
|
1917
|
+
*/
|
|
1918
|
+
get chunkUpload() {
|
|
1919
|
+
const service = new ChunkUploadSdk(this.urlOptions, this.factory);
|
|
1920
|
+
return service;
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Executes a GET request to retrieve a collection of items.
|
|
1924
|
+
*
|
|
1925
|
+
* @param parameters Query, action, fallback-property, and callback options.
|
|
1926
|
+
* @returns Nothing. The result is delivered to `successCb` or `failureCb`.
|
|
1927
|
+
* @throws If request creation fails.
|
|
1928
|
+
*/
|
|
1929
|
+
get(parameters) {
|
|
1930
|
+
const request = this.factory.get({
|
|
1931
|
+
urlOptions: this.urlOptions,
|
|
1932
|
+
query: parameters.query,
|
|
1933
|
+
action: parameters.action,
|
|
1934
|
+
successCb: parameters.successCb,
|
|
1935
|
+
failureCb: parameters.failureCb,
|
|
1936
|
+
fallbackProperties: parameters.fallbackProperties
|
|
1937
|
+
});
|
|
1938
|
+
request.execute();
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Executes a GET request to retrieve operations for an item or its parent collection.
|
|
1942
|
+
*
|
|
1943
|
+
* When `key` is omitted, `parentId` is added to the operations URL.
|
|
1944
|
+
*
|
|
1945
|
+
* @param parameters Operation and callback options.
|
|
1946
|
+
* @returns Nothing. The result is delivered to `successCb` or `failureCb`.
|
|
1947
|
+
* @throws If the underlying request cannot be created.
|
|
1948
|
+
*/
|
|
1949
|
+
getOperations(parameters) {
|
|
1950
|
+
let request;
|
|
1951
|
+
let action = "operations";
|
|
1952
|
+
if (!parameters.key)
|
|
1953
|
+
action += `?${SF_PARAMS.parentId}=` + parameters.parentId;
|
|
1954
|
+
const params = {
|
|
1955
|
+
urlOptions: this.urlOptions,
|
|
1956
|
+
action,
|
|
1957
|
+
successCb: parameters.successCb,
|
|
1958
|
+
failureCb: parameters.failureCb
|
|
1959
|
+
};
|
|
1960
|
+
if (parameters.key) {
|
|
1961
|
+
params.key = parameters.key;
|
|
1962
|
+
request = this.factory.getSingle(params);
|
|
1963
|
+
} else {
|
|
1964
|
+
request = this.factory.get(params);
|
|
1965
|
+
}
|
|
1966
|
+
request.execute();
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* Executes a GET request for a single item.
|
|
1970
|
+
*
|
|
1971
|
+
* @param parameters Item key, query, action, and callback options.
|
|
1972
|
+
* @returns Nothing. The item is delivered to `successCb` or `failureCb`.
|
|
1973
|
+
* @throws If `key` is missing.
|
|
1974
|
+
*/
|
|
1975
|
+
getSingle(parameters) {
|
|
1976
|
+
if (!parameters.key)
|
|
1977
|
+
throw "Parameter 'key' is required!";
|
|
1978
|
+
const request = this.factory.getSingle({
|
|
1979
|
+
urlOptions: this.urlOptions,
|
|
1980
|
+
key: parameters.key,
|
|
1981
|
+
query: parameters.query,
|
|
1982
|
+
action: parameters.action,
|
|
1983
|
+
successCb: parameters.successCb,
|
|
1984
|
+
failureCb: parameters.failureCb,
|
|
1985
|
+
fallbackProperties: parameters.fallbackProperties
|
|
1986
|
+
});
|
|
1987
|
+
request.execute();
|
|
1988
|
+
}
|
|
1989
|
+
/**
|
|
1990
|
+
* Executes a POST request for a single item.
|
|
1991
|
+
*
|
|
1992
|
+
* @param parameters Item data, optional key/action, and callbacks.
|
|
1993
|
+
* @returns Nothing. The created item or error is delivered to a callback.
|
|
1994
|
+
* @throws If `data` is missing.
|
|
1995
|
+
*/
|
|
1996
|
+
create(parameters) {
|
|
1997
|
+
if (!parameters.data)
|
|
1998
|
+
throw "Parameter 'data' is required!";
|
|
1999
|
+
const request = this.factory.create({
|
|
2000
|
+
urlOptions: this.urlOptions,
|
|
2001
|
+
key: parameters.key,
|
|
2002
|
+
query: parameters.query,
|
|
2003
|
+
data: parameters.data,
|
|
2004
|
+
action: parameters.action,
|
|
2005
|
+
successCb: parameters.successCb,
|
|
2006
|
+
failureCb: parameters.failureCb
|
|
2007
|
+
});
|
|
2008
|
+
request.execute();
|
|
2009
|
+
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Executes a PATCH request to update a single item.
|
|
2012
|
+
*
|
|
2013
|
+
* @param parameters Item key, update data, optional temporary-save flag, and callbacks.
|
|
2014
|
+
* @returns Nothing. The updated item or error is delivered to a callback.
|
|
2015
|
+
* @throws If `key` or `data` is missing.
|
|
2016
|
+
*
|
|
2017
|
+
* @example
|
|
2018
|
+
* const data = sf.data({
|
|
2019
|
+
* entitySet: "newsitems",
|
|
2020
|
+
* provider: "OpenAccessDataProvider",
|
|
2021
|
+
* culture: "en"
|
|
2022
|
+
* });
|
|
2023
|
+
*
|
|
2024
|
+
* data.update({
|
|
2025
|
+
* key: "00000000-0000-0000-0000-000000000000",
|
|
2026
|
+
* data: { Title: "Updated news title" },
|
|
2027
|
+
* saveTemp: true,
|
|
2028
|
+
* successCb,
|
|
2029
|
+
* failureCb
|
|
2030
|
+
* });
|
|
2031
|
+
*/
|
|
2032
|
+
update(parameters) {
|
|
2033
|
+
if (parameters.key === void 0 || parameters.key === null || !parameters.data)
|
|
2034
|
+
throw "Parameters: 'data' and 'key' are required!";
|
|
2035
|
+
const request = this.factory.update({
|
|
2036
|
+
urlOptions: this.urlOptions,
|
|
2037
|
+
key: parameters.key,
|
|
2038
|
+
data: parameters.data,
|
|
2039
|
+
action: parameters.action,
|
|
2040
|
+
saveTemp: parameters.saveTemp,
|
|
2041
|
+
successCb: parameters.successCb,
|
|
2042
|
+
failureCb: parameters.failureCb
|
|
2043
|
+
});
|
|
2044
|
+
request.execute();
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Executes a DELETE request to delete a single item.
|
|
2048
|
+
*
|
|
2049
|
+
* @param parameters Item key, optional action, and callbacks.
|
|
2050
|
+
* @returns Nothing. The result is delivered to `successCb` or `failureCb`.
|
|
2051
|
+
* @throws If `key` is missing.
|
|
2052
|
+
*/
|
|
2053
|
+
destroy(parameters) {
|
|
2054
|
+
if (!parameters.key)
|
|
2055
|
+
throw "Parameter 'key' is required!";
|
|
2056
|
+
const request = this.factory.destroy({
|
|
2057
|
+
urlOptions: this.urlOptions,
|
|
2058
|
+
key: parameters.key,
|
|
2059
|
+
action: parameters.action,
|
|
2060
|
+
successCb: parameters.successCb,
|
|
2061
|
+
failureCb: parameters.failureCb
|
|
2062
|
+
});
|
|
2063
|
+
request.execute();
|
|
2064
|
+
}
|
|
2065
|
+
/**
|
|
2066
|
+
* Executes a POST request to execute a workflow operation for a single item.
|
|
2067
|
+
*
|
|
2068
|
+
* @param parameters Item key, operation data, and callbacks.
|
|
2069
|
+
* @returns Nothing. The operation result is delivered to a callback.
|
|
2070
|
+
* @throws If `key` or `data` is missing.
|
|
2071
|
+
*/
|
|
2072
|
+
operation(parameters) {
|
|
2073
|
+
if (parameters.key === void 0 || parameters.key === null || !parameters.data)
|
|
2074
|
+
throw "Parameters: 'data' and 'key' are required!";
|
|
2075
|
+
const request = this.factory.create({
|
|
2076
|
+
urlOptions: this.urlOptions,
|
|
2077
|
+
key: parameters.key,
|
|
2078
|
+
action: "operation",
|
|
2079
|
+
data: parameters.data,
|
|
2080
|
+
successCb: parameters.successCb,
|
|
2081
|
+
failureCb: parameters.failureCb
|
|
2082
|
+
});
|
|
2083
|
+
request.execute();
|
|
2084
|
+
}
|
|
2085
|
+
/**
|
|
2086
|
+
* Executes a GET request to retrieve a property of a single item.
|
|
2087
|
+
*
|
|
2088
|
+
* @param parameters Item key, property name, and callbacks.
|
|
2089
|
+
* @returns Nothing. The property value is delivered to a callback.
|
|
2090
|
+
* @throws If `key` or `property` is missing.
|
|
2091
|
+
*/
|
|
2092
|
+
getProperty(parameters) {
|
|
2093
|
+
if (parameters.key === void 0 || parameters.key === null || !parameters.property)
|
|
2094
|
+
throw "Parameters: 'data' and 'property' are required!";
|
|
2095
|
+
const request = this.factory.getProperty({
|
|
2096
|
+
urlOptions: this.urlOptions,
|
|
2097
|
+
key: parameters.key,
|
|
2098
|
+
property: parameters.property,
|
|
2099
|
+
successCb: parameters.successCb,
|
|
2100
|
+
failureCb: parameters.failureCb
|
|
2101
|
+
});
|
|
2102
|
+
request.execute();
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Executes a GET request to retrieve a related property value of a single item.
|
|
2106
|
+
*
|
|
2107
|
+
* @param parameters Item key, relation property name, and callbacks.
|
|
2108
|
+
* @returns Nothing. The related value is delivered to a callback.
|
|
2109
|
+
* @throws If `key` or `property` is missing.
|
|
2110
|
+
*/
|
|
2111
|
+
getRelated(parameters) {
|
|
2112
|
+
if (parameters.key === void 0 || parameters.key === null || !parameters.property)
|
|
2113
|
+
throw "Parameters: 'data' and 'property' are required!";
|
|
2114
|
+
const request = this.factory.getRelated({
|
|
2115
|
+
urlOptions: this.urlOptions,
|
|
2116
|
+
key: parameters.key,
|
|
2117
|
+
property: parameters.property,
|
|
2118
|
+
successCb: parameters.successCb,
|
|
2119
|
+
failureCb: parameters.failureCb
|
|
2120
|
+
});
|
|
2121
|
+
request.execute();
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Executes a GET request to retrieve a related item by its ID.
|
|
2125
|
+
*
|
|
2126
|
+
* @param parameters Item key, relation property, related item ID, and callbacks.
|
|
2127
|
+
* @returns Nothing. The related item is delivered to a callback.
|
|
2128
|
+
* @throws If `key`, `property`, or `relatedId` is missing.
|
|
2129
|
+
*/
|
|
2130
|
+
getRelatedById(parameters) {
|
|
2131
|
+
if (parameters.key === void 0 || parameters.key === null || !parameters.property || parameters.relatedId === void 0 || parameters.relatedId === null)
|
|
2132
|
+
throw "Parameters: 'data', 'relatedId' and 'property' are required!";
|
|
2133
|
+
const request = this.factory.getRelatedById({
|
|
2134
|
+
urlOptions: this.urlOptions,
|
|
2135
|
+
key: parameters.key,
|
|
2136
|
+
relatedId: parameters.relatedId,
|
|
2137
|
+
property: parameters.property,
|
|
2138
|
+
successCb: parameters.successCb,
|
|
2139
|
+
failureCb: parameters.failureCb
|
|
2140
|
+
});
|
|
2141
|
+
request.execute();
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* Executes a DELETE request for all members associated with a relation property.
|
|
2145
|
+
*
|
|
2146
|
+
* @param parameters Item key, relation property, and callbacks.
|
|
2147
|
+
* @returns Nothing. The result is delivered to `successCb` or `failureCb`.
|
|
2148
|
+
* @throws If `key` or `property` is missing.
|
|
2149
|
+
*/
|
|
2150
|
+
destroyRelated(parameters) {
|
|
2151
|
+
if (parameters.key === void 0 || parameters.key === null || !parameters.property)
|
|
2152
|
+
throw "Parameters: 'data' and 'property' are required!";
|
|
2153
|
+
const request = this.factory.destroyRelated({
|
|
2154
|
+
urlOptions: this.urlOptions,
|
|
2155
|
+
key: parameters.key,
|
|
2156
|
+
property: parameters.property,
|
|
2157
|
+
successCb: parameters.successCb,
|
|
2158
|
+
failureCb: parameters.failureCb
|
|
2159
|
+
});
|
|
2160
|
+
request.execute();
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Executes a DELETE request for one member of a relation property.
|
|
2164
|
+
*
|
|
2165
|
+
* @param parameters Item key, relation property, related item ID, and callbacks.
|
|
2166
|
+
* @returns Nothing. The result is delivered to `successCb` or `failureCb`.
|
|
2167
|
+
* @throws If `key`, `property`, or `relatedId` is missing.
|
|
2168
|
+
*/
|
|
2169
|
+
destroyRelatedById(parameters) {
|
|
2170
|
+
if (parameters.key === void 0 || parameters.key === null || !parameters.property || parameters.relatedId === void 0 || parameters.relatedId === null)
|
|
2171
|
+
throw "Parameters: 'data', 'relatedId' and 'property' are required!";
|
|
2172
|
+
const request = this.factory.destroyRelatedById({
|
|
2173
|
+
urlOptions: this.urlOptions,
|
|
2174
|
+
key: parameters.key,
|
|
2175
|
+
relatedId: parameters.relatedId,
|
|
2176
|
+
property: parameters.property,
|
|
2177
|
+
successCb: parameters.successCb,
|
|
2178
|
+
failureCb: parameters.failureCb
|
|
2179
|
+
});
|
|
2180
|
+
request.execute();
|
|
2181
|
+
}
|
|
2182
|
+
/**
|
|
2183
|
+
* Executes a POST request to add a related item to a property collection.
|
|
2184
|
+
*
|
|
2185
|
+
* @param parameters Item key, relation property, related item link, and callbacks.
|
|
2186
|
+
* @returns Nothing. The result is delivered to `successCb` or `failureCb`.
|
|
2187
|
+
* @throws If `key`, `property`, or `link` is missing.
|
|
2188
|
+
*/
|
|
2189
|
+
createRelated(parameters) {
|
|
2190
|
+
if (parameters.key === void 0 || parameters.key === null || !parameters.property || parameters.link === void 0 || parameters.link === null)
|
|
2191
|
+
throw "Parameters: 'data', 'link' and 'property' are required!";
|
|
2192
|
+
const data = {
|
|
2193
|
+
"@odata.id": parameters.link
|
|
2194
|
+
};
|
|
2195
|
+
const request = this.factory.createRelated({
|
|
2196
|
+
urlOptions: this.urlOptions,
|
|
2197
|
+
key: parameters.key,
|
|
2198
|
+
property: parameters.property,
|
|
2199
|
+
data,
|
|
2200
|
+
successCb: parameters.successCb,
|
|
2201
|
+
failureCb: parameters.failureCb
|
|
2202
|
+
});
|
|
2203
|
+
request.execute();
|
|
2204
|
+
}
|
|
2205
|
+
/**
|
|
2206
|
+
* Executes a POST request to upload a media item and optionally update or publish it.
|
|
2207
|
+
*
|
|
2208
|
+
* The SDK orchestrates the upload in a transaction. `content`, `contentType`, `name`,
|
|
2209
|
+
* and `uploadProperties` are required. When `payload` is supplied, it updates the
|
|
2210
|
+
* uploaded item; when `publish` is `true`, it then executes the `Publish` operation.
|
|
2211
|
+
*
|
|
2212
|
+
* @param parameters Upload data, optional post-upload payload, publish flag, and callbacks.
|
|
2213
|
+
* @returns Nothing. The result is delivered to `successCb` or `failureCb`.
|
|
2214
|
+
* @throws If required upload data is missing.
|
|
2215
|
+
*
|
|
2216
|
+
* @example
|
|
2217
|
+
* const data = sf.data({ entitySet: "images" });
|
|
2218
|
+
* data.upload({
|
|
2219
|
+
* data: {
|
|
2220
|
+
* content: "base64 file content",
|
|
2221
|
+
* contentType: "image/jpeg",
|
|
2222
|
+
* name: "test.jpg",
|
|
2223
|
+
* payload: { Title: "Test" },
|
|
2224
|
+
* uploadProperties: {
|
|
2225
|
+
* ParentId: "4BA7AD46-F29B-4E65-BE17-9BF7CE5BA1FB"
|
|
2226
|
+
* }
|
|
2227
|
+
* },
|
|
2228
|
+
* successCb,
|
|
2229
|
+
* failureCb
|
|
2230
|
+
* });
|
|
2231
|
+
*/
|
|
2232
|
+
upload(parameters) {
|
|
2233
|
+
if (!parameters?.data?.content || !parameters.data.contentType || !parameters.data.name || !parameters.data.uploadProperties)
|
|
2234
|
+
throw "parameters: content, contentType, name and uploadProperties are required!";
|
|
2235
|
+
const options = {
|
|
2236
|
+
urlOptions: this.urlOptions,
|
|
2237
|
+
_factory: this.factory,
|
|
2238
|
+
successCb: parameters.successCb,
|
|
2239
|
+
failureCb: parameters.failureCb
|
|
2240
|
+
};
|
|
2241
|
+
const batch = this.factory.batch(options);
|
|
2242
|
+
const transaction = batch.beginTransaction();
|
|
2243
|
+
const uploadedFile = transaction.upload({
|
|
2244
|
+
entitySet: this.urlOptions.entitySet,
|
|
2245
|
+
data: parameters.data.content,
|
|
2246
|
+
contentType: parameters.data.contentType,
|
|
2247
|
+
fileName: parameters.data.name,
|
|
2248
|
+
uploadProperties: parameters.data.uploadProperties
|
|
2249
|
+
});
|
|
2250
|
+
if (parameters.data.payload)
|
|
2251
|
+
transaction.update({
|
|
2252
|
+
entitySet: this.urlOptions.entitySet,
|
|
2253
|
+
key: uploadedFile,
|
|
2254
|
+
data: parameters.data.payload
|
|
2255
|
+
});
|
|
2256
|
+
if (parameters.publish === true) {
|
|
2257
|
+
transaction.operation({
|
|
2258
|
+
entitySet: this.urlOptions.entitySet,
|
|
2259
|
+
key: uploadedFile,
|
|
2260
|
+
data: {
|
|
2261
|
+
action: "Publish"
|
|
2262
|
+
}
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
batch.endTransaction(transaction);
|
|
2266
|
+
return batch.execute();
|
|
2267
|
+
}
|
|
2268
|
+
};
|
|
2269
|
+
|
|
2270
|
+
// src/QueryBase.ts
|
|
2271
|
+
var QueryBase = class {
|
|
2272
|
+
/** Creates an empty projection. */
|
|
2273
|
+
constructor() {
|
|
2274
|
+
this.selectProperties = null;
|
|
2275
|
+
this.expandProperties = null;
|
|
2276
|
+
}
|
|
2277
|
+
/**
|
|
2278
|
+
* Selects the scalar fields returned by the service.
|
|
2279
|
+
*
|
|
2280
|
+
* Duplicate names are removed while preserving their first occurrence.
|
|
2281
|
+
* Property names must be simple paths without a dot.
|
|
2282
|
+
*
|
|
2283
|
+
* @param properties Field names to include.
|
|
2284
|
+
* @returns A cloned query with `$select` configured.
|
|
2285
|
+
* @throws Error If a property is not a string or is a nested path.
|
|
2286
|
+
*/
|
|
2287
|
+
select(...properties) {
|
|
2288
|
+
properties = properties ?? [];
|
|
2289
|
+
this.validatePropertyPaths(properties);
|
|
2290
|
+
return this.clone((newObj) => {
|
|
2291
|
+
newObj.selectProperties = properties.filter((prop, index, props) => props.indexOf(prop) === index);
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
/**
|
|
2295
|
+
* Selects the navigation properties expanded by the service.
|
|
2296
|
+
*
|
|
2297
|
+
* Duplicate names are removed while preserving their first occurrence.
|
|
2298
|
+
* Property names must be simple paths without a dot.
|
|
2299
|
+
*
|
|
2300
|
+
* @param properties Navigation property names to expand.
|
|
2301
|
+
* @returns A cloned query with `$expand` configured.
|
|
2302
|
+
* @throws Error If a property is not a string or is a nested path.
|
|
2303
|
+
*/
|
|
2304
|
+
expand(...properties) {
|
|
2305
|
+
properties = properties ?? [];
|
|
2306
|
+
this.validatePropertyPaths(properties);
|
|
2307
|
+
return this.clone((newObj) => {
|
|
2308
|
+
newObj.expandProperties = properties.filter((prop, index, props) => props.indexOf(prop) === index);
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
validatePropertyPaths(propPaths, allowNested = false) {
|
|
2312
|
+
for (let i = 0; i < propPaths.length; i++) {
|
|
2313
|
+
const member = propPaths[i];
|
|
2314
|
+
if (!utils.isString(member)) {
|
|
2315
|
+
throw new Error("Invalid argument in clause");
|
|
2316
|
+
}
|
|
2317
|
+
if (!allowNested && member.indexOf(".") > -1) {
|
|
2318
|
+
throw new Error("Invalid argument in clause");
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
clone(setter = null) {
|
|
2323
|
+
const newObj = utils.clone(this, Object.create(Object.getPrototypeOf(this)), setter);
|
|
2324
|
+
return newObj;
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
|
|
2328
|
+
// src/OrderProperty.ts
|
|
2329
|
+
var OrderProperty = class {
|
|
2330
|
+
/**
|
|
2331
|
+
* Creates an order-by descriptor.
|
|
2332
|
+
*
|
|
2333
|
+
* The property path may include a trailing `asc` or `desc` direction.
|
|
2334
|
+
* Without a direction, ascending order is used.
|
|
2335
|
+
*
|
|
2336
|
+
* @param propertyPath Property name, optionally followed by `asc` or `desc`.
|
|
2337
|
+
* @param isDesc Explicit direction override when supplied.
|
|
2338
|
+
* @throws Error If the property name is not a string or the direction is invalid.
|
|
2339
|
+
*/
|
|
2340
|
+
constructor(propertyPath, isDesc = null) {
|
|
2341
|
+
this.propertyPath = propertyPath;
|
|
2342
|
+
this.isDesc = isDesc;
|
|
2343
|
+
if (!utils.isString(propertyPath))
|
|
2344
|
+
throw new Error("Property name is not a valid string");
|
|
2345
|
+
propertyPath = propertyPath.trim();
|
|
2346
|
+
const parts = propertyPath.split(" ");
|
|
2347
|
+
if (parts.length > 1 && isDesc !== true && isDesc !== false) {
|
|
2348
|
+
isDesc = parts[1].toLowerCase() == "desc";
|
|
2349
|
+
if (!isDesc) {
|
|
2350
|
+
const isAsc = parts[1].toLowerCase() == "asc";
|
|
2351
|
+
if (!isAsc) {
|
|
2352
|
+
throw new Error("the second word in the propertyPath must begin with 'desc' or 'asc'");
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
this.propertyPath = parts[0];
|
|
2357
|
+
this.isDesc = isDesc;
|
|
2358
|
+
}
|
|
2359
|
+
/** Returns the property name without its direction. */
|
|
2360
|
+
getPropertyPath() {
|
|
2361
|
+
return this.propertyPath;
|
|
2362
|
+
}
|
|
2363
|
+
/** Returns `true` for descending order and `false` for ascending order. */
|
|
2364
|
+
getDirection() {
|
|
2365
|
+
return this.isDesc;
|
|
2366
|
+
}
|
|
2367
|
+
/** Returns the normalized `property direction` string used in `$orderby`. */
|
|
2368
|
+
getValue() {
|
|
2369
|
+
const direction = this.isDesc ? "desc" : "asc";
|
|
2370
|
+
return this.propertyPath + " " + direction;
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
|
|
2374
|
+
// src/QueryBuilder.ts
|
|
2375
|
+
var QueryBuilder = class {
|
|
2376
|
+
/** Creates a builder for the supplied query. */
|
|
2377
|
+
constructor(query) {
|
|
2378
|
+
this.query = query;
|
|
2379
|
+
}
|
|
2380
|
+
/**
|
|
2381
|
+
* Serializes the query into OData parameter names and values.
|
|
2382
|
+
*
|
|
2383
|
+
* Supported output keys are `$filter`, `$select`, `$expand`, `$orderby`,
|
|
2384
|
+
* `$skip`, `$top`, `$count`, and `$search`. Missing or empty clauses are
|
|
2385
|
+
* omitted. String constants are escaped and quoted; GUID constants remain
|
|
2386
|
+
* unquoted, and `in` requires an array value.
|
|
2387
|
+
*
|
|
2388
|
+
* @returns An object suitable for the data request's query parameters.
|
|
2389
|
+
* @throws Error If the expression tree is invalid, an operator is unsupported,
|
|
2390
|
+
* or an `in` condition does not contain an array.
|
|
2391
|
+
*/
|
|
2392
|
+
build() {
|
|
2393
|
+
const queryParameters = {};
|
|
2394
|
+
const whereClause = this.query.filter;
|
|
2395
|
+
if (whereClause instanceof WhereQuery) {
|
|
2396
|
+
const expression = whereClause.getExpression();
|
|
2397
|
+
if (expression instanceof ComplexExpression) {
|
|
2398
|
+
const result = this.buildComplexExpression(expression, null);
|
|
2399
|
+
if (result) {
|
|
2400
|
+
queryParameters[ODATA_PARAMS.$filter] = result;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
const selectClause = this.query.selectProperties;
|
|
2405
|
+
if (selectClause instanceof Array) {
|
|
2406
|
+
queryParameters[ODATA_PARAMS.$select] = selectClause.join(", ");
|
|
2407
|
+
}
|
|
2408
|
+
const expandClause = this.query.expandProperties;
|
|
2409
|
+
if (expandClause instanceof Array)
|
|
2410
|
+
queryParameters[ODATA_PARAMS.$expand] = expandClause.join(", ");
|
|
2411
|
+
const orderByClause = this.query.orderProperties;
|
|
2412
|
+
if (orderByClause instanceof Array) {
|
|
2413
|
+
const order = [];
|
|
2414
|
+
for (const i in orderByClause) {
|
|
2415
|
+
if (orderByClause[i] instanceof OrderProperty)
|
|
2416
|
+
order.push(orderByClause[i].getValue());
|
|
2417
|
+
}
|
|
2418
|
+
queryParameters[ODATA_PARAMS.$orderby] = order.join(", ");
|
|
2419
|
+
}
|
|
2420
|
+
const take = this.query.takeValue;
|
|
2421
|
+
if (utils.isNumber(take))
|
|
2422
|
+
queryParameters[ODATA_PARAMS.$top] = take;
|
|
2423
|
+
const skip = this.query.skipValue;
|
|
2424
|
+
if (utils.isNumber(skip))
|
|
2425
|
+
queryParameters[ODATA_PARAMS.$skip] = skip;
|
|
2426
|
+
const search = this.query.searchValue;
|
|
2427
|
+
if (search)
|
|
2428
|
+
queryParameters[ODATA_PARAMS.$search] = search;
|
|
2429
|
+
if (this.query.inlineCount !== null) {
|
|
2430
|
+
queryParameters[ODATA_PARAMS.$count] = this.query.inlineCount;
|
|
2431
|
+
}
|
|
2432
|
+
return queryParameters;
|
|
2433
|
+
}
|
|
2434
|
+
buildComplexExpression(expression, parent) {
|
|
2435
|
+
if (!(expression instanceof ComplexExpression))
|
|
2436
|
+
throw new Error("Invalid complex expression");
|
|
2437
|
+
let counter = 0;
|
|
2438
|
+
let result = "";
|
|
2439
|
+
const subExpressions = expression.getExpressions();
|
|
2440
|
+
if (!subExpressions.length) {
|
|
2441
|
+
return result;
|
|
2442
|
+
}
|
|
2443
|
+
while (true) {
|
|
2444
|
+
const currentExp = subExpressions[counter];
|
|
2445
|
+
if (currentExp instanceof BinaryExpression) {
|
|
2446
|
+
result += this.buildBinaryExpression(currentExp);
|
|
2447
|
+
} else if (currentExp instanceof ComplexExpression) {
|
|
2448
|
+
const complexResult = this.buildComplexExpression(currentExp, expression.type);
|
|
2449
|
+
if (complexResult) {
|
|
2450
|
+
result += "(" + complexResult + ")";
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
if (expression.getType() === EXPRESSION_TYPE.not)
|
|
2454
|
+
result = expression.getType() + " " + result;
|
|
2455
|
+
if (expression.getType() === EXPRESSION_TYPE.any) {
|
|
2456
|
+
const exprVal = [];
|
|
2457
|
+
for (let index = 0; index < subExpressions.length; index++) {
|
|
2458
|
+
if (subExpressions[index].type == EXPRESSION_TYPE.contains || subExpressions[index].type == EXPRESSION_TYPE.startsWith || subExpressions[index].type == EXPRESSION_TYPE.endsWith)
|
|
2459
|
+
exprVal.push(subExpressions[index].type.toLowerCase() + "(x, '" + subExpressions[index].constant + "')");
|
|
2460
|
+
else
|
|
2461
|
+
exprVal.push("x " + subExpressions[index].type.toLowerCase() + " " + this.checkType(subExpressions[index].constant));
|
|
2462
|
+
}
|
|
2463
|
+
result = currentExp.parameter + "/" + expression.getType() + "(x:" + exprVal.join(" " + parent + " ") + ")";
|
|
2464
|
+
}
|
|
2465
|
+
counter++;
|
|
2466
|
+
if (counter == subExpressions.length)
|
|
2467
|
+
break;
|
|
2468
|
+
result += " " + expression.getType() + " ";
|
|
2469
|
+
}
|
|
2470
|
+
return result;
|
|
2471
|
+
}
|
|
2472
|
+
buildBinaryExpression(expression) {
|
|
2473
|
+
let result = null;
|
|
2474
|
+
const type = expression.getType();
|
|
2475
|
+
switch (type) {
|
|
2476
|
+
case EXPRESSION_TYPE.eq:
|
|
2477
|
+
case EXPRESSION_TYPE.ne:
|
|
2478
|
+
case EXPRESSION_TYPE.lt:
|
|
2479
|
+
case EXPRESSION_TYPE.le:
|
|
2480
|
+
case EXPRESSION_TYPE.gt:
|
|
2481
|
+
case EXPRESSION_TYPE.ge: {
|
|
2482
|
+
const constant = expression.getConstant();
|
|
2483
|
+
result = `(${expression.getParameter()} ${type} ${this.checkType(constant)})`;
|
|
2484
|
+
break;
|
|
2485
|
+
}
|
|
2486
|
+
case EXPRESSION_TYPE.contains:
|
|
2487
|
+
case EXPRESSION_TYPE.startsWith:
|
|
2488
|
+
case EXPRESSION_TYPE.endsWith: {
|
|
2489
|
+
const expressionParameter = this.applyCaseSensitiveSettings(expression, expression.getParameter());
|
|
2490
|
+
const expressionConstant = this.checkType(expression.getConstant(), true);
|
|
2491
|
+
const expressionValue = this.applyCaseSensitiveSettings(expression, expressionConstant);
|
|
2492
|
+
result = `${type.toLowerCase()}(${expressionParameter}, ${expressionValue})`;
|
|
2493
|
+
break;
|
|
2494
|
+
}
|
|
2495
|
+
case EXPRESSION_TYPE.in: {
|
|
2496
|
+
const valueArray = expression.getConstant();
|
|
2497
|
+
if (!Array.isArray(valueArray)) {
|
|
2498
|
+
throw new Error("Parameter is not an array!");
|
|
2499
|
+
}
|
|
2500
|
+
result = `${expression.getParameter()} in (${valueArray.join(", ")})`;
|
|
2501
|
+
break;
|
|
2502
|
+
}
|
|
2503
|
+
default: {
|
|
2504
|
+
const msg = `Unsupported operator ${type}`;
|
|
2505
|
+
throw new Error(msg);
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
return result;
|
|
2509
|
+
}
|
|
2510
|
+
applyCaseSensitiveSettings(expression, value) {
|
|
2511
|
+
if (expression.isCaseSensitive()) {
|
|
2512
|
+
return value;
|
|
2513
|
+
}
|
|
2514
|
+
return `tolower(${value})`;
|
|
2515
|
+
}
|
|
2516
|
+
checkType(constant, treatAsString = false) {
|
|
2517
|
+
if (this.isGuid(constant) && !treatAsString)
|
|
2518
|
+
return constant;
|
|
2519
|
+
if (constant == null)
|
|
2520
|
+
return null;
|
|
2521
|
+
constant = constant.replace(/[+/?%#&]/g, function($0) {
|
|
2522
|
+
return encodeURIComponent($0);
|
|
2523
|
+
});
|
|
2524
|
+
constant = constant.replace(/'/g, "''");
|
|
2525
|
+
return "'" + constant + "'";
|
|
2526
|
+
}
|
|
2527
|
+
isGuid(constant) {
|
|
2528
|
+
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(constant);
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
|
|
2532
|
+
// src/Query.ts
|
|
2533
|
+
var Query = class extends QueryBase {
|
|
2534
|
+
/** Creates an empty query with no selected fields, filters, ordering, or paging. */
|
|
2535
|
+
constructor() {
|
|
2536
|
+
super();
|
|
2537
|
+
/** The order-by clauses, when an order has been configured. */
|
|
2538
|
+
this.orderProperties = null;
|
|
2539
|
+
/** The number of records to skip, when paging is configured. */
|
|
2540
|
+
this.skipValue = null;
|
|
2541
|
+
/** The maximum number of records to return, when paging is configured. */
|
|
2542
|
+
this.takeValue = null;
|
|
2543
|
+
/** The full-text search expression, when configured. */
|
|
2544
|
+
this.searchValue = null;
|
|
2545
|
+
/** The root filter expression, when a where clause has been configured. */
|
|
2546
|
+
this.filter = null;
|
|
2547
|
+
}
|
|
2548
|
+
/**
|
|
2549
|
+
* Starts a filter expression.
|
|
2550
|
+
*
|
|
2551
|
+
* The returned builder is generic over its parent query. Call `done()` to
|
|
2552
|
+
* return to this query; nested logical groups require one `done()` per group.
|
|
2553
|
+
*
|
|
2554
|
+
* @returns A fluent filter builder.
|
|
2555
|
+
*/
|
|
2556
|
+
where() {
|
|
2557
|
+
const clone = this.clone((newObj) => {
|
|
2558
|
+
newObj.filter = new WhereQuery(newObj);
|
|
2559
|
+
});
|
|
2560
|
+
return clone.filter;
|
|
2561
|
+
}
|
|
2562
|
+
/**
|
|
2563
|
+
* Specifies one or more order-by clauses.
|
|
2564
|
+
*
|
|
2565
|
+
* Each property may be followed by `asc` or `desc`; ascending order is the
|
|
2566
|
+
* default. Property names must be simple paths without a dot.
|
|
2567
|
+
*
|
|
2568
|
+
* @param properties Property names and optional directions.
|
|
2569
|
+
* @returns A cloned query containing the requested ordering.
|
|
2570
|
+
* @throws Error If a property is not a string, contains a nested path, or
|
|
2571
|
+
* has an invalid direction.
|
|
2572
|
+
*
|
|
2573
|
+
* @example
|
|
2574
|
+
* new Query().order("Title desc", "PublicationDate asc");
|
|
2575
|
+
*/
|
|
2576
|
+
order(...properties) {
|
|
2577
|
+
properties = properties ?? [];
|
|
2578
|
+
this.validatePropertyPaths(properties);
|
|
2579
|
+
return this.clone((newObj) => {
|
|
2580
|
+
const orderItems = [];
|
|
2581
|
+
for (let i = 0; i < properties.length; i++) {
|
|
2582
|
+
const member = properties[i];
|
|
2583
|
+
const orderProp = new OrderProperty(member);
|
|
2584
|
+
orderItems.push(orderProp);
|
|
2585
|
+
}
|
|
2586
|
+
newObj.orderProperties = orderItems;
|
|
2587
|
+
});
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Skips a number of records before returning results.
|
|
2591
|
+
*
|
|
2592
|
+
* @param value Number of records to skip.
|
|
2593
|
+
* @returns A cloned query with `$skip` configured.
|
|
2594
|
+
*/
|
|
2595
|
+
skip(value) {
|
|
2596
|
+
return this.clone((newObj) => {
|
|
2597
|
+
newObj.skipValue = value;
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* Limits the number of records returned.
|
|
2602
|
+
*
|
|
2603
|
+
* @param value Maximum number of records to return.
|
|
2604
|
+
* @returns A cloned query with `$top` configured.
|
|
2605
|
+
*/
|
|
2606
|
+
take(value) {
|
|
2607
|
+
return this.clone((newObj) => {
|
|
2608
|
+
newObj.takeValue = value;
|
|
2609
|
+
});
|
|
2610
|
+
}
|
|
2611
|
+
/**
|
|
2612
|
+
* Adds a full-text search expression.
|
|
2613
|
+
*
|
|
2614
|
+
* @param value Search text understood by the Sitefinity service.
|
|
2615
|
+
* @returns A cloned query with `$search` configured.
|
|
2616
|
+
*/
|
|
2617
|
+
search(value) {
|
|
2618
|
+
return this.clone((newObj) => {
|
|
2619
|
+
newObj.searchValue = value;
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
/**
|
|
2623
|
+
* Requests the total matching count with the result.
|
|
2624
|
+
*
|
|
2625
|
+
* @param inline Whether `$count` should be enabled. Defaults to `true`.
|
|
2626
|
+
* @returns A cloned query with `$count` configured.
|
|
2627
|
+
*/
|
|
2628
|
+
count(inline = true) {
|
|
2629
|
+
return this.clone((newObj) => {
|
|
2630
|
+
newObj.inlineCount = inline;
|
|
2631
|
+
});
|
|
2632
|
+
}
|
|
2633
|
+
/**
|
|
2634
|
+
* Converts this query into OData query parameters.
|
|
2635
|
+
*
|
|
2636
|
+
* The returned object may contain `$filter`, `$select`, `$expand`,
|
|
2637
|
+
* `$orderby`, `$skip`, `$top`, `$count`, and `$search`. Empty clauses are
|
|
2638
|
+
* omitted. Building does not mutate the query.
|
|
2639
|
+
*
|
|
2640
|
+
* @returns The query parameter object for a data request.
|
|
2641
|
+
*/
|
|
2642
|
+
build() {
|
|
2643
|
+
return new QueryBuilder(this).build();
|
|
2644
|
+
}
|
|
2645
|
+
};
|
|
2646
|
+
|
|
2647
|
+
// src/Sitefinity.ts
|
|
2648
|
+
var Sitefinity = class {
|
|
2649
|
+
/**
|
|
2650
|
+
* Creates the SDK entry point.
|
|
2651
|
+
*
|
|
2652
|
+
* @param options Service URL and optional site-level configuration.
|
|
2653
|
+
*/
|
|
2654
|
+
constructor(options) {
|
|
2655
|
+
this.baseUrl = options.baseUrl;
|
|
2656
|
+
this.siteId = options.siteId;
|
|
2657
|
+
this.factory = new RequestFactory(options);
|
|
2658
|
+
}
|
|
2659
|
+
/**
|
|
2660
|
+
* Creates a data client for an entity set.
|
|
2661
|
+
*
|
|
2662
|
+
* The returned client uses the SDK defaults unless a URL, provider, culture, site,
|
|
2663
|
+
* query parameters, or headers are overridden in `options`.
|
|
2664
|
+
*
|
|
2665
|
+
* @param options Entity-set and request URL options.
|
|
2666
|
+
* @returns A data client for the requested entity set.
|
|
2667
|
+
*
|
|
2668
|
+
* @example
|
|
2669
|
+
* const news = sdk.data({ entitySet: "newsitems", culture: "en" });
|
|
2670
|
+
* news.get({ successCb: items => console.log(items) });
|
|
2671
|
+
*/
|
|
2672
|
+
data(options) {
|
|
2673
|
+
const urlOptions = {
|
|
2674
|
+
baseUrl: utils.addTrailingSlash(options.baseUrl || this.baseUrl),
|
|
2675
|
+
provider: options.provider,
|
|
2676
|
+
culture: options.culture,
|
|
2677
|
+
siteId: options.siteId || this.siteId,
|
|
2678
|
+
additionalQueryParams: options.additionalQueryParams,
|
|
2679
|
+
additionalHeaders: options.additionalHeaders,
|
|
2680
|
+
entitySet: options.entitySet
|
|
2681
|
+
};
|
|
2682
|
+
return new Data(urlOptions, this.factory);
|
|
2683
|
+
}
|
|
2684
|
+
/**
|
|
2685
|
+
* Creates a batch for grouping requests and optional upload, update, or workflow operations.
|
|
2686
|
+
*
|
|
2687
|
+
* Call `execute()` after adding requests. The callbacks receive the batch response,
|
|
2688
|
+
* failure payload, and progress event respectively. Batch options override SDK URL options.
|
|
2689
|
+
*
|
|
2690
|
+
* @param success Callback invoked when the batch succeeds.
|
|
2691
|
+
* @param failure Callback invoked when the batch fails.
|
|
2692
|
+
* @param progress Callback invoked as request progress is reported.
|
|
2693
|
+
* @param options Optional URL and request options for the batch.
|
|
2694
|
+
* @returns A batch request that can be populated and executed.
|
|
2695
|
+
*/
|
|
2696
|
+
batch(success, failure, progress, options) {
|
|
2697
|
+
if (!options)
|
|
2698
|
+
options = {};
|
|
2699
|
+
const batch = this.factory.batch({
|
|
2700
|
+
successCb: success,
|
|
2701
|
+
failureCb: failure,
|
|
2702
|
+
progressCb: progress,
|
|
2703
|
+
urlOptions: {
|
|
2704
|
+
baseUrl: utils.addTrailingSlash(options.baseUrl || this.baseUrl),
|
|
2705
|
+
provider: options.provider,
|
|
2706
|
+
culture: options.culture,
|
|
2707
|
+
siteId: options.siteId || this.siteId,
|
|
2708
|
+
additionalQueryParams: options.additionalQueryParams,
|
|
2709
|
+
additionalHeaders: options.additionalHeaders
|
|
2710
|
+
}
|
|
2711
|
+
});
|
|
2712
|
+
return batch;
|
|
2713
|
+
}
|
|
2714
|
+
/**
|
|
2715
|
+
* Sets the value sent in the `Authorization` header.
|
|
2716
|
+
*
|
|
2717
|
+
* The current token form is `{ type, value }`, for example
|
|
2718
|
+
* `{ type: "Bearer", value: "token" }`. A raw string is also accepted at runtime
|
|
2719
|
+
* for backward compatibility and is sent unchanged.
|
|
2720
|
+
*
|
|
2721
|
+
* @param token Token object or legacy raw authorization header value.
|
|
2722
|
+
*/
|
|
2723
|
+
setToken(token) {
|
|
2724
|
+
this.factory.token = token;
|
|
2725
|
+
}
|
|
2726
|
+
};
|
|
2727
|
+
/**
|
|
2728
|
+
* Query builder constructor exposed for consumers that need to build OData queries.
|
|
2729
|
+
*/
|
|
2730
|
+
Sitefinity.Query = Query;
|
|
2731
|
+
|
|
2732
|
+
// src/Transport/FetchTransport.ts
|
|
2733
|
+
var FetchTransport = class {
|
|
2734
|
+
/**
|
|
2735
|
+
* Creates a fetch-based transport.
|
|
2736
|
+
*
|
|
2737
|
+
* @param fetchImplementation Fetch function to use. Defaults to the global `fetch`, resolved when sending.
|
|
2738
|
+
*/
|
|
2739
|
+
constructor(fetchImplementation) {
|
|
2740
|
+
this.fetchImplementation = fetchImplementation;
|
|
2741
|
+
}
|
|
2742
|
+
/** Sends the request with `fetch`. A failure to get any response is reported with status `0`. */
|
|
2743
|
+
send(request, onComplete) {
|
|
2744
|
+
const send = this.fetchImplementation ?? globalThis.fetch.bind(globalThis);
|
|
2745
|
+
send(request.url, { method: request.method, headers: request.headers, body: request.body }).then((response) => response.text().then((body) => ({ response, body }))).then(
|
|
2746
|
+
({ response, body }) => onComplete({
|
|
2747
|
+
status: response.status,
|
|
2748
|
+
body,
|
|
2749
|
+
headers: readHeaders(response.headers)
|
|
2750
|
+
}),
|
|
2751
|
+
() => onComplete({ status: 0, body: "", headers: {} })
|
|
2752
|
+
);
|
|
2753
|
+
}
|
|
2754
|
+
};
|
|
2755
|
+
function readHeaders(source) {
|
|
2756
|
+
const headers = {};
|
|
2757
|
+
source.forEach((value, name) => {
|
|
2758
|
+
headers[name.toLowerCase()] = value;
|
|
2759
|
+
});
|
|
2760
|
+
return headers;
|
|
2761
|
+
}
|
|
2762
|
+
return __toCommonJS(sitefinity_webservices_sdk_exports);
|
|
2763
|
+
})();
|
|
2764
|
+
//# sourceMappingURL=sitefinity-webservices-sdk.js.map
|