@pi-r/azure 0.9.3 → 0.10.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/client/index.js CHANGED
@@ -35,7 +35,7 @@ function createStorageClient(credential) {
35
35
  if (!accountName) {
36
36
  credential.accountName = /AccountName=([^;]+);/.exec(connectionString)?.[1];
37
37
  }
38
- return storage.BlobServiceClient.fromConnectionString(connectionString);
38
+ return storage.BlobServiceClient.fromConnectionString(connectionString, credential.clientOptions);
39
39
  }
40
40
  if (accountSas && !accountSas.startsWith('?')) {
41
41
  accountSas = '?' + accountSas;
@@ -52,7 +52,17 @@ function createStorageClient(credential) {
52
52
  }
53
53
  return new storage.BlobServiceClient(sharedAccessSignature);
54
54
  }
55
- return new storage.BlobServiceClient(url, accountName && accountSas ? new storage.AnonymousCredential() : accountName && accountKey ? new storage.StorageSharedKeyCredential(accountName, accountKey) : new identity.DefaultAzureCredential());
55
+ let serviceCredential;
56
+ if (accountName && accountSas) {
57
+ serviceCredential = new storage.AnonymousCredential();
58
+ }
59
+ else if (accountName && accountKey) {
60
+ serviceCredential = new storage.StorageSharedKeyCredential(accountName, accountKey);
61
+ }
62
+ else {
63
+ serviceCredential = new identity.DefaultAzureCredential(credential.defaultAzureOptions);
64
+ }
65
+ return new storage.BlobServiceClient(url, serviceCredential, credential.clientOptions);
56
66
  }
57
67
  function createDatabaseClient(credential) {
58
68
  if (credential.username && credential.password && credential.tenantId && credential.clientId) {
package/download/index.js CHANGED
@@ -27,11 +27,15 @@ function download(credential, service = 'azure') {
27
27
  const blockSize = (flags & 4) && (0, types_1.alignSize)(target.chunkSize, 1024) || 0;
28
28
  let diskClient, destination;
29
29
  if (blockSize >= 2097152000 && (tempDir = this.getTempDir({ uuidDir: true }))) {
30
- diskClient = blobClient.downloadToFile(destination = path.join(tempDir, path.basename(target.filename || Key)), 0, undefined, { snapshot: target.versionId, abortSignal: this.signal });
30
+ destination = path.join(tempDir, path.basename(target.filename || Key));
31
+ diskClient = blobClient.downloadToFile(destination, 0, undefined, { snapshot: target.versionId, abortSignal: this.signal });
31
32
  }
32
- (diskClient || blobClient.downloadToBuffer(0, 0, { ...target.options, blockSize, concurrency: blockSize > 0 ? target.chunkLimit : undefined, abortSignal: this.signal }))
33
+ else {
34
+ diskClient = blobClient.downloadToBuffer(0, 0, { ...target.options, blockSize, concurrency: blockSize > 0 ? target.chunkLimit : undefined, abortSignal: this.signal });
35
+ }
36
+ diskClient
33
37
  .then((value) => {
34
- downloadResponse(null, diskClient && destination || value);
38
+ downloadResponse(null, destination || value);
35
39
  const deleteObject = target.deleteObject;
36
40
  if (deleteObject) {
37
41
  const location = Cloud.joinPath(Bucket, Key);
@@ -40,9 +44,10 @@ function download(credential, service = 'azure') {
40
44
  this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE });
41
45
  })
42
46
  .catch((err) => {
43
- if (!(err instanceof Error && err.code === 'BlobNotFound')) {
44
- this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
47
+ if (err instanceof Error && err.code === 'BlobNotFound') {
48
+ return;
45
49
  }
50
+ this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
46
51
  });
47
52
  }
48
53
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/azure",
3
- "version": "0.9.3",
3
+ "version": "0.10.0",
4
4
  "description": "Azure cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -19,11 +19,11 @@
19
19
  "license": "MIT",
20
20
  "homepage": "https://github.com/anpham6/pi-r#readme",
21
21
  "dependencies": {
22
- "@e-mc/cloud": "^0.11.4",
23
- "@e-mc/module": "^0.11.4",
24
- "@e-mc/types": "^0.11.4",
22
+ "@e-mc/cloud": "^0.12.0",
23
+ "@e-mc/module": "^0.12.0",
24
+ "@e-mc/types": "^0.12.0",
25
25
  "@azure/cosmos": "^4.3.0",
26
- "@azure/identity": "4.6.0",
26
+ "@azure/identity": "*",
27
27
  "@azure/storage-blob": "^12.27.0"
28
28
  }
29
29
  }
package/types/index.d.ts CHANGED
@@ -2,6 +2,8 @@ import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
2
2
  import type { AuthValue } from '@e-mc/types/lib/http';
3
3
 
4
4
  import type { CosmosClientOptions, FeedOptions, PartitionKey, PatchRequestBody, RequestOptions, SqlQuerySpec } from '@azure/cosmos';
5
+ import type { StoragePipelineOptions } from '@azure/storage-blob';
6
+ import type { DefaultAzureCredentialOptions } from '@azure/identity';
5
7
 
6
8
  export type AzureStorage = CloudStorage<AzureStorageCredential, "azure" | "az">;
7
9
 
@@ -11,6 +13,8 @@ export interface AzureStorageCredential {
11
13
  accountSas?: string;
12
14
  connectionString?: string;
13
15
  sharedAccessSignature?: string;
16
+ defaultAzureOptions?: DefaultAzureCredentialOptions;
17
+ clientOptions?: StoragePipelineOptions;
14
18
  }
15
19
 
16
20
  export interface AzureDatabaseQuery<T = FeedOptions | RequestOptions, U = PatchRequestBody | PlainObject> extends CloudDatabase<string | SqlQuerySpec, T, U, unknown[], AzureDatabaseCredential> {
package/upload/index.js CHANGED
@@ -174,7 +174,10 @@ function upload(credential, service = 'azure') {
174
174
  params.concurrency = data.upload.chunkLimit;
175
175
  uploadClient = blobClient.uploadData(Body[i], params);
176
176
  }
177
- (uploadClient || blobClient.upload(Body[i], Body[i].byteLength, params))
177
+ else {
178
+ uploadClient = blobClient.upload(Body[i], Body[i].byteLength, params);
179
+ }
180
+ uploadClient
178
181
  .then(result => {
179
182
  let requestUrl = result._response.request.url;
180
183
  const url = endpoint ? Cloud.joinPath(endpoint, blobName) : Cloud.isFile(requestUrl = decodeURIComponent(requestUrl), 'http/s') ? requestUrl : Cloud.joinPath(`https://${credential.accountName}.blob.core.windows.net`, bucket, blobName);