@pi-r/gcp 0.5.0 → 0.5.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 Wit Studio
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 Vivy
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,21 +456,21 @@ 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) {
467
- queryString = name + '_' + database + '_' + (table ? table + Module.asString(columns, true) : '') + Module.asString(query, true) + limit;
467
+ queryString = name + '_' + database + '_' + (table ? table + (columns ? Module.asString(columns, true) : '') : '') + Module.asString(query, true) + limit;
468
468
  if (!update && (rows = getCache(queryString))) {
469
469
  result[i] = rows;
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);
@@ -608,7 +608,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
608
608
  case 'order':
609
609
  case 'select':
610
610
  case 'start':
611
- task[method].apply(task, args.slice(1)); // eslint-disable-line prefer-spread
611
+ task[method].apply(task, args.slice(1));
612
612
  break;
613
613
  }
614
614
  }
@@ -622,7 +622,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
622
622
  else if (product === 'firestore' || !product && table) {
623
623
  if (!table) {
624
624
  closeClient();
625
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
625
+ throw (0, util_1.formatError)(item, "Missing database table");
626
626
  }
627
627
  if (cached) {
628
628
  queryString = table + '_';
@@ -635,7 +635,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
635
635
  continue;
636
636
  }
637
637
  }
638
- const db = createClient(item, 3 /* DB.FIRESTORE */).collection(table).doc(id);
638
+ const db = createClient(item, 3).collection(table).doc(id);
639
639
  if ((0, types_1.isPlainObject)(update)) {
640
640
  await db.update(update, { exists: true });
641
641
  }
@@ -649,7 +649,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
649
649
  result[i] = rows;
650
650
  continue;
651
651
  }
652
- let db = createClient(item, 3 /* DB.FIRESTORE */).collection(table);
652
+ let db = createClient(item, 3).collection(table);
653
653
  for (const args of query) {
654
654
  if ((0, types_1.isArray)(args)) {
655
655
  const method = args[0];
@@ -665,7 +665,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
665
665
  case 'startAt':
666
666
  case 'where':
667
667
  case 'withConverter':
668
- db = db[method].apply(db, args.slice(1)); // eslint-disable-line prefer-spread
668
+ db = db[method].apply(db, args.slice(1));
669
669
  break;
670
670
  }
671
671
  }
@@ -684,12 +684,12 @@ async function executeBatchQuery(credential, batch, sessionKey) {
684
684
  }
685
685
  else {
686
686
  closeClient();
687
- throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
687
+ throw (0, util_1.formatError)(item, "Missing database query");
688
688
  }
689
689
  }
690
690
  else {
691
691
  closeClient();
692
- throw (0, util_1.formatError)(item, "Missing database product" /* ERR_DB.PRODUCT */);
692
+ throw (0, util_1.formatError)(item, "Missing database product");
693
693
  }
694
694
  result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
695
695
  }
@@ -701,12 +701,12 @@ function setPublicRead(acl, pathname, requested, service = 'gcp') {
701
701
  acl.add({ entity: 'allUsers', role: 'READER' })
702
702
  .then(() => {
703
703
  if (requested) {
704
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Grant public-read" /* VAL_CLOUD.PUBLIC_READ */, pathname, { ...Cloud.LOG_CLOUD_COMMAND });
704
+ this.formatMessage(64, service, "Grant public-read", pathname, { ...Cloud.LOG_CLOUD_COMMAND });
705
705
  }
706
706
  })
707
707
  .catch(err => {
708
708
  if (requested) {
709
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to grant public-read" /* ERR_CLOUD.PUBLIC_READ */, pathname], err, { ...Cloud.LOG_CLOUD_WARN });
709
+ this.formatMessage(64, service, ["Unable to grant public-read", pathname], err, { ...Cloud.LOG_CLOUD_WARN });
710
710
  }
711
711
  });
712
712
  }
@@ -781,10 +781,10 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
781
781
  }
782
782
  return updatePredefinedAcl(target, items, metadata).then(errors => {
783
783
  if (errors.length) {
784
- 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 });
784
+ 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 });
785
785
  }
786
786
  else if (requested && (bucket || pathname)) {
787
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket?.name], pathname, { ...Cloud.LOG_CLOUD_COMMAND });
787
+ this.formatMessage(64, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket?.name], pathname, { ...Cloud.LOG_CLOUD_COMMAND });
788
788
  }
