@pittica/google-business-intelligence-csv 1.3.0 → 1.4.0

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.
@@ -38,16 +38,16 @@ const {
38
38
  * @param {string} temporary Temporary bucket.
39
39
  * @param {string} destination Destination bucket.
40
40
  */
41
- exports.bulk = async (source, temporary, destination) => {
41
+ exports.bulk = async (source = null, temporary = null, destination = null) => {
42
42
  const storage = getStorage();
43
43
  const dataset = await getDataset(config.dataset.temporary.name, {
44
44
  location: config.dataset.temporary.location
45
45
  });
46
- const bucketSource = await storage.bucket(source);
47
- const bucketTemporary = await storage.bucket(temporary);
48
- const bucketDestination = await storage.bucket(destination);
46
+ const bucketSource = await storage.bucket(source ?? config.bucket.upload);
47
+ const bucketTemporary = await storage.bucket(temporary ?? config.bucket.temporary);
48
+ const bucketDestination = await storage.bucket(destination ?? config.bucket.archive);
49
49
  const now = getNow();
50
- storage.bucket(source).getFiles().then(response => {
50
+ bucketSource.getFiles().then(response => {
51
51
  log.info(`Starting bulk import...`);
52
52
  const files = extractStorageResponse(response, config.files.sql);
53
53
  process(dataset, bucketSource, bucketTemporary, bucketDestination, sort(files), now);
@@ -33,7 +33,8 @@ const {
33
33
  getSafeFilenameFromBucket,
34
34
  mergeFiledata,
35
35
  getNow,
36
- formatDate
36
+ formatDate,
37
+ stringToDate
37
38
  } = require("@pittica/google-business-intelligence-helpers");
38
39
  const log = require("@pittica/logger-helpers");
39
40
  const {
@@ -51,12 +52,12 @@ const {
51
52
  * @param {string} temporary Temporary bucket.
52
53
  * @param {string} destination Destination bucket.
53
54
  */
54
- exports.day = async (date, source, temporary, destination) => {
55
+ exports.day = async (date, source = null, temporary = null, destination = null) => {
55
56
  if (date) {
56
- const day = formatDate(date);
57
+ const day = formatDate(typeof date === "string" ? stringToDate(date) : date);
57
58
  const now = getNow();
58
59
  log.info(`Starting "${day}" day import...`);
59
- this.run(day, now, source, temporary, destination);
60
+ this.run(day, now, source ?? config.bucket.upload, temporary ?? config.bucket.temporary, destination ?? config.bucket.archive);
60
61
  }
61
62
  };
62
63
 
@@ -46,14 +46,14 @@ const {
46
46
  * @param {boolean} clean A value indicating whether the temporary table will be deleted.
47
47
  * @returns {boolean} A value indicating whether the process has been done.
48
48
  */
49
- exports.file = async (name, bucketSource, bucketTemporary, bucketDestination, clean = true) => {
49
+ exports.file = async (name, bucketSource = null, bucketTemporary = null, bucketDestination = null, clean = true) => {
50
50
  const filedata = splitName(name);
51
51
  if (isDataCsv(filedata, config.files.json)) {
52
52
  const storage = getStorage();
53
- const source = storage.bucket(bucketSource).file(name);
53
+ const source = storage.bucket(bucketSource ?? config.bucket.upload).file(name);
54
54
  const [exists] = await source.exists();
55
55
  if (exists) {
56
- return await copyFile(source, bucketTemporary).then(async response => {
56
+ return await copyFile(source, bucketTemporary ?? config.bucket.temporary).then(async response => {
57
57
  const file = copiedFile(response);
58
58
  if (file !== null) {
59
59
  deleteFile(source);
@@ -62,7 +62,7 @@ exports.file = async (name, bucketSource, bucketTemporary, bucketDestination, cl
62
62
  });
63
63
  const day = getNow();
64
64
  const table = await ds.table(getTemporaryTableName(filedata, config.dataset.temporary.prefix));
65
- return await this.run(table, bucketDestination, file, filedata, day, clean);
65
+ return await this.run(table, bucketDestination ?? config.bucket.archive, file, filedata, day, clean);
66
66
  }
67
67
  return false;
68
68
  }).catch(logErrors);
@@ -0,0 +1,20 @@
1
+ // Copyright 2024-2026 Pittica S.r.l.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ /**
16
+ * Processes all CSV files in upload bucket bucket or the given file.
17
+ *
18
+ * @param {string} filename Element name.
19
+ */
20
+ exports.process = async filename => filename ? await file(filename) : await bulk();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pittica/google-business-intelligence-csv",
3
3
  "private": false,
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "description": "CSV importer for business intelligence for Google Cloud.",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {