@pi-r/azure 0.6.3 → 0.6.5

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
2
2
 
3
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
4
 
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
- ### @pi-r/azure
1
+ # @pi-r/azure
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/cloud/azure.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/cloud/azure.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
package/client/index.js CHANGED
@@ -13,11 +13,11 @@ function validateStorage(credential) {
13
13
  if (credential.accountName && credential.accountKey || credential.connectionString || credential.sharedAccessSignature || env.AZURE_TENANT_ID && env.AZURE_CLIENT_ID && env.AZURE_CLIENT_SECRET) {
14
14
  return true;
15
15
  }
16
- return Cloud.enabled("process.env.apply" /* KEY_NAME.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));
16
+ 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));
17
17
  }
18
18
  exports.validateStorage = validateStorage;
19
19
  function validateDatabase(credential, data) {
20
- 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" /* KEY_NAME.PROCESS_ENV_APPLY */) && (credential.endpoint = process.env.AZURE_COSMOS_ENDPOINT) && (credential.key = process.env.AZURE_COSMOS_KEY)));
20
+ 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)));
21
21
  }
22
22
  exports.validateDatabase = validateDatabase;
23
23
  function createStorageClient(credential) {
@@ -69,7 +69,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
69
69
  break;
70
70
  }
71
71
  const containerClient = createStorageClient.call(this, credential).getContainerClient(bucket);
72
- const setAccessPolicy = async () => containerClient.setAccessPolicy(access).catch(err => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure container" /* ERR_AZURE.CONFIGURE_CONTAINER */, bucket], err, { ...Cloud.LOG_CLOUD_WARN }));
72
+ const setAccessPolicy = async () => containerClient.setAccessPolicy(access).catch(err => this.formatMessage(64, service, ["Unable to configure container", bucket], err, { ...Cloud.LOG_CLOUD_WARN }));
73
73
  if (await containerClient.exists().catch(() => false)) {
74
74
  if (access) {
75
75
  await setAccessPolicy();
@@ -85,10 +85,10 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
85
85
  .then(response => {
86
86
  const { requestId, errorCode } = response;
87
87
  if (errorCode) {
88
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Container created with errors', bucket], (0, types_1.errorMessage)("Error code" /* ERR_MESSAGE.ERROR_CODE */, errorCode), { ...Cloud.LOG_CLOUD_WARN });
88
+ this.formatMessage(64, service, ['Container created with errors', bucket], (0, types_1.errorMessage)("Error code", errorCode), { ...Cloud.LOG_CLOUD_WARN });
89
89
  }
90
90
  else {
91
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Container created', bucket], requestId, { ...Cloud.LOG_CLOUD_COMMAND });
91
+ this.formatMessage(64, service, ['Container created', bucket], requestId, { ...Cloud.LOG_CLOUD_COMMAND });
92
92
  }
93
93
  return true;
94
94
  })
@@ -99,7 +99,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
99
99
  }
100
100
  return true;
101
101
  }
102
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to create container" /* ERR_AZURE.CREATE_CONTAINER */, bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
102
+ this.formatFail(64, service, ["Unable to create container", bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
103
103
  return false;
104
104
  });
105
105
  }
@@ -120,15 +120,15 @@ async function setBucketWebsite(credential, bucket, options, service = 'azure')
120
120
  .then(response => {
121
121
  const { requestId, errorCode } = response;
122
122
  if (errorCode) {
123
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ + ' with errors', bucket], (0, types_1.errorMessage)("Error code" /* ERR_MESSAGE.ERROR_CODE */, errorCode), { ...Cloud.LOG_CLOUD_WARN });
123
+ this.formatMessage(64, service, ["Bucket configured" + ' with errors', bucket], (0, types_1.errorMessage)("Error code", errorCode), { ...Cloud.LOG_CLOUD_WARN });
124
124
  }
125
125
  else {
126
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */, bucket], requestId, { ...Cloud.LOG_CLOUD_COMMAND });
126
+ this.formatMessage(64, service, ["Bucket configured", bucket], requestId, { ...Cloud.LOG_CLOUD_COMMAND });
127
127
  }
128
128
  return true;
129
129
  })
130
130
  .catch(err => {
131
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure bucket" /* ERR_CLOUD.CONFIGURE_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
131
+ this.formatFail(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
132
132
  return false;
133
133
  });
134
134
  }
@@ -151,12 +151,12 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
151
151
  }
152
152
  }
153
153
  fileCount = tasks.length;