789
789
  });
790
790
  }
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.5.0",
3
+ "version": "0.5.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,10 +20,10 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.7.0",
24
- "@e-mc/module": "^0.7.0",
25
- "@e-mc/types": "^0.7.0",
26
- "@google-cloud/firestore": "^7.1.0",
23
+ "@e-mc/cloud": "^0.7.2",
24
+ "@e-mc/module": "^0.7.2",
25
+ "@e-mc/types": "^0.7.2",
26
+ "@google-cloud/firestore": "^7.3.1",
27
27
  "@google-cloud/storage": "^7.7.0"
28
28
  }
29
29
  }
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;
@@ -57,7 +57,7 @@ function upload(credential, service = 'gcp') {
57
57
  if (typeof retentionPolicy === 'number') {
58
58
  bucketClient.setRetentionPeriod(retentionPolicy)
59
59
  .then(([response]) => {
60
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ + ' (retention policy)', bucket], response.retentionPolicy?.effectiveTime, { ...Cloud.LOG_CLOUD_COMMAND });
60
+ this.formatMessage(64, service, ["Bucket configured" + ' (retention policy)', bucket], response.retentionPolicy?.effectiveTime, { ...Cloud.LOG_CLOUD_COMMAND });
61
61
  })
62
62
  .catch(err => addLog(err));
63
63
  }
@@ -82,13 +82,13 @@ function upload(credential, service = 'gcp') {
82
82
  }
83
83
  } while (exists && ++i);
84
84
  if (i > 0) {
85
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["File renamed" /* VAL_CLOUD.RENAME_FILE */, current], filename, { ...Cloud.LOG_CLOUD_WARN });
85
+ this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
86
86
  }
87
87
  }
88
88
  const Key = [filename];
89
89
  const Body = [data.buffer];
90
90
  const ContentType = [contentType];
91
- const getURL = (value) => endpoint ? Module.joinPath(endpoint, value) : Module.joinPath("https://storage.googleapis.com" /* STRINGS.BASE_URL */, bucket, value);
91
+ const getURL = (value) => endpoint ? Module.joinPath(endpoint, value) : Module.joinPath("https://storage.googleapis.com", bucket, value);
92
92
  if (fileGroup) {
93
93
  for (const [content, ext, localFile] of fileGroup) {
94
94
  Key.push(ext === '.map' && localFile ? path.basename(localFile) : filename + ext);
@@ -132,7 +132,7 @@ function upload(credential, service = 'gcp') {
132
132
  uploadBytes(ref(bucketClient, destination), Body[i], params)
133
133
  .then(() => {
134
134
  const url = getURL(destination);
135
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
135
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
136
136
  if (first) {
137
137
  uploadResponse(null, url);
138
138
  }
@@ -152,7 +152,7 @@ function upload(credential, service = 'gcp') {
152
152
  const output = Body[i];
153
153
  if (Buffer.isBuffer(output) || path.basename(output) !== Key[i]) {
154
154
  if (!(tempDir = this.getTempDir({ uuidDir: true }))) {
155
- throw new Error("Unable to create temp directory" /* ERR_CLOUD.TEMP_DIR */);
155
+ throw new Error("Unable to create temp directory");
156
156
  }
157
157
  outputUri = path.join(tempDir, Key[i]);
158
158
  if (typeof output === 'string') {
@@ -213,7 +213,7 @@ function upload(credential, service = 'gcp') {
213
213
  bucketClient.upload(outputUri, params, (err, file) => {
214
214
  if (file) {
215
215
  const url = getURL(file.name);
216
- this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Upload success" /* VAL_CLOUD.UPLOAD_FILE */, url, { ...Cloud.LOG_CLOUD_UPLOAD });
216
+ this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
217
217
  if (first) {
218
218
  uploadResponse(null, url);
219
219
  }
@@ -235,5 +235,9 @@ function upload(credential, service = 'gcp') {
235
235
  }
236
236
  };
237
237
  }
238
+ exports.default = upload;
238
239
 
239
- module.exports = upload;
240
+ if (exports.default) {
241
+ module.exports = exports.default;
242
+ module.exports.default = exports.default;
243
+ }