@pi-r/azure 0.8.1 → 0.8.2

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
@@ -20,7 +20,7 @@ const util_1 = require("@e-mc/cloud/util");
20
20
  const types_1 = require("@e-mc/types");
21
21
  function validateStorage(credential) {
22
22
  const env = process.env;
23
- if (credential.accountName && credential.accountKey || credential.connectionString || credential.sharedAccessSignature || env.AZURE_TENANT_ID && env.AZURE_CLIENT_ID && env.AZURE_CLIENT_SECRET) {
23
+ if (credential.accountName && (credential.accountKey || credential.accountSas) || credential.connectionString || credential.sharedAccessSignature || env.AZURE_TENANT_ID && env.AZURE_CLIENT_ID && env.AZURE_CLIENT_SECRET) {
24
24
  return true;
25
25
  }
26
26
  return Cloud.enabled("process.env.apply") && !!((credential.connectionString = env.AZURE_STORAGE_CONNECTION_STRING) || (credential.sharedAccessSignature = env.AZURE_STORAGE_SAS_TOKEN) || (credential.accountName = env.AZURE_STORAGE_ACCOUNT) && (credential.accountKey = env.AZURE_STORAGE_KEY));
@@ -29,14 +29,17 @@ function validateDatabase(credential, data) {
29
29
  return !!(data.name && data.table && (credential.endpoint && credential.key || credential.username && credential.password && (credential.tenantId && credential.clientId || (credential.tenantId = process.env.AZURE_TENANT_ID) && (credential.clientId = process.env.AZURE_CLIENT_ID)) || Cloud.enabled("process.env.apply") && (credential.endpoint = process.env.AZURE_COSMOS_ENDPOINT) && (credential.key = process.env.AZURE_COSMOS_KEY)));
30
30
  }
31
31
  function createStorageClient(credential) {
32
- let { accountName, accountKey, connectionString, sharedAccessSignature } = credential;
32
+ let { accountName, accountKey, accountSas = '', connectionString, sharedAccessSignature } = credential;
33
33
  if (connectionString) {
34
34
  if (!accountName) {
35
35
  credential.accountName = /AccountName=([^;]+);/.exec(connectionString)?.[1];
36
36
  }
37
37
  return storage.BlobServiceClient.fromConnectionString(connectionString);
38
38
  }
39
- const url = `https://${accountName || process.env.AZURE_STORAGE_ACCOUNT}.blob.core.windows.net`;
39
+ if (accountSas && !accountSas.startsWith('?')) {
40
+ accountSas = '?' + accountSas;
41
+ }
42
+ const url = `https://${accountName || process.env.AZURE_STORAGE_ACCOUNT}.blob.core.windows.net${accountSas}`;
40
43
  if (sharedAccessSignature) {
41
44
  if (accountName) {
42
45
  if (!Cloud.isURL(sharedAccessSignature)) {
@@ -48,7 +51,7 @@ function createStorageClient(credential) {
48
51
  }
49
52
  return new storage.BlobServiceClient(sharedAccessSignature);
50
53
  }
51
- return new storage.BlobServiceClient(url, accountName && accountKey ? new storage.StorageSharedKeyCredential(accountName, accountKey) : new identity.DefaultAzureCredential());
54
+ return new storage.BlobServiceClient(url, accountName && accountSas ? new storage.AnonymousCredential() : accountName && accountKey ? new storage.StorageSharedKeyCredential(accountName, accountKey) : new identity.DefaultAzureCredential());
52
55
  }
53
56
  function createDatabaseClient(credential) {
54
57
  if (credential.username && credential.password && credential.tenantId && credential.clientId) {
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "@pi-r/azure",
3
- "version": "0.8.1",
4
- "description": "Azure cloud functions for E-mc.",
5
- "main": "client/index.js",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/anpham6/pi-r.git",
12
- "directory": "src/cloud/azure"
13
- },
14
- "keywords": [
15
- "squared",
16
- "e-mc",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/pi-r#readme",
22
- "dependencies": {
23
- "@e-mc/cloud": "^0.10.0",
24
- "@e-mc/module": "^0.10.0",
25
- "@e-mc/types": "^0.10.0",
26
- "@azure/cosmos": "^4.0.0",
27
- "@azure/identity": "^4.4.1",
28
- "@azure/storage-blob": "^12.24.0"
29
- }
30
- }
1
+ {
2
+ "name": "@pi-r/azure",
3
+ "version": "0.8.2",
4
+ "description": "Azure cloud functions for E-mc.",
5
+ "main": "client/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
+ "directory": "src/cloud/azure"
13
+ },
14
+ "keywords": [
15
+ "squared",
16
+ "e-mc",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/pi-r#readme",
22
+ "dependencies": {
23
+ "@e-mc/cloud": "^0.10.2",
24
+ "@e-mc/module": "^0.10.2",
25
+ "@e-mc/types": "^0.10.2",
26
+ "@azure/cosmos": "^4.1.1",
27
+ "@azure/identity": "^4.4.1",
28
+ "@azure/storage-blob": "^12.24.0"
29
+ }
30
+ }
package/types/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export type AzureStorage = CloudStorage<AzureStorageCredential, "azure" | "az">;
7
7
  export interface AzureStorageCredential {
8
8
  accountName?: string;
9
9
  accountKey?: string;
10
+ accountSas?: string;
10
11
  connectionString?: string;
11
12
  sharedAccessSignature?: string;
12
13
  }