154
- return this.allSettled(tasks, ["Unable to delete blob" /* ERR_AZURE.DELETE_BLOB */, bucket], 64 /* LOG_TYPE.CLOUD */).then(() => {
155
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Container emptied' + (recursive ? ' (recursive)' : ''), bucket], fileCount + ' files', { ...Cloud.LOG_CLOUD_COMMAND });
154
+ return this.allSettled(tasks, ["Unable to delete blob", bucket], 64).then(() => {
155
+ this.formatMessage(64, service, ['Container emptied' + (recursive ? ' (recursive)' : ''), bucket], fileCount + ' files', { ...Cloud.LOG_CLOUD_COMMAND });
156
156
  });
157
157
  }
158
158
  catch (err) {
159
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to list bucket" /* ERR_CLOUD.LIST_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
159
+ this.formatFail(64, service, ["Unable to list bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
160
160
  }
161
161
  }
162
162
  }
@@ -181,7 +181,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
181
181
  const { service, name, table, id, query, storedProcedureId, partitionKey = null, params, limit = 0, update, ignoreCache } = item;
182
182
  if (!name || !table) {
183
183
  closeClient();
184
- throw (0, util_1.formatError)(item, name ? "Missing database table" /* ERR_DB.TABLE */ : "Missing database name" /* ERR_DB.NAME */);
184
+ throw (0, util_1.formatError)(item, name ? "Missing database table" : "Missing database name");
185
185
  }
186
186
  const getCache = (value) => {
187
187
  if (ignoreCache !== 1) {
@@ -198,7 +198,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
198
198
  continue;
199
199
  }
200
200
  const { statusCode, resource } = await createClient(name, table).scripts.storedProcedure(storedProcedureId).execute(partitionKey, params, options);
201
- if (statusCode === 200 /* HTTP_STATUS.OK */) {
201
+ if (statusCode === 200) {
202
202
  rows = Array.isArray(resource) ? resource : [resource];
203
203
  }
204
204
  }
@@ -213,7 +213,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
213
213
  }
214
214
  const db = createClient(name, table).item(id, partitionKey);
215
215
  const { statusCode, resource } = update ? await db.patch(update, options) : await db.read(options);
216
- if (statusCode === 200 /* HTTP_STATUS.OK */) {
216
+ if (statusCode === 200) {
217
217
  rows = [resource];
218
218
  }
219
219
  }
@@ -235,7 +235,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
235
235
  }
236
236
  else {
237
237
  closeClient();
238
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
238
+ throw (0, util_1.formatError)(item, "Missing database query");
239
239
  }
240
240
  }
241
241
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
package/download/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  const types_1 = require("@e-mc/types");
4
3
  const Module = require("@e-mc/module");
5
4
  const Cloud = require("@e-mc/cloud");
6
- const client_1 = require("../client");
5
+ const client_1 = require("@pi-r/azure");
7
6
  function download(credential, service = 'azure') {
8
7
  const blobServiceClient = client_1.createStorageClient.call(this, credential);
9
8
  return (data, callback) => {
@@ -21,10 +20,10 @@ function download(credential, service = 'azure') {
21
20
  const deleteObject = target.deleteObject;
22
21
  if (deleteObject) {
23
22
  blobClient.delete((0, types_1.isPlainObject)(deleteObject) ? (deleteObject.abortSignal = this.signal, deleteObject) : { abortSignal: this.signal })
24
- .then(() => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Delete success" /* VAL_CLOUD.DELETE_FILE */, location, { ...Cloud.LOG_CLOUD_DELETE }))
23
+ .then(() => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE }))
25
24
  .catch((err) => {
26
25
  if (!(err instanceof Error && err.code === 'BlobNotFound')) {
27
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Delete failed" /* ERR_CLOUD.DELETE_FAIL */, location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
26
+ this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
28
27
  }
29
28
  });
30
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/azure",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "Azure cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -20,9 +20,9 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.8.3",
24
- "@e-mc/module": "^0.8.3",
25
- "@e-mc/types": "^0.8.3",
23
+ "@e-mc/cloud": "^0.8.6",
24
+ "@e-mc/module": "^0.8.6",
25
+ "@e-mc/types": "^0.8.6",
26
26
  "@azure/cosmos": "^4.0.0",
27
27
  "@azure/identity": "^4.0.1",
28
28
  "@azure/storage-blob": "^12.17.0"
package/upload/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  const path = require("path");
4
3
  const util_1 = require("@e-mc/cloud/util");
5
4
  const types_1 = require("@e-mc/types");
6
5
  const Module = require("@e-mc/module");
7
6
  const Cloud = require("@e-mc/cloud");
8
- const client_1 = require("../client");
7
+ const client_1 = require("@pi-r/azure");
9
8
  const BUCKET_SESSION = new Set();
10
9
  const BUCKET_RESPONSE = {};
11
10
  const getBucketKey = (credential, bucket, acl = '') => Module.asString(credential, true) + bucket + '_' + acl;
@@ -46,7 +45,7 @@ function upload(credential, service = 'azure') {
46
45
  containerClient.setAccessPolicy('container', retentionPolicy)
47
46
  .then(() => {
48
47
  const { expiresOn, startsOn, permissions } = retentionPolicy[0].accessPolicy;
49
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ + ' (retention policy)', bucket], expiresOn ? expiresOn.toLocaleString() + ' (expires)' : startsOn ? startsOn.toLocaleString() + ' (starts)' : permissions, { ...Cloud.LOG_CLOUD_COMMAND });
48
+ this.formatMessage(64, service, ["Bucket configured" + ' (retention policy)', bucket], expiresOn ? expiresOn.toLocaleString() + ' (expires)' : startsOn ? startsOn.toLocaleString() + ' (starts)' : permissions, { ...Cloud.LOG_CLOUD_COMMAND });
50
49
  })
51
50
  .catch(err => addLog(err));
52
51
  }
@@ -71,7 +70,7 @@ function upload(credential, service = 'azure') {
71
70
  }
72
71
  } while (exists && ++i);
73
72
  if (i > 0) {
74
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["File renamed" /* VAL_CLOUD.RENAME_FILE */, current], filename, { ...Cloud.LOG_CLOUD_WARN });
73
+ this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
75
74
  }
76
75
  }
77
76
  catch (err) {
@@ -111,7 +110,7 @@ function upload(credential, service = 'azure') {
111
110
  .then(result => {
112
111
  let requestUrl = result._response.request.url;
113
112
  const url = endpoint ? Module.joinPath(endpoint, blobName) : Module.isFile(requestUrl = decodeURIComponent(requestUrl), 'http/s') ? requestUrl : Module.joinPath(`https://${credential.accountName}.blob.core.windows.net`, bucket, blobName);
114
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
113
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
115
114
  if (first) {
116
115
  cleanup();
117
116
  callback(null, url);