@pittica/google-business-intelligence-csv 1.1.5 → 1.3.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.
- package/dist/config.js +4 -2
- package/dist/index.js +25 -1
- package/dist/scripts/bootstrap.js +24 -0
- package/dist/scripts/clean.js +23 -0
- package/dist/scripts/pub-sub.js +33 -0
- package/dist/scripts/rollback.js +23 -0
- package/dist/scripts/unlistened.js +25 -0
- package/dist/scripts/upload.js +40 -0
- package/package.json +2 -2
package/dist/config.js
CHANGED
|
@@ -38,9 +38,11 @@ exports.config = (config = {}) => {
|
|
|
38
38
|
},
|
|
39
39
|
files: {
|
|
40
40
|
json: path.join(process.cwd(), "json"),
|
|
41
|
-
sql: path.join(process.cwd(), "sql")
|
|
41
|
+
sql: path.join(process.cwd(), "sql"),
|
|
42
|
+
bootstrap: null
|
|
42
43
|
},
|
|
43
|
-
order: []
|
|
44
|
+
order: [],
|
|
45
|
+
bootstrap: []
|
|
44
46
|
};
|
|
45
47
|
global.config = {
|
|
46
48
|
...initial,
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,24 @@ const {
|
|
|
21
21
|
const {
|
|
22
22
|
file
|
|
23
23
|
} = require("./scripts/file");
|
|
24
|
+
const {
|
|
25
|
+
bootstrap
|
|
26
|
+
} = require("./scripts/bootstrap");
|
|
27
|
+
const {
|
|
28
|
+
upload
|
|
29
|
+
} = require("./scripts/upload");
|
|
30
|
+
const {
|
|
31
|
+
clean
|
|
32
|
+
} = require("./scripts/clean");
|
|
33
|
+
const {
|
|
34
|
+
pubSub
|
|
35
|
+
} = require("./scripts/pub-sub");
|
|
36
|
+
const {
|
|
37
|
+
rollback
|
|
38
|
+
} = require("./scripts/rollback");
|
|
39
|
+
const {
|
|
40
|
+
unlistened
|
|
41
|
+
} = require("./scripts/unlistened");
|
|
24
42
|
const {
|
|
25
43
|
config
|
|
26
44
|
} = require("./config");
|
|
@@ -28,5 +46,11 @@ exports.config = config;
|
|
|
28
46
|
exports.scripts = {
|
|
29
47
|
bulk,
|
|
30
48
|
day,
|
|
31
|
-
file
|
|
49
|
+
file,
|
|
50
|
+
bootstrap,
|
|
51
|
+
upload,
|
|
52
|
+
clean,
|
|
53
|
+
pubSub,
|
|
54
|
+
rollback,
|
|
55
|
+
unlistened
|
|
32
56
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const {
|
|
16
|
+
executeSqlFolder
|
|
17
|
+
} = require("@pittica/google-bigquery-helpers");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Processes a the files from the configuration.
|
|
21
|
+
*
|
|
22
|
+
* @returns {boolean} A value indicating whether the process has been done.
|
|
23
|
+
*/
|
|
24
|
+
exports.bootstrap = async () => config.files.bootstrap ? executeSqlFolder(config.files.bootstrap, config.bootstrap) : false;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
|
|
14
|
+
const {
|
|
15
|
+
cleanDataset
|
|
16
|
+
} = require("@pittica/google-bigquery-helpers");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Drops the tables in temporary dataset.
|
|
20
|
+
*
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
exports.clean = async () => await cleanDataset(`^${config.dataset.temporary.name}.*`);
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
|
|
14
|
+
const {
|
|
15
|
+
bulk
|
|
16
|
+
} = require("./bulk");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Handles a Pub/Sub message event.
|
|
20
|
+
*
|
|
21
|
+
* @param {object} message Pub/Sub event data.
|
|
22
|
+
*/
|
|
23
|
+
exports.pubSub = async ({
|
|
24
|
+
data: {
|
|
25
|
+
message: {
|
|
26
|
+
data
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}) => {
|
|
30
|
+
if (data && Buffer.from(data, "base64").toString() == config.pubSub.message) {
|
|
31
|
+
await bulk(config.bucket.upload, config.bucket.temporary, config.bucket.archive);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
|
|
14
|
+
const {
|
|
15
|
+
moveFiles
|
|
16
|
+
} = require("@pittica/google-cloud-storage-helpers");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Moves the files from the temporary bucket to the source bucket.
|
|
20
|
+
*
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
exports.rollback = async () => await moveFiles(config.bucket.temporary, config.bucket.upload);
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
|
|
14
|
+
const {
|
|
15
|
+
scripts: {
|
|
16
|
+
unlistened
|
|
17
|
+
}
|
|
18
|
+
} = require("@pittica/google-business-intelligence-helpers");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Removes all not allowed files in "nempos-upload" bucket.
|
|
22
|
+
*
|
|
23
|
+
* @returns {void}
|
|
24
|
+
*/
|
|
25
|
+
exports.unlistened = async () => await unlistened(config.bucket.upload, config.files.sql);
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
|
|
14
|
+
const {
|
|
15
|
+
splitName
|
|
16
|
+
} = require("@pittica/google-business-intelligence-helpers");
|
|
17
|
+
const {
|
|
18
|
+
day
|
|
19
|
+
} = require("./day");
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Handles an "upload" event in Google Cloud Storage.
|
|
23
|
+
*
|
|
24
|
+
* @param {object} message Contains the event message which contains settings and type.
|
|
25
|
+
* @param {string} last Last uploaded file name without extension used as trigger.
|
|
26
|
+
*/
|
|
27
|
+
exports.upload = async ({
|
|
28
|
+
type,
|
|
29
|
+
data: {
|
|
30
|
+
bucket,
|
|
31
|
+
name
|
|
32
|
+
}
|
|
33
|
+
}, last = "till_status") => {
|
|
34
|
+
if (type === "google.cloud.storage.object.v1.finalized" && bucket === config.bucket.upload) {
|
|
35
|
+
const file = splitName(name);
|
|
36
|
+
if (file.name === last) {
|
|
37
|
+
await day(file.date, config.bucket.upload, config.bucket.temporary, config.bucket.archive);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
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.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"description": "CSV importer for business intelligence for Google Cloud.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/pittica/google-business-intelligence-csv#README.md",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@pittica/google-bigquery-helpers": "^1.
|
|
28
|
+
"@pittica/google-bigquery-helpers": "^1.4.4",
|
|
29
29
|
"@pittica/google-business-intelligence-helpers": "^1.12.7",
|
|
30
30
|
"@pittica/google-cloud-storage-helpers": "^1.3.5",
|
|
31
31
|
"@pittica/logger-helpers": "^1.0.4",
|