@pi-r/gcp 0.3.1 → 0.3.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2023 Studio Trigger
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/gcp
1
+ # @pi-r/gcp
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Aina
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -194,7 +194,7 @@ async function createBucketV2(credential, bucket, acl, options, service = 'gcp')
194
194
  }
195
195
  return instance.createBucket(bucket, options)
196
196
  .then(async ([target]) => {
197
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket created" /* VAL_CLOUD.CREATE_BUCKET */, bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
197
+ this.formatMessage(64, service, ["Bucket created", bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
198
198
  if (acl) {
199
199
  await setBucketPolicy.call(this, credential, bucket, { acl, bucket: target }, service);
200
200
  }
@@ -204,7 +204,7 @@ async function createBucketV2(credential, bucket, acl, options, service = 'gcp')
204
204
  if (isErrorConflict(err)) {
205
205
  return acl ? await setBucketPolicy.call(this, credential, bucket, { acl }, service) : true;
206
206
  }
207
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to create bucket" /* ERR_CLOUD.CREATE_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
207
+ this.formatFail(64, service, ["Unable to create bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
208
208
  return false;
209
209
  });
210
210
  }
@@ -215,7 +215,7 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
215
215
  }
216
216
  const client = createStorageClient.call(this, credential, bucket).bucket(bucket);
217
217
  if (!await hasBucket(client)) {
218
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Bucket does not exist" /* ERR_CLOUD.EXISTS_BUCKET */, bucket], (0, types_1.errorMessage)(service, "Bucket does not exist" /* ERR_CLOUD.EXISTS_BUCKET */), { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
218
+ this.formatFail(64, service, ["Bucket does not exist", bucket], (0, types_1.errorMessage)(service, "Bucket does not exist"), { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
219
219
  return false;
220
220
  }
221
221
  const errors = [];
@@ -256,10 +256,10 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
256
256
  errors.push(...await updatePredefinedAcl(client.acl, options.acl, options.metadata));
257
257
  }
258
258
  if (errors.length) {
259
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to update bucket policy" /* ERR_CLOUD.POLICY_BUCKET */, bucket], errors[0], { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
259
+ this.formatFail(64, service, ["Unable to update bucket policy", bucket], errors[0], { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
260
260
  return false;
261
261
  }
262
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket ACL configured" /* VAL_CLOUD.ACL_BUCKET */, bucket], (0, types_1.isString)(acl) ? acl : '', { ...Cloud.LOG_CLOUD_COMMAND });
262
+ this.formatMessage(64, service, ["Bucket ACL configured", bucket], (0, types_1.isString)(acl) ? acl : '', { ...Cloud.LOG_CLOUD_COMMAND });
263
263
  return true;
264
264
  }
265
265
  exports.setBucketPolicy = setBucketPolicy;
@@ -277,11 +277,11 @@ function setBucketWebsite(credential, bucket, options, service = 'gcp') {
277
277
  }
278
278
  return createStorageClient.call(this, credential, bucket).bucket(bucket).setMetadata({ website })
279
279
  .then(() => {
280
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */, bucket], website, { ...Cloud.LOG_CLOUD_COMMAND });
280
+ this.formatMessage(64, service, ["Bucket configured", bucket], website, { ...Cloud.LOG_CLOUD_COMMAND });
281
281
  return true;
282
282
  })
283
283
  .catch(err => {
284
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure bucket" /* ERR_CLOUD.CONFIGURE_BUCKET */, bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
284
+ this.formatFail(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
285
285
  return false;
286
286
  });
287
287
  }
@@ -321,14 +321,14 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
321
321
  const client = instance.bucket(bucket);
322
322
  if (await hasBucket(client)) {
323
323
  if (recursive) {
324
- return client.deleteFiles({ force: true }).then(() => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Bucket emptied" /* VAL_CLOUD.EMPTY_BUCKET */ + ' (recursive)', bucket, { ...Cloud.LOG_CLOUD_COMMAND }));
324
+ return client.deleteFiles({ force: true }).then(() => this.formatMessage(64, service, "Bucket emptied" + ' (recursive)', bucket, { ...Cloud.LOG_CLOUD_COMMAND }));
325
325
  }
326
326
  const tasks = [];
327
327
  try {
328
328
  const result = await client.getFiles();
329
329
  for (const { name } of result[0]) {
330
330
  if (name.indexOf('/') === -1) {
331
- tasks.push(client.file(name).delete({ ignoreNotFound: true }).catch(err => this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Delete failed" /* ERR_CLOUD.DELETE_FAIL */, name], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false })));
331
+ tasks.push(client.file(name).delete({ ignoreNotFound: true }).catch(err => this.formatFail(64, service, ["Delete failed", name], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false })));
332
332
  }
333
333
  }
334
334
  }
@@ -342,7 +342,7 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
342
342
  }
343
343
  const checkErrors = () => {
344
344
  if (errors.length) {
345
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to empty bucket" /* ERR_CLOUD.DELETE_BUCKET */ + (recursive ? ' (recursive)' : ''), errors.length + ' errors'], errors[0], { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
345
+ this.formatFail(64, service, ["Unable to empty bucket" + (recursive ? ' (recursive)' : ''), errors.length + ' errors'], errors[0], { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
346
346
  return true;
347
347
  }
348
348
  return false;
@@ -352,7 +352,7 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
352
352
  errors.push(...result.filter(item => item.status === 'rejected').map((item) => item.reason));
353
353
  if (!checkErrors()) {
354
354
  const files = result.length + ' files';
355
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket emptied" /* VAL_CLOUD.EMPTY_BUCKET */ + ` (${recursive ? 'recursive' : files})`, bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
355
+ this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
356
356
  }
357
357
  })
358
358
  .catch(err => {
@@ -383,7 +383,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
383
383
  return (clients[type] = createDatabaseClient.call(this, item, data));
384
384
  };
385
385
  const closeClient = () => {
386
- const fs = clients[3 /* DB.FIRESTORE */];
386
+ const fs = clients[3];
387
387
  fs?.terminate();
388
388
  };
389
389
  const getFamily = (data, row, family) => {
@@ -430,7 +430,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
430
430
  result[i] = rows;
431
431
  continue;
432
432
  }
433
- const db = createClient(item, 4 /* DB.BIGTABLE */).instance(name).table(table);
433
+ const db = createClient(item, 4).instance(name).table(table);
434
434
  if (id) {
435
435
  const row = db.row(id);
436
436
  if (Array.isArray(columns)) {
@@ -456,11 +456,11 @@ async function executeBatchQuery(credential, batch, sessionKey) {
456
456
  const columns = (0, types_1.isPlainObject)(query) && query.columns || item.columns;
457
457
  if (!(query || table && columns)) {
458
458
  closeClient();
459
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
459
+ throw (0, util_1.formatError)(item, "Missing database query");
460
460
  }
461
461
  if (!name || !database) {
462
462
  closeClient();
463
- throw (0, util_1.formatError)(item, !name ? "Missing instance name" /* ERR_DB.INSTANCE */ : "Missing database name" /* ERR_DB.NAME */);
463
+ throw (0, util_1.formatError)(item, !name ? "Missing instance name" : "Missing database name");
464
464
  }
465
465
  const { updateType, options = {} } = item;
466
466
  if (cached) {
@@ -470,7 +470,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
470
470
  continue;
471
471
  }
472
472
  }
473
- const db = createClient(item, 5 /* DB.SPANNER */).instance(name).database(database, options.databasePool, options.databaseQuery);
473
+ const db = createClient(item, 5).instance(name).database(database, options.databasePool, options.databaseQuery);
474
474
  if (table) {
475
475
  if ((0, types_1.isPlainObject)(update)) {
476
476
  await db.table(table)[updateType === 1 ? 'insert' : updateType === 2 ? 'replace' : 'update'](update, options.tableUpdate);
@@ -489,7 +489,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
489
489
  await new Promise((resolve, reject) => {
490
490
  db.runTransaction((err, transaction) => {
491
491
  if (err || !transaction) {
492
- reject(err || new Error("Unknown" /* ERR_MESSAGE.UNKNOWN */));
492
+ reject(err || new Error("Unknown"));
493
493
  }
494
494
  else {
495
495
  transaction.runUpdate(update)
@@ -510,7 +510,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
510
510
  else if (product === 'firebase' || product === 'bigquery' || !product && !table && typeof query === 'string') {
511
511
  if (!(0, types_1.isString)(query)) {
512
512
  closeClient();
513
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
513
+ throw (0, util_1.formatError)(item, "Missing database query");
514
514
  }
515
515
  const firebaseApp = product === 'firebase' || isFirebaseApp(credential);
516
516
  if (cached) {
@@ -554,7 +554,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
554
554
  }
555
555
  }
556
556
  }
557
- const db = createClient(item, 0 /* DB.FIREBASE */);
557
+ const db = createClient(item, 0);
558
558
  if ((0, types_1.isPlainObject)(update)) {
559
559
  await updateDB(ref(db, query), update);
560
560
  }
@@ -572,20 +572,20 @@ async function executeBatchQuery(credential, batch, sessionKey) {
572
572
  if (limit > 0) {
573
573
  options.maxResults = limit;
574
574
  }
575
- const [job] = await createClient(item, 1 /* DB.BIGQUERY */).createQueryJob(options);
575
+ const [job] = await createClient(item, 1).createQueryJob(options);
576
576
  [rows] = await job.getQueryResults();
577
577
  }
578
578
  }
579
579
  else if (product === 'datastore' || !product && !table && (keys || query)) {
580
580
  if (!keys && !Array.isArray(query)) {
581
581
  closeClient();
582
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
582
+ throw (0, util_1.formatError)(item, "Missing database query");
583
583
  }
584
584
  if (cached && (rows = getCache(queryString = Module.asString(keys || query, true) + Module.asString(item.options, true) + limit))) {
585
585
  result[i] = rows;
586
586
  continue;
587
587
  }
588
- const db = createClient(item, 2 /* DB.DATASTORE */);
588
+ const db = createClient(item, 2);
589
589
  if (keys) {
590
590
  const items = !Array.isArray(keys) ? db.key(keys) : keys.map((key) => db.key(key));
591
591
  rows = await db.get(items, item.options);
@@ -610,7 +610,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
610
610
  case 'order':
611
611
  case 'select':
612
612
  case 'start':
613
- task[method].apply(task, args.slice(1)); // eslint-disable-line prefer-spread
613
+ task[method].apply(task, args.slice(1));
614
614
  break;
615
615
  }
616
616
  }
@@ -623,7 +623,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
623
623
  else if (product === 'firestore' || !product && table) {
624
624
  if (!table) {
625
625
  closeClient();
626
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
626
+ throw (0, util_1.formatError)(item, "Missing database table");
627
627
  }
628
628
  if (cached) {
629
629
  queryString = table + '_';
@@ -636,7 +636,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
636
636
  continue;
637
637
  }
638
638
  }
639
- const db = createClient(item, 3 /* DB.FIRESTORE */).collection(table).doc(id);
639
+ const db = createClient(item, 3).collection(table).doc(id);
640
640
  if ((0, types_1.isPlainObject)(update)) {
641
641
  await db.update(update, { exists: true });
642
642
  }
@@ -650,7 +650,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
650
650
  result[i] = rows;
651
651
  continue;
652
652
  }
653
- let db = createClient(item, 3 /* DB.FIRESTORE */).collection(table);
653
+ let db = createClient(item, 3).collection(table);
654
654
  for (const args of query) {
655
655
  if (!(0, types_1.isArray)(args)) {
656
656
  continue;
@@ -668,7 +668,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
668
668
  case 'startAt':
669
669
  case 'where':
670
670
  case 'withConverter':
671
- db = db[method].apply(db, args.slice(1)); // eslint-disable-line prefer-spread
671
+ db = db[method].apply(db, args.slice(1));
672
672
  break;
673
673
  }
674
674
  }
@@ -686,12 +686,12 @@ async function executeBatchQuery(credential, batch, sessionKey) {
686
686
  }
687
687
  else {
688
688
  closeClient();
689
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
689
+ throw (0, util_1.formatError)(item, "Missing database query");
690
690
  }
691
691
  }
692
692
  else {
693
693
  closeClient();
694
- throw (0, util_1.formatError)(item, "Missing database product" /* ERR_DB.PRODUCT */);
694
+ throw (0, util_1.formatError)(item, "Missing database product");
695
695
  }
696
696
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
697
697
  }
@@ -703,12 +703,12 @@ function setPublicRead(acl, pathname, requested, service = 'gcp') {
703
703
  acl.add({ entity: 'allUsers', role: 'READER' })
704
704
  .then(() => {
705
705
  if (requested) {
706
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Grant public-read" /* VAL_CLOUD.PUBLIC_READ */, pathname, { ...Cloud.LOG_CLOUD_COMMAND });
706
+ this.formatMessage(64, service, "Grant public-read", pathname, { ...Cloud.LOG_CLOUD_COMMAND });
707
707
  }
708
708
  })
709
709
  .catch(err => {
710
710
  if (requested) {
711
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to grant public-read" /* ERR_CLOUD.PUBLIC_READ */, pathname], err, { ...Cloud.LOG_CLOUD_WARN });
711
+ this.formatMessage(64, service, ["Unable to grant public-read", pathname], err, { ...Cloud.LOG_CLOUD_WARN });
712
712
  }
713
713
  });
714
714
  }
@@ -783,10 +783,10 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
783
783
  }
784
784
  return updatePredefinedAcl(target, items, metadata).then(errors => {
785
785
  if (errors.length) {
786
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [`Unable to ${revoke ? 'revoke' : 'grant'} ` + value, bucket && pathname ? bucket.name + '/' + pathname : bucket ? bucket.name : pathname], errors[0], { ...Cloud.LOG_CLOUD_WARN });
786
+ this.formatMessage(64, service, [`Unable to ${revoke ? 'revoke' : 'grant'} ` + value, bucket && pathname ? bucket.name + '/' + pathname : bucket ? bucket.name : pathname], errors[0], { ...Cloud.LOG_CLOUD_WARN });
787
787
  }
788
788
  else if (requested && (bucket || pathname)) {
789
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket?.name], pathname, { ...Cloud.LOG_CLOUD_COMMAND });
789
+ this.formatMessage(64, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket?.name], pathname, { ...Cloud.LOG_CLOUD_COMMAND });
790
790
  }
791
791
  });
792
792
  }
package/download/index.js CHANGED
@@ -6,7 +6,7 @@ const https = require("https");
6
6
  const types_1 = require("@e-mc/types");
7
7
  const Module = require("@e-mc/module");
8
8
  const Cloud = require("@e-mc/cloud");
9
- const client_1 = require("../client");
9
+ const client_1 = require("@pi-r/gcp");
10
10
  function download(credential, service = 'gcp') {
11
11
  const storage = client_1.createStorageClient.call(this, credential);
12
12
  return (data, callback) => {
@@ -25,12 +25,12 @@ function download(credential, service = 'gcp') {
25
25
  return;
26
26
  }
27
27
  if (!(tempDir = this.getTempDir({ uuidDir: true }))) {
28
- downloadResponse(new Error("Unable to create temp directory" /* ERR_CLOUD.TEMP_DIR */));
28
+ downloadResponse(new Error("Unable to create temp directory"));
29
29
  return;
30
30
  }
31
31
  const location = Module.joinPath(Bucket, Key);
32
32
  const destination = path.join(tempDir, path.basename(Key));
33
- const deleteMessage = () => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Delete success" /* VAL_CLOUD.DELETE_FILE */, location, { ...Cloud.LOG_CLOUD_DELETE });
33
+ const deleteMessage = () => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE });
34
34
  if (firebase) {
35
35
  const { ref, getDownloadURL, deleteObject } = require('@firebase/storage');
36
36
  const objectRef = ref(storage, Key);
@@ -45,7 +45,7 @@ function download(credential, service = 'gcp') {
45
45
  if (target.deleteObject) {
46
46
  deleteObject(objectRef)
47
47
  .then(() => deleteMessage())
48
- .catch(err => this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Delete failed" /* ERR_CLOUD.DELETE_FAIL */, location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
48
+ .catch(err => this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
49
49
  }
50
50
  })
51
51
  .on('error', err => downloadResponse(err)));
@@ -69,7 +69,7 @@ function download(credential, service = 'gcp') {
69
69
  deleteMessage();
70
70
  }
71
71
  else {
72
- this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Delete failed" /* ERR_CLOUD.DELETE_FAIL */, location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
72
+ this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
73
73
  }
74
74
  });
75
75
  }
@@ -78,5 +78,9 @@ function download(credential, service = 'gcp') {
78
78
  }
79
79
  };
80
80
  }
