@pi-r/azure 0.2.3 → 0.2.8

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 2023 Mile Square Park
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,5 +1,7 @@
1
- ### @pi-r/azure
1
+ # @pi-r/azure
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -11,11 +11,11 @@ function validateStorage(credential) {
11
11
  if (credential.accountName && credential.accountKey || credential.connectionString || credential.sharedAccessSignature || env.AZURE_TENANT_ID && env.AZURE_CLIENT_ID && env.AZURE_CLIENT_SECRET && (credential.accountName || env.AZURE_STORAGE_ACCOUNT)) {
12
12
  return true;
13
13
  }
14
- return Module.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));
14
+ return Module.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));
15
15
  }
16
16
  exports.validateStorage = validateStorage;
17
17
  function validateDatabase(credential, data) {
18
- return !!(data.name && data.table && (credential.endpoint && credential.key || Module.enabled("process.env.apply" /* KEY_NAME.PROCESS_ENV_APPLY */) && (credential.endpoint = process.env.AZURE_COSMOS_ENDPOINT) && (credential.key = process.env.AZURE_COSMOS_KEY)));
18
+ return !!(data.name && data.table && (credential.endpoint && credential.key || Module.enabled("process.env.apply") && (credential.endpoint = process.env.AZURE_COSMOS_ENDPOINT) && (credential.key = process.env.AZURE_COSMOS_KEY)));
19
19
  }
20
20
  exports.validateDatabase = validateDatabase;
21
21
  function createStorageClient(credential) {
@@ -72,7 +72,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
72
72
  break;
73
73
  }
74
74
  const containerClient = createStorageClient.call(this, credential).getContainerClient(bucket);
75
- const setAccessPolicy = () => 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 }));
75
+ const setAccessPolicy = () => containerClient.setAccessPolicy(access).catch(err => this.formatMessage(64, service, ["Unable to configure container", bucket], err, { ...Cloud.LOG_CLOUD_WARN }));
76
76
  if (await containerClient.exists().catch(() => false)) {
77
77
  if (access) {
78
78
  await setAccessPolicy();
@@ -87,10 +87,10 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
87
87
  return containerClient.create(options)
88
88
  .then(response => {
89
89
  if (response.errorCode) {
90
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Container created with errors', bucket], (0, types_1.errorMessage)("Error code" /* ERR_MESSAGE.ERROR_CODE */, response.errorCode), { ...Cloud.LOG_CLOUD_WARN });
90
+ this.formatMessage(64, service, ['Container created with errors', bucket], (0, types_1.errorMessage)("Error code", response.errorCode), { ...Cloud.LOG_CLOUD_WARN });
91
91
  }
92
92
  else {
93
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ['Container created', bucket], response.requestId, { ...Cloud.LOG_CLOUD_COMMAND });
93
+ this.formatMessage(64, service, ['Container created', bucket], response.requestId, { ...Cloud.LOG_CLOUD_COMMAND });
94
94
  }
95
95
  return true;
96
96
  })
@@ -101,7 +101,7 @@ async function createBucketV2(credential, bucket, access, options, service = 'az
101
101
  }
102
102
  return true;
103
103
  }
104
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to create container" /* ERR_AZURE.CREATE_CONTAINER */, bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
104
+ this.formatFail(64, service, ["Unable to create container", bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
105
105
  return false;
106
106
  });
107
107
  }
@@ -119,11 +119,11 @@ function setBucketWebsite(credential, bucket, options, service = 'azure') {
119
119
  }
120
120
  return createStorageClient.call(this, credential).setProperties({ staticWebsite })
121
121
  .then(() => {
122
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */, bucket], options, { ...Cloud.LOG_CLOUD_COMMAND });
122
+ this.formatMessage(64, service, ["Bucket configured", bucket], options, { ...Cloud.LOG_CLOUD_COMMAND });
123
123
  return true;
124
124
  })
125
125
  .catch(err => {
126
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure bucket" /* ERR_CLOUD.CONFIGURE_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
126
+ this.formatFail(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
127
127
  return false;
128
128
  });
129
129
  }
@@ -145,13 +145,13 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
145
145
  tasks.push(containerClient.deleteBlob(blob.name, { versionId: blob.versionId }).catch(() => { --fileCount; }));
146
146
  }
147
147
  fileCount = tasks.length;
