@pi-r/azure 0.3.4 → 0.3.6
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/LICENSE +6 -6
- package/README.md +4 -6
- package/client/index.js +41 -31
- package/download/index.js +2 -2
- package/package.json +30 -30
- package/types/index.d.ts +30 -0
- package/upload/index.js +1 -1
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2023 An Pham
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeBatchQuery = exports.executeQuery = exports.deleteObjectsV2 = exports.deleteObjects = exports.setBucketWebsite = exports.createBucketV2 = exports.createBucket = exports.createDatabaseClient = exports.createStorageClient = exports.validateDatabase = exports.validateStorage = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const storage = require("@azure/storage-blob");
|
|
6
|
-
const cosmos = require("@azure/cosmos");
|
|
7
|
-
const identity = require("@azure/identity");
|
|
8
5
|
const types_1 = require("@e-mc/types");
|
|
9
6
|
const util_1 = require("@e-mc/cloud/util");
|
|
10
7
|
const Module = require("@e-mc/module");
|
|
@@ -23,28 +20,43 @@ function validateDatabase(credential, data) {
|
|
|
23
20
|
exports.validateDatabase = validateDatabase;
|
|
24
21
|
function createStorageClient(credential) {
|
|
25
22
|
var _a, _b;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
azureCredential
|
|
23
|
+
let packageName = '';
|
|
24
|
+
try {
|
|
25
|
+
const { BlobServiceClient, StorageSharedKeyCredential } = require(packageName = '@azure/storage-blob');
|
|
26
|
+
const { accountName, accountKey, connectionString, sharedAccessSignature } = credential;
|
|
27
|
+
if (connectionString) {
|
|
28
|
+
credential.accountName || (credential.accountName = (_a = /AccountName=([^;]+);/.exec(connectionString)) === null || _a === void 0 ? void 0 : _a[1]);
|
|
29
|
+
return BlobServiceClient.fromConnectionString(connectionString);
|
|
30
|
+
}
|
|
31
|
+
if (sharedAccessSignature) {
|
|
32
|
+
credential.accountName || (credential.accountName = (_b = /^https:\/\/([a-z\d]+)\./.exec(sharedAccessSignature)) === null || _b === void 0 ? void 0 : _b[1]);
|
|
33
|
+
return new BlobServiceClient(sharedAccessSignature);
|
|
34
|
+
}
|
|
35
|
+
let azureCredential;
|
|
36
|
+
if (accountName && accountKey) {
|
|
37
|
+
azureCredential = new StorageSharedKeyCredential(accountName, accountKey);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const { DefaultAzureCredential } = require(packageName = '@azure/identity');
|
|
41
|
+
azureCredential = new DefaultAzureCredential();
|
|
42
|
+
}
|
|
43
|
+
return new BlobServiceClient(`https://${accountName || process.env.AZURE_STORAGE_ACCOUNT}.blob.core.windows.net`, azureCredential);
|
|
39
44
|
}
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
catch (err) {
|
|
46
|
+
this.checkPackage(err, packageName, { passThrough: true });
|
|
47
|
+
throw err;
|
|
42
48
|
}
|
|
43
|
-
return new BlobServiceClient(`https://${accountName || process.env.AZURE_STORAGE_ACCOUNT}.blob.core.windows.net`, azureCredential);
|
|
44
49
|
}
|
|
45
50
|
exports.createStorageClient = createStorageClient;
|
|
46
51
|
function createDatabaseClient(credential) {
|
|
47
|
-
|
|
52
|
+
try {
|
|
53
|
+
const { CosmosClient } = require('@azure/cosmos');
|
|
54
|
+
return new CosmosClient(credential);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
this.checkPackage(err, '@azure/cosmos', { passThrough: true });
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
48
60
|
}
|
|
49
61
|
exports.createDatabaseClient = createDatabaseClient;
|
|
50
62
|
async function createBucket(credential, bucket, publicRead, service = 'azure') {
|
|
@@ -75,12 +87,11 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
|
|
|
75
87
|
options.abortSignal = this.signal;
|
|
76
88
|
return containerClient.create(options)
|
|
77
89
|
.then(response => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
this.formatMessage(64, service, ['Container created with errors', bucket], (0, types_1.errorMessage)("Error code", errorCode), { ...Cloud.LOG_CLOUD_WARN });
|
|
90
|
+
if (response.errorCode) {
|
|
91
|
+
this.formatMessage(64, service, ['Container created with errors', bucket], (0, types_1.errorMessage)("Error code", response.errorCode), { ...Cloud.LOG_CLOUD_WARN });
|
|
81
92
|
}
|
|
82
93
|
else {
|
|
83
|
-
this.formatMessage(64, service, ['Container created', bucket], requestId, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
94
|
+
this.formatMessage(64, service, ['Container created', bucket], response.requestId, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
84
95
|
}
|
|
85
96
|
return true;
|
|
86
97
|
})
|
|
@@ -98,15 +109,14 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
|
|
|
98
109
|
exports.createBucketV2 = createBucketV2;
|
|
99
110
|
function setBucketWebsite(credential, bucket, options, service = 'azure') {
|
|
100
111
|
const staticWebsite = { enabled: true };
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
staticWebsite.indexDocument = path.basename(indexPage);
|
|
112
|
+
if ((0, types_1.isString)(options.indexPage)) {
|
|
113
|
+
staticWebsite.indexDocument = path.basename(options.indexPage);
|
|
104
114
|
}
|
|
105
|
-
if ((0, types_1.isString)(indexPath)) {
|
|
106
|
-
staticWebsite.defaultIndexDocumentPath = Module.joinPath(bucket, indexPath);
|
|
115
|
+
if ((0, types_1.isString)(options.indexPath)) {
|
|
116
|
+
staticWebsite.defaultIndexDocumentPath = Module.joinPath(bucket, options.indexPath);
|
|
107
117
|
}
|
|
108
|
-
if ((0, types_1.isString)(errorPath)) {
|
|
109
|
-
staticWebsite.errorDocument404Path = Module.joinPath(bucket, errorPath);
|
|
118
|
+
if ((0, types_1.isString)(options.errorPath)) {
|
|
119
|
+
staticWebsite.errorDocument404Path = Module.joinPath(bucket, options.errorPath);
|
|
110
120
|
}
|
|
111
121
|
return createStorageClient.call(this, credential).setProperties({ staticWebsite })
|
|
112
122
|
.then(() => {
|
package/download/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
const client_1 = require("@pi-r/azure");
|
|
2
3
|
const types_1 = require("@e-mc/types");
|
|
3
4
|
const Module = require("@e-mc/module");
|
|
4
5
|
const Cloud = require("@e-mc/cloud");
|
|
5
|
-
const client_1 = require("@pi-r/azure");
|
|
6
6
|
function download(credential, service = 'azure') {
|
|
7
7
|
const blobServiceClient = client_1.createStorageClient.call(this, credential);
|
|
8
8
|
return (data, callback) => {
|
|
@@ -18,7 +18,7 @@ function download(credential, service = 'azure') {
|
|
|
18
18
|
.then(value => {
|
|
19
19
|
callback(null, value);
|
|
20
20
|
const deleteObject = target.deleteObject;
|
|
21
|
-
if (deleteObject) {
|
|
21
|
+
if (target.deleteObject) {
|
|
22
22
|
blobClient.delete((0, types_1.isPlainObject)(deleteObject) && (deleteObject.abortSignal = this.signal) ? deleteObject : undefined)
|
|
23
23
|
.then(() => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE }))
|
|
24
24
|
.catch((err) => {
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/azure",
|
|
3
|
-
"version": "0.3.
|
|
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.6.
|
|
24
|
-
"@e-mc/module": "^0.6.
|
|
25
|
-
"@e-mc/types": "^0.6.
|
|
26
|
-
"@azure/cosmos": "^3.17.3",
|
|
27
|
-
"@azure/identity": "^3.4.2",
|
|
28
|
-
"@azure/storage-blob": "^12.
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/azure",
|
|
3
|
+
"version": "0.3.6",
|
|
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.6.16",
|
|
24
|
+
"@e-mc/module": "^0.6.16",
|
|
25
|
+
"@e-mc/types": "^0.6.16",
|
|
26
|
+
"@azure/cosmos": "^3.17.3",
|
|
27
|
+
"@azure/identity": "^3.4.2",
|
|
28
|
+
"@azure/storage-blob": "^12.23.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
|
|
2
|
+
import type { AuthValue } from '@e-mc/types/lib/http';
|
|
3
|
+
|
|
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';
|
|
7
|
+
|
|
8
|
+
export type AzureStorage = CloudStorage<AzureStorageCredential, "azure" | "az">;
|
|
9
|
+
|
|
10
|
+
export interface AzureStorageCredential {
|
|
11
|
+
accountName?: string;
|
|
12
|
+
accountKey?: string;
|
|
13
|
+
accountSas?: string;
|
|
14
|
+
connectionString?: string;
|
|
15
|
+
sharedAccessSignature?: string;
|
|
16
|
+
defaultAzureOptions?: DefaultAzureCredentialOptions;
|
|
17
|
+
clientOptions?: StoragePipelineOptions;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface AzureDatabaseQuery<T = FeedOptions | RequestOptions, U = PatchRequestBody | PlainObject> extends CloudDatabase<string | SqlQuerySpec, T, U, unknown[], AzureDatabaseCredential> {
|
|
21
|
+
source: "cloud";
|
|
22
|
+
service: "azure" | "az";
|
|
23
|
+
partitionKey?: PartitionKey;
|
|
24
|
+
storedProcedureId?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface AzureDatabaseCredential extends AuthValue, CosmosClientOptions {
|
|
28
|
+
tenantId?: string;
|
|
29
|
+
clientId?: string;
|
|
30
|
+
}
|
package/upload/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
|
+
const client_1 = require("@pi-r/azure");
|
|
4
5
|
const util_1 = require("@e-mc/cloud/util");
|
|
5
6
|
const types_1 = require("@e-mc/types");
|
|
6
7
|
const Module = require("@e-mc/module");
|
|
7
8
|
const Cloud = require("@e-mc/cloud");
|
|
8
|
-
const client_1 = require("@pi-r/azure");
|
|
9
9
|
const BUCKET_SESSION = new Set();
|
|
10
10
|
const BUCKET_RESPONSE = {};
|
|
11
11
|
const getBucketKey = (credential, bucket, acl = '') => Module.asString(credential, true) + bucket + '_' + acl;
|