@azure/data-tables 13.0.1-alpha.20211210.2 → 13.0.1-alpha.20211221.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/README.md CHANGED
@@ -123,6 +123,24 @@ const { TableServiceClient, AzureNamedKeyCredential } = require("@azure/data-tab
123
123
 
124
124
  The `TableServiceClient` requires a URL to the table service and an access credential. It also optionally accepts some settings in the `options` parameter.
125
125
 
126
+ #### `TableServiceClient` with AzureNamedKeyCredential
127
+
128
+ You can instantiate a `TableServiceClient` with a `AzureNamedKeyCredential` by passing account-name and account-key as arguments. (The account-name and account-key can be obtained from the azure portal.)
129
+ [ONLY AVAILABLE IN NODE.JS RUNTIME]
130
+
131
+ ```javascript
132
+ const { TableServiceClient, AzureNamedKeyCredential } = require("@azure/data-tables");
133
+
134
+ const account = "<account>";
135
+ const accountKey = "<accountkey>";
136
+
137
+ const credential = new AzureNamedKeyCredential(account, accountKey);
138
+ const serviceClient = new TableServiceClient(
139
+ `https://${account}.table.core.windows.net`,
140
+ credential
141
+ );
142
+ ```
143
+
126
144
  #### `TableServiceClient` with TokenCredential (AAD)
127
145
 
128
146
  Azure Tables provides integration with Azure Active Directory (Azure AD) for identity-based authentication of requests
@@ -220,7 +238,7 @@ const serviceClient = new TableServiceClient(
220
238
 
221
239
  async function main() {
222
240
  const tableName = `newtable`;
223
- // If the table 'newTable' already exists, createTable doesn' throw
241
+ // If the table 'newTable' already exists, createTable doesn't throw
224
242
  await serviceClient.createTable(tableName);
225
243
  }
226
244
 
@@ -326,6 +344,36 @@ const clientWithSAS = new TableClient(
326
344
  );
327
345
  ```
328
346
 
347
+ #### `TableClient` with TokenCredential (AAD)
348
+
349
+ Azure Tables provides integration with Azure Active Directory (Azure AD) for identity-based authentication of requests
350
+ to the Table service when targeting a Storage endpoint. With Azure AD, you can use role-based access control (RBAC) to
351
+ grant access to your Azure Table resources to users, groups, or applications.
352
+
353
+ To access a table resource with a `TokenCredential`, the authenticated identity should have either the "Storage Table Data Contributor" or "Storage Table Data Reader" role.
354
+
355
+ With the `@azure/identity` package, you can seamlessly authorize requests in both development and production environments.
356
+ To learn more about Azure AD integration in Azure Storage, see the [Azure.Identity README](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md)
357
+
358
+ ```javascript
359
+ const { TableClient } = require("@azure/data-tables");
360
+ const { DefaultAzureCredential } = require("@azure/identity");
361
+
362
+ // DefaultAzureCredential expects the following three environment variables:
363
+ // - AZURE_TENANT_ID: The tenant ID in Azure Active Directory
364
+ // - AZURE_CLIENT_ID: The application (client) ID registered in the AAD tenant
365
+ // - AZURE_CLIENT_SECRET: The client secret for the registered application
366
+ const credential = new DefaultAzureCredential();
367
+ const account = "<account name>";
368
+ const tableName = "<tableName>";
369
+
370
+ const clientWithAAD = new TableClient(
371
+ `https://${account}.table.core.windows.net`,
372
+ tableName,
373
+ credential
374
+ );
375
+ ```
376
+
329
377
  #### List Entities in a table
330
378
 
331
379
  You can list entities within a table by through a `TableClient` instance calling the `listEntities` function. This function returns a `PageableAsyncIterator` that you can consume using `for-await-of`
package/dist/index.js CHANGED
@@ -3854,7 +3854,8 @@ class InternalTableTransaction {
3854
3854
  * @param partitionKey - partition key
3855
3855
  * @param credential - credential to authenticate the transaction request
3856
3856
  */
3857
- constructor(url, partitionKey, transactionId, changesetId, interceptClient, credential, allowInsecureConnection = false) {
3857
+ constructor(url, partitionKey, transactionId, changesetId, clientOptions, interceptClient, credential, allowInsecureConnection = false) {
3858
+ this.clientOptions = clientOptions;
3858
3859
  this.credential = credential;
3859
3860
  this.url = url;
3860
3861
  this.interceptClient = interceptClient;
@@ -3949,7 +3950,7 @@ class InternalTableTransaction {
3949
3950
  async submitTransaction() {
3950
3951
  await Promise.all(this.resetableState.pendingOperations);
3951
3952
  const body = getTransactionHttpRequestBody(this.resetableState.bodyParts, this.resetableState.transactionId, this.resetableState.changesetId);
3952
- const options = {};
3953
+ const options = this.clientOptions;
3953
3954
  if (coreAuth.isTokenCredential(this.credential)) {
3954
3955
  options.credentialScopes = STORAGE_SCOPE;
3955
3956
  options.credential = this.credential;
@@ -4393,10 +4394,10 @@ class TableClient {
4393
4394
  this.tableName = tableName;
4394
4395
  const credential = isCredential(credentialOrOptions) ? credentialOrOptions : undefined;
4395
4396
  this.credential = credential;
4396
- const clientOptions = (!isCredential(credentialOrOptions) ? credentialOrOptions : options) || {};
4397
- this.allowInsecureConnection = (_a = clientOptions.allowInsecureConnection) !== null && _a !== void 0 ? _a : false;
4398
- clientOptions.endpoint = clientOptions.endpoint || this.url;
4399
- const internalPipelineOptions = Object.assign(Object.assign(Object.assign({}, clientOptions), { loggingOptions: {
4397
+ this.clientOptions = (!isCredential(credentialOrOptions) ? credentialOrOptions : options) || {};
4398
+ this.allowInsecureConnection = (_a = this.clientOptions.allowInsecureConnection) !== null && _a !== void 0 ? _a : false;
4399
+ this.clientOptions.endpoint = this.clientOptions.endpoint || this.url;
4400
+ const internalPipelineOptions = Object.assign(Object.assign(Object.assign({}, this.clientOptions), { loggingOptions: {
4400
4401
  logger: logger.info,
4401
4402
  additionalAllowedHeaderNames: [...TablesLoggingAllowedHeaderNames]
4402
4403
  }, deserializationOptions: {
@@ -4953,7 +4954,7 @@ class TableClient {
4953
4954
  const changesetId = Uuid.generateUuid();
4954
4955
  if (!this.transactionClient) {
4955
4956
  // Add pipeline
4956
- this.transactionClient = new InternalTableTransaction(this.url, partitionKey, transactionId, changesetId, new TableClient(this.url, this.tableName), this.credential, this.allowInsecureConnection);
4957
+ this.transactionClient = new InternalTableTransaction(this.url, partitionKey, transactionId, changesetId, this.clientOptions, new TableClient(this.url, this.tableName), this.credential, this.allowInsecureConnection);
4957
4958
  }
4958
4959
  else {
4959
4960
  this.transactionClient.reset(transactionId, changesetId, partitionKey);