148
- return this.allSettled(tasks, ["Unable to delete blob" /* ERR_AZURE.DELETE_BLOB */, bucket], 64 /* LOG_TYPE.CLOUD */).then(() => {
148
+ return this.allSettled(tasks, ["Unable to delete blob", bucket], 64).then(() => {
149
149
  const files = fileCount + ' files';
150
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [`Container emptied (${recursive ? 'recursive' : files})`, bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
150
+ this.formatMessage(64, service, [`Container emptied (${recursive ? 'recursive' : files})`, bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
151
151
  });
152
152
  }
153
153
  catch (err) {
154
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to list bucket" /* ERR_CLOUD.LIST_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
154
+ this.formatFail(64, service, ["Unable to list bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
155
155
  }
156
156
  }
157
157
  }
@@ -176,7 +176,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
176
176
  const { service, name, table, id, query, storedProcedureId, partitionKey, params, limit = 0, update, ignoreCache } = item;
177
177
  if (!name || !table) {
178
178
  closeClient();
179
- throw (0, util_1.formatError)(item, name ? "Missing database table" /* ERR_DB.TABLE */ : "Missing database name" /* ERR_DB.NAME */);
179
+ throw (0, util_1.formatError)(item, name ? "Missing database table" : "Missing database name");
180
180
  }
181
181
  const renewCache = ignoreCache === 0;
182
182
  const getCache = (value) => {
@@ -194,7 +194,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
194
194
  continue;
195
195
  }
196
196
  const { statusCode, resource } = await createClient(name, table).scripts.storedProcedure(storedProcedureId).execute(partitionKey, params, options);
197
- if (statusCode === 200 /* HTTP_STATUS.OK */) {
197
+ if (statusCode === 200) {
198
198
  rows = Array.isArray(resource) ? resource : [resource];
199
199
  }
200
200
  }
@@ -209,7 +209,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
209
209
  }
210
210
  const db = createClient(name, table).item(id, partitionKey);
211
211
  const { statusCode, resource } = update ? await db.patch(update, options) : await db.read(options);
212
- if (statusCode === 200 /* HTTP_STATUS.OK */) {
212
+ if (statusCode === 200) {
213
213
  rows = [resource];
214
214
  }
215
215
  }
@@ -226,7 +226,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
226
226
  }
227
227
  else {
228
228
  closeClient();
229
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
229
+ throw (0, util_1.formatError)(item, "Missing database query");
230
230
  }
231
231
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
232
232
  }
package/download/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const client_1 = require("../client");
3
+ const client_1 = require("@pi-r/azure");
4
4
  const types_1 = require("@e-mc/types");
5
5
  const Module = require("@e-mc/module");
6
6
  const Cloud = require("@e-mc/cloud");
@@ -21,10 +21,10 @@ function download(credential, service = 'azure') {
21
21
  const deleteObject = target.deleteObject;
22
22
  if (target.deleteObject) {
23
23
  blobClient.delete((0, types_1.isPlainObject)(deleteObject) && (deleteObject.abortSignal = this.signal) ? deleteObject : undefined)
24
- .then(() => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Delete success" /* VAL_CLOUD.DELETE_FILE */, location, { ...Cloud.LOG_CLOUD_DELETE }))
24
+ .then(() => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE }))
25
25
  .catch((err) => {
26
26
  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 });
27
+ this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
28
28
  }
29
29
  });
30
30
  }
@@ -32,5 +32,9 @@ function download(credential, service = 'azure') {
32
32
  .catch(err => callback(err));
33
33
  };
34
34
  }
35
+ exports.default = download;
35
36
 
36
- module.exports = download;
37
+ if (exports.default) {
38
+ module.exports = exports.default;
39
+ module.exports.default = exports.default;
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/azure",
3
- "version": "0.2.3",
3
+ "version": "0.2.8",
4
4
  "description": "Azure cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/anpham6/pi-r.git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
12
  "directory": "src/cloud/azure"
13
13
  },
14
14
  "keywords": [
@@ -20,11 +20,11 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.5.3",
24
- "@e-mc/module": "^0.5.3",
25
- "@e-mc/types": "^0.5.3",
23
+ "@e-mc/cloud": "^0.5.4",
24
+ "@e-mc/module": "^0.5.4",
25
+ "@e-mc/types": "^0.5.4",
26
26
  "@azure/cosmos": "^3.17.3",
27
- "@azure/identity": "^3.2.4",
28
- "@azure/storage-blob": "^12.15.0"
27
+ "@azure/identity": "^3.4.2",
28
+ "@azure/storage-blob": "^12.17.0"
29
29
  }
30
30
  }
package/upload/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require("path");
4
4
  const fs = require("fs");
5
- const client_1 = require("../client");
5
+ const client_1 = require("@pi-r/azure");
6
6
  const util_1 = require("@e-mc/cloud/util");
7
7
  const types_1 = require("@e-mc/types");
8
8
  const Module = require("@e-mc/module");
@@ -58,7 +58,7 @@ function upload(credential, service = 'azure') {
58
58
  }
59
59
  } while (exists && ++i);
60
60
  if (i > 0) {
61
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["File renamed" /* VAL_CLOUD.RENAME_FILE */, current], filename, { ...Cloud.LOG_CLOUD_WARN });
61
+ this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
62
62
  }
63
63
  }
64
64
  catch (err) {
@@ -99,7 +99,7 @@ function upload(credential, service = 'azure') {
99
99
  .then(result => {
100
100
  let requestUrl = result._response.request.url;
101
101
  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);
102
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
102
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
103
103
  if (first) {
104
104
  cleanup();
105
105
  callback(null, url);
@@ -116,5 +116,9 @@ function upload(credential, service = 'azure') {
116
116
  }
117
117
  };
118
118
  }
119
+ exports.default = upload;
119
120
 
120
- module.exports = upload;
121
+ if (exports.default) {
122
+ module.exports = exports.default;
123
+ module.exports.default = exports.default;
124
+ }