@azure/cosmos 3.13.1-alpha.20210830.2 → 3.14.1
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/CHANGELOG.md +19 -0
- package/dist/index.js +94 -27
- package/dist/index.js.map +1 -1
- package/dist/types/3.1/cosmos.d.ts +57 -4
- package/dist/types/latest/cosmos.d.ts +64 -4
- package/dist-esm/ClientContext.d.ts +8 -0
- package/dist-esm/ClientContext.d.ts.map +1 -1
- package/dist-esm/ClientContext.js +41 -3
- package/dist-esm/ClientContext.js.map +1 -1
- package/dist-esm/auth.d.ts.map +1 -1
- package/dist-esm/auth.js +0 -12
- package/dist-esm/auth.js.map +1 -1
- package/dist-esm/client/Item/Item.d.ts +10 -0
- package/dist-esm/client/Item/Item.d.ts.map +1 -1
- package/dist-esm/client/Item/Item.js +25 -0
- package/dist-esm/client/Item/Item.js.map +1 -1
- package/dist-esm/common/constants.d.ts +3 -1
- package/dist-esm/common/constants.d.ts.map +1 -1
- package/dist-esm/common/constants.js +3 -1
- package/dist-esm/common/constants.js.map +1 -1
- package/dist-esm/documents/ConnectionMode.d.ts +1 -1
- package/dist-esm/documents/ConnectionMode.js +1 -1
- package/dist-esm/documents/ConnectionMode.js.map +1 -1
- package/dist-esm/index.d.ts +2 -1
- package/dist-esm/index.d.ts.map +1 -1
- package/dist-esm/index.js +1 -0
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/utils/batch.d.ts +16 -2
- package/dist-esm/utils/batch.d.ts.map +1 -1
- package/dist-esm/utils/batch.js +4 -2
- package/dist-esm/utils/batch.js.map +1 -1
- package/dist-esm/utils/patch.d.ts +22 -0
- package/dist-esm/utils/patch.d.ts.map +1 -0
- package/dist-esm/utils/patch.js +10 -0
- package/dist-esm/utils/patch.js.map +1 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
## 3.14.1 (2021-09-02)
|
|
4
|
+
|
|
5
|
+
### Bugs Fixed
|
|
6
|
+
|
|
7
|
+
- Fix @azure/core-rest-pipeline version for AAD auth.
|
|
8
|
+
|
|
9
|
+
## 3.14.0 (2021-09-01)
|
|
10
|
+
|
|
11
|
+
### Features Added
|
|
12
|
+
|
|
13
|
+
- _PREVIEW_ Adds `container.item(itemId).patch()`. `patch()` is an alternative to `replace()` for item updates. https://github.com/Azure/azure-sdk-for-js/pull/16264/files#diff-7caca690c469e2025576523c0377ac71815f001024fde7c48b20cd24adaa6977R561
|
|
14
|
+
- _PREVIEW_ Adds support for Bulk operation PATCH.
|
|
15
|
+
- _PREVIEW_ Adds support for Batch operation PATCH.
|
|
16
|
+
|
|
17
|
+
### Bugs Fixed
|
|
18
|
+
|
|
19
|
+
- Fixes bug where Batch was passing the wrong header for batch requests with partition keys
|
|
20
|
+
- Fixes 401s when using AAD auth. AAD credentials should now work and no longer cause 429s from @azure/identity at high throughput.
|
|
21
|
+
|
|
3
22
|
## 3.13.1 (2021-08-23)
|
|
4
23
|
|
|
5
24
|
### Bugs Fixed
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
var universalUserAgent = require('universal-user-agent');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
|
-
var url = require('url');
|
|
10
9
|
var uuid$3 = require('uuid');
|
|
11
10
|
var tslib = require('tslib');
|
|
12
11
|
var debugLib = _interopDefault(require('debug'));
|
|
@@ -16,6 +15,7 @@ var stableStringify = _interopDefault(require('fast-json-stable-stringify'));
|
|
|
16
15
|
var JSBI = _interopDefault(require('jsbi'));
|
|
17
16
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
18
17
|
var AbortController = _interopDefault(require('node-abort-controller'));
|
|
18
|
+
var url = require('url');
|
|
19
19
|
|
|
20
20
|
// Copyright (c) Microsoft Corporation.
|
|
21
21
|
// Licensed under the MIT license.
|
|
@@ -170,7 +170,7 @@ const Constants = {
|
|
|
170
170
|
ThrottleRetryWaitTimeInMs: "x-ms-throttle-retry-wait-time-ms",
|
|
171
171
|
CurrentVersion: "2018-12-31",
|
|
172
172
|
SDKName: "azure-cosmos-js",
|
|
173
|
-
SDKVersion: "3.
|
|
173
|
+
SDKVersion: "3.14.1",
|
|
174
174
|
Quota: {
|
|
175
175
|
CollectionSize: "collectionSize"
|
|
176
176
|
},
|
|
@@ -232,6 +232,7 @@ const Constants = {
|
|
|
232
232
|
})(exports.ResourceType || (exports.ResourceType = {}));
|
|
233
233
|
(function (HTTPMethod) {
|
|
234
234
|
HTTPMethod["get"] = "GET";
|
|
235
|
+
HTTPMethod["patch"] = "PATCH";
|
|
235
236
|
HTTPMethod["post"] = "POST";
|
|
236
237
|
HTTPMethod["put"] = "PUT";
|
|
237
238
|
HTTPMethod["delete"] = "DELETE";
|
|
@@ -245,6 +246,7 @@ const Constants = {
|
|
|
245
246
|
OperationType["Query"] = "query";
|
|
246
247
|
OperationType["Execute"] = "execute";
|
|
247
248
|
OperationType["Batch"] = "batch";
|
|
249
|
+
OperationType["Patch"] = "patch";
|
|
248
250
|
})(exports.OperationType || (exports.OperationType = {}));
|
|
249
251
|
/**
|
|
250
252
|
* @hidden
|
|
@@ -930,20 +932,11 @@ async function signature(masterKey, method, resourceType, resourceId = "", date
|
|
|
930
932
|
return encodeURIComponent("type=" + type + "&ver=" + version + "&sig=" + signed);
|
|
931
933
|
}
|
|
932
934
|
|
|
933
|
-
// Copyright (c) Microsoft Corporation.
|
|
934
|
-
function checkURL(testString) {
|
|
935
|
-
return new url.URL(testString);
|
|
936
|
-
}
|
|
937
|
-
function sanitizeEndpoint(url$1) {
|
|
938
|
-
return new url.URL(url$1).href.replace(/\/$/, "");
|
|
939
|
-
}
|
|
940
|
-
|
|
941
935
|
// Copyright (c) Microsoft Corporation.
|
|
942
936
|
/**
|
|
943
937
|
* @hidden
|
|
944
938
|
*/
|
|
945
939
|
async function setAuthorizationHeader(clientOptions, verb, path, resourceId, resourceType, headers) {
|
|
946
|
-
var _a;
|
|
947
940
|
if (clientOptions.permissionFeed) {
|
|
948
941
|
clientOptions.resourceTokens = {};
|
|
949
942
|
for (const permission of clientOptions.permissionFeed) {
|
|
@@ -964,16 +957,6 @@ async function setAuthorizationHeader(clientOptions, verb, path, resourceId, res
|
|
|
964
957
|
else if (clientOptions.tokenProvider) {
|
|
965
958
|
headers[Constants.HttpHeaders.Authorization] = encodeURIComponent(await clientOptions.tokenProvider({ verb, path, resourceId, resourceType, headers }));
|
|
966
959
|
}
|
|
967
|
-
else if (clientOptions.aadCredentials) {
|
|
968
|
-
if (typeof ((_a = clientOptions.aadCredentials) === null || _a === void 0 ? void 0 : _a.getToken) !== "function") {
|
|
969
|
-
throw new Error("Cannot use AAD Credentials without `getToken`. See @azure/identity docs");
|
|
970
|
-
}
|
|
971
|
-
const hrefEndpoint = sanitizeEndpoint(clientOptions.endpoint);
|
|
972
|
-
const token = await clientOptions.aadCredentials.getToken(`${hrefEndpoint}/.default`);
|
|
973
|
-
const AUTH_PREFIX = `type=aad&ver=1.0&sig=`;
|
|
974
|
-
const authorizationToken = `${AUTH_PREFIX}${token.token}`;
|
|
975
|
-
headers[Constants.HttpHeaders.Authorization] = encodeURIComponent(authorizationToken);
|
|
976
|
-
}
|
|
977
960
|
}
|
|
978
961
|
/**
|
|
979
962
|
* The default function for setting header token using the masterKey
|
|
@@ -1048,10 +1031,12 @@ const BulkOperationType = {
|
|
|
1048
1031
|
Upsert: "Upsert",
|
|
1049
1032
|
Read: "Read",
|
|
1050
1033
|
Delete: "Delete",
|
|
1051
|
-
Replace: "Replace"
|
|
1034
|
+
Replace: "Replace",
|
|
1035
|
+
Patch: "Patch"
|
|
1052
1036
|
};
|
|
1053
1037
|
function hasResource(operation) {
|
|
1054
|
-
return operation.
|
|
1038
|
+
return (operation.operationType !== "Patch" &&
|
|
1039
|
+
operation.resourceBody !== undefined);
|
|
1055
1040
|
}
|
|
1056
1041
|
function getPartitionKeyToHash(operation, partitionProperty) {
|
|
1057
1042
|
const toHashKey = hasResource(operation)
|
|
@@ -1123,9 +1108,19 @@ function deepFind(document, path) {
|
|
|
1123
1108
|
return h;
|
|
1124
1109
|
}
|
|
1125
1110
|
|
|
1111
|
+
// Copyright (c) Microsoft Corporation.
|
|
1112
|
+
// Licensed under the MIT license.
|
|
1113
|
+
const PatchOperationType = {
|
|
1114
|
+
add: "add",
|
|
1115
|
+
replace: "replace",
|
|
1116
|
+
remove: "remove",
|
|
1117
|
+
set: "set",
|
|
1118
|
+
incr: "incr"
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1126
1121
|
// Copyright (c) Microsoft Corporation.
|
|
1127
1122
|
(function (ConnectionMode) {
|
|
1128
|
-
/** Gateway mode talks to
|
|
1123
|
+
/** Gateway mode talks to an intermediate gateway which handles the direct communication with your individual partitions. */
|
|
1129
1124
|
ConnectionMode[ConnectionMode["Gateway"] = 0] = "Gateway";
|
|
1130
1125
|
})(exports.ConnectionMode || (exports.ConnectionMode = {}));
|
|
1131
1126
|
|
|
@@ -4440,6 +4435,31 @@ class Item {
|
|
|
4440
4435
|
});
|
|
4441
4436
|
return new ItemResponse(response.result, response.headers, response.code, response.substatus, this);
|
|
4442
4437
|
}
|
|
4438
|
+
/**
|
|
4439
|
+
* Perform a JSONPatch on the item.
|
|
4440
|
+
*
|
|
4441
|
+
* Any provided type, T, is not necessarily enforced by the SDK.
|
|
4442
|
+
* You may get more or less properties and it's up to your logic to enforce it.
|
|
4443
|
+
*
|
|
4444
|
+
* @param options - Additional options for the request
|
|
4445
|
+
*/
|
|
4446
|
+
async patch(body, options = {}) {
|
|
4447
|
+
if (this.partitionKey === undefined) {
|
|
4448
|
+
const { resource: partitionKeyDefinition } = await this.container.readPartitionKeyDefinition();
|
|
4449
|
+
this.partitionKey = extractPartitionKey(body, partitionKeyDefinition);
|
|
4450
|
+
}
|
|
4451
|
+
const path = getPathFromLink(this.url);
|
|
4452
|
+
const id = getIdFromLink(this.url);
|
|
4453
|
+
const response = await this.clientContext.patch({
|
|
4454
|
+
body,
|
|
4455
|
+
path,
|
|
4456
|
+
resourceType: exports.ResourceType.item,
|
|
4457
|
+
resourceId: id,
|
|
4458
|
+
options,
|
|
4459
|
+
partitionKey: this.partitionKey
|
|
4460
|
+
});
|
|
4461
|
+
return new ItemResponse(response.result, response.headers, response.code, response.substatus, this);
|
|
4462
|
+
}
|
|
4443
4463
|
}
|
|
4444
4464
|
|
|
4445
4465
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -8119,6 +8139,14 @@ SessionContainer.EMPTY_SESSION_TOKEN = "";
|
|
|
8119
8139
|
SessionContainer.SESSION_TOKEN_SEPARATOR = ",";
|
|
8120
8140
|
SessionContainer.SESSION_TOKEN_PARTITION_SPLITTER = ":";
|
|
8121
8141
|
|
|
8142
|
+
// Copyright (c) Microsoft Corporation.
|
|
8143
|
+
function checkURL(testString) {
|
|
8144
|
+
return new url.URL(testString);
|
|
8145
|
+
}
|
|
8146
|
+
function sanitizeEndpoint(url$1) {
|
|
8147
|
+
return new url.URL(url$1).href.replace(/\/$/, "");
|
|
8148
|
+
}
|
|
8149
|
+
|
|
8122
8150
|
// Copyright (c) Microsoft Corporation.
|
|
8123
8151
|
const uuid$2 = uuid$3.v4;
|
|
8124
8152
|
/** @hidden */
|
|
@@ -8142,7 +8170,15 @@ class ClientContext {
|
|
|
8142
8170
|
const scope = `${hrefEndpoint}/.default`;
|
|
8143
8171
|
this.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
8144
8172
|
credential: cosmosClientOptions.aadCredentials,
|
|
8145
|
-
scopes: scope
|
|
8173
|
+
scopes: scope,
|
|
8174
|
+
challengeCallbacks: {
|
|
8175
|
+
async authorizeRequest({ request, getAccessToken }) {
|
|
8176
|
+
const tokenResponse = await getAccessToken([scope], {});
|
|
8177
|
+
const AUTH_PREFIX = `type=aad&ver=1.0&sig=`;
|
|
8178
|
+
const authorizationToken = `${AUTH_PREFIX}${tokenResponse.token}`;
|
|
8179
|
+
request.headers.set("Authorization", authorizationToken);
|
|
8180
|
+
}
|
|
8181
|
+
}
|
|
8146
8182
|
}));
|
|
8147
8183
|
}
|
|
8148
8184
|
}
|
|
@@ -8303,6 +8339,36 @@ class ClientContext {
|
|
|
8303
8339
|
throw err;
|
|
8304
8340
|
}
|
|
8305
8341
|
}
|
|
8342
|
+
async patch({ body, path, resourceType, resourceId, options = {}, partitionKey }) {
|
|
8343
|
+
try {
|
|
8344
|
+
const request$1 = {
|
|
8345
|
+
globalEndpointManager: this.globalEndpointManager,
|
|
8346
|
+
requestAgent: this.cosmosClientOptions.agent,
|
|
8347
|
+
connectionPolicy: this.connectionPolicy,
|
|
8348
|
+
method: exports.HTTPMethod.patch,
|
|
8349
|
+
client: this,
|
|
8350
|
+
operationType: exports.OperationType.Patch,
|
|
8351
|
+
path,
|
|
8352
|
+
resourceType,
|
|
8353
|
+
body,
|
|
8354
|
+
resourceId,
|
|
8355
|
+
options,
|
|
8356
|
+
plugins: this.cosmosClientOptions.plugins,
|
|
8357
|
+
partitionKey
|
|
8358
|
+
};
|
|
8359
|
+
request$1.headers = await this.buildHeaders(request$1);
|
|
8360
|
+
this.applySessionToken(request$1);
|
|
8361
|
+
// patch will use WriteEndpoint
|
|
8362
|
+
request$1.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request$1.resourceType, request$1.operationType);
|
|
8363
|
+
const response = await executePlugins(request$1, request, exports.PluginOn.operation);
|
|
8364
|
+
this.captureSessionToken(undefined, path, exports.OperationType.Patch, response.headers);
|
|
8365
|
+
return response;
|
|
8366
|
+
}
|
|
8367
|
+
catch (err) {
|
|
8368
|
+
this.captureSessionToken(err, path, exports.OperationType.Upsert, err.headers);
|
|
8369
|
+
throw err;
|
|
8370
|
+
}
|
|
8371
|
+
}
|
|
8306
8372
|
async create({ body, path, resourceType, resourceId, options = {}, partitionKey }) {
|
|
8307
8373
|
try {
|
|
8308
8374
|
const request$1 = {
|
|
@@ -8508,11 +8574,11 @@ class ClientContext {
|
|
|
8508
8574
|
resourceId,
|
|
8509
8575
|
plugins: this.cosmosClientOptions.plugins,
|
|
8510
8576
|
options,
|
|
8511
|
-
pipeline: this.pipeline
|
|
8577
|
+
pipeline: this.pipeline,
|
|
8578
|
+
partitionKey
|
|
8512
8579
|
};
|
|
8513
8580
|
request$1.headers = await this.buildHeaders(request$1);
|
|
8514
8581
|
request$1.headers[Constants.HttpHeaders.IsBatchRequest] = true;
|
|
8515
|
-
request$1.headers[Constants.HttpHeaders.PartitionKey] = partitionKey;
|
|
8516
8582
|
request$1.headers[Constants.HttpHeaders.IsBatchAtomic] = true;
|
|
8517
8583
|
this.applySessionToken(request$1);
|
|
8518
8584
|
request$1.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request$1.resourceType, request$1.operationType);
|
|
@@ -8983,6 +9049,7 @@ exports.Items = Items;
|
|
|
8983
9049
|
exports.Offer = Offer;
|
|
8984
9050
|
exports.OfferResponse = OfferResponse;
|
|
8985
9051
|
exports.Offers = Offers;
|
|
9052
|
+
exports.PatchOperationType = PatchOperationType;
|
|
8986
9053
|
exports.Permission = Permission;
|
|
8987
9054
|
exports.PermissionResponse = PermissionResponse;
|
|
8988
9055
|
exports.Permissions = Permissions;
|