81
+ exports.default = download;
81
82
 
82
- module.exports = download;
83
+ if (exports.default) {
84
+ module.exports = exports.default;
85
+ module.exports.default = exports.default;
86
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/gcp",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Google (GCP) 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/gcp"
13
13
  },
14
14
  "keywords": [
@@ -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.6.0",
24
- "@e-mc/module": "^0.6.0",
25
- "@e-mc/types": "^0.6.0",
23
+ "@e-mc/cloud": "^0.6.1",
24
+ "@e-mc/module": "^0.6.1",
25
+ "@e-mc/types": "^0.6.1",
26
26
  "@google-cloud/firestore": "^6.8.0",
27
27
  "@google-cloud/storage": "^7.7.0"
28
28
  }
package/upload/index.js CHANGED
@@ -6,7 +6,7 @@ const util_1 = require("@e-mc/cloud/util");
6
6
  const types_1 = require("@e-mc/types");
7
7
  const Module = require("@e-mc/module");
8
8
  const Cloud = require("@e-mc/cloud");
9
- const client_1 = require("../client");
9
+ const client_1 = require("@pi-r/gcp");
10
10
  const BUCKET_SESSION = new Set();
11
11
  const BUCKET_RESPONSE = {};
12
12
  const getBucketKey = (credential, bucket, acl = '') => Module.asString(credential, true) + bucket + '_' + acl;
