@@ -9,10 +9,13 @@ import { maybeCast } from 'botbuilder-stdlib';
9
9
import { sanitizeBlobKey } from './sanitizeBlobKey' ;
10
10
11
11
import {
12
+ AnonymousCredential ,
12
13
ContainerClient ,
13
14
ContainerListBlobHierarchySegmentResponse ,
14
15
StoragePipelineOptions ,
16
+ StorageSharedKeyCredential ,
15
17
} from '@azure/storage-blob' ;
18
+ import { isTokenCredential , TokenCredential } from '@azure/core-http' ;
16
19
17
20
// Formats a timestamp in a way that is consistent with the C# SDK
18
21
function formatTicks ( timestamp : Date ) : string {
@@ -45,6 +48,12 @@ function getBlobKey(activity: Activity, options?: BlobsTranscriptStoreOptions):
45
48
) ;
46
49
}
47
50
51
+ function isCredentialType ( value : any ) : value is TokenCredential {
52
+ return (
53
+ isTokenCredential ( value ) || value instanceof StorageSharedKeyCredential || value instanceof AnonymousCredential
54
+ ) ;
55
+ }
56
+
48
57
// Max number of results returned in a single Azure API call
49
58
const MAX_PAGE_SIZE = 20 ;
50
59
@@ -85,21 +94,54 @@ export class BlobsTranscriptStore implements TranscriptStore {
85
94
* @param {string } connectionString Azure Blob Storage connection string
86
95
* @param {string } containerName Azure Blob Storage container name
87
96
* @param {BlobsTranscriptStoreOptions } options Other options for BlobsTranscriptStore
97
+ * @param {string } blobServiceUri A Uri referencing the blob container that includes the name of the account and the name of the container
98
+ * @param {StorageSharedKeyCredential | AnonymousCredential | TokenCredential } tokenCredential The token credential to authenticate to the Azure storage
88
99
*/
89
- constructor ( connectionString : string , containerName : string , options ?: BlobsTranscriptStoreOptions ) {
90
- z . object ( { connectionString : z . string ( ) , containerName : z . string ( ) } ) . parse ( {
91
- connectionString,
92
- containerName,
93
- } ) ;
100
+ constructor (
101
+ connectionString : string ,
102
+ containerName : string ,
103
+ options ?: BlobsTranscriptStoreOptions ,
104
+ blobServiceUri = '' ,
105
+ tokenCredential ?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential
106
+ ) {
107
+ if ( blobServiceUri != '' && tokenCredential != null ) {
108
+ z . object ( { blobServiceUri : z . string ( ) } ) . parse ( {
109
+ blobServiceUri,
110
+ } ) ;
94
111
95
- this . _containerClient = new ContainerClient ( connectionString , containerName , options ?. storagePipelineOptions ) ;
112
+ if ( typeof tokenCredential != 'object' || ! isCredentialType ( tokenCredential ) ) {
113
+ throw new ReferenceError ( 'Invalid credential type.' ) ;
114
+ }
96
115
97
- this . _isDecodeTranscriptKey = options ?. decodeTranscriptKey ;
116
+ this . _containerClient = new ContainerClient (
117
+ blobServiceUri ,
118
+ tokenCredential ,
119
+ options ?. storagePipelineOptions
120
+ ) ;
98
121
99
- // At most one promise at a time to be friendly to local emulator users
100
- if ( connectionString . trim ( ) === 'UseDevelopmentStorage=true;' ) {
101
- this . _concurrency = 1 ;
122
+ // At most one promise at a time to be friendly to local emulator users
123
+ if ( blobServiceUri . trim ( ) === 'UseDevelopmentStorage=true;' ) {
124
+ this . _concurrency = 1 ;
125
+ }
126
+ } else {
127
+ z . object ( { connectionString : z . string ( ) , containerName : z . string ( ) } ) . parse ( {
128
+ connectionString,
129
+ containerName,
130
+ } ) ;
131
+
132
+ this . _containerClient = new ContainerClient (
133
+ connectionString ,
134
+ containerName ,
135
+ options ?. storagePipelineOptions
136
+ ) ;
137
+
138
+ // At most one promise at a time to be friendly to local emulator users
139
+ if ( connectionString . trim ( ) === 'UseDevelopmentStorage=true;' ) {
140
+ this . _concurrency = 1 ;
141
+ }
102
142
}
143
+
144
+ this . _isDecodeTranscriptKey = options ?. decodeTranscriptKey ;
103
145
}
104
146
105
147
// Protects against JSON.stringify cycles
0 commit comments