@@ -72,13 +72,13 @@ function upload(credential, service = 'gcp') {
72
72
  }
73
73
  } while (exists && ++i);
74
74
  if (i > 0) {
75
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["File renamed" /* VAL_CLOUD.RENAME_FILE */, current], filename, { ...Cloud.LOG_CLOUD_WARN });
75
+ this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
76
76
  }
77
77
  }
78
78
  const Key = [filename];
79
79
  const Body = [data.buffer];
80
80
  const ContentType = [contentType];
81
- const getURL = (value) => endpoint ? Module.joinPath(endpoint, value) : Module.joinPath("https://storage.googleapis.com" /* STRINGS.BASE_URL */, bucket, value);
81
+ const getURL = (value) => endpoint ? Module.joinPath(endpoint, value) : Module.joinPath("https://storage.googleapis.com", bucket, value);
82
82
  const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + bucket);
83
83
  if (fileGroup) {
84
84
  for (const [content, ext, localFile] of fileGroup) {
@@ -123,7 +123,7 @@ function upload(credential, service = 'gcp') {
123
123
  uploadBytes(ref(bucketClient, destination), Body[i], params)
124
124
  .then(() => {
125
125
  const url = getURL(destination);
126
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
126
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
127
127
  if (first) {
128
128
  uploadResponse(null, url);
129
129
  }
@@ -143,7 +143,7 @@ function upload(credential, service = 'gcp') {
143
143
  const output = Body[i];
144
144
  if (Buffer.isBuffer(output) || path.basename(output) !== Key[i]) {
145
145
  if (!(tempDir = this.getTempDir({ uuidDir: true }))) {
146
- throw new Error("Unable to create temp directory" /* ERR_CLOUD.TEMP_DIR */);
146
+ throw new Error("Unable to create temp directory");
147
147
  }
148
148
  outputUri = path.join(tempDir, Key[i]);
149
149
  if (typeof output === 'string') {
@@ -204,7 +204,7 @@ function upload(credential, service = 'gcp') {
204
204
  bucketClient.upload(outputUri, params, (err, file) => {
205
205
  if (file) {
206
206
  const url = getURL(file.name);
207
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
207
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
208
208
  if (first) {
209
209
  uploadResponse(null, url);
210
210
  }
@@ -226,5 +226,9 @@ function upload(credential, service = 'gcp') {
226
226
  }
227
227
  };
228
228
  }
229
+ exports.default = upload;
229
230
 
230
- module.exports = upload;
231
+ if (exports.default) {
232
+ module.exports = exports.default;
233
+ module.exports.default = exports.default;
234
+ }