@8ms/helpers 2.0.0 → 2.0.1
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/.github/workflows/deploy_npmjs.yml +7 -0
- package/.yarn/install-state.gz +0 -0
- package/_class/BaseClass.d.ts +18 -0
- package/_class/BaseClass.js +53 -0
- package/_class/BaseNamespace.d.ts +9 -0
- package/_class/BaseNamespace.js +27 -0
- package/_class/index.d.ts +2 -0
- package/_class/index.js +7 -0
- package/adverity/getJobs.d.ts +15 -0
- package/adverity/getJobs.js +30 -0
- package/adverity/index.d.ts +112 -0
- package/adverity/index.js +61 -0
- package/api/ApiResponseClass.d.ts +35 -0
- package/api/ApiResponseClass.js +97 -0
- package/api/index.d.ts +22 -0
- package/api/index.js +44 -0
- package/array/index.d.ts +8 -0
- package/array/index.js +17 -0
- package/atInternet/index.d.ts +16 -0
- package/atInternet/index.js +18 -0
- package/aws/athenaExpress/AwsAthenaNamespace.d.ts +8 -0
- package/aws/athenaExpress/AwsAthenaNamespace.js +82 -0
- package/aws/athenaExpress/index.d.ts +10 -0
- package/aws/athenaExpress/index.js +40 -0
- package/aws/ec2/AwsEc2Namespace.d.ts +10 -0
- package/aws/ec2/AwsEc2Namespace.js +78 -0
- package/aws/ec2/index.d.ts +3 -0
- package/aws/ec2/index.js +16 -0
- package/aws/ecs/AwsEcsNamespace.d.ts +53 -0
- package/aws/ecs/AwsEcsNamespace.js +159 -0
- package/aws/ecs/index.d.ts +3 -0
- package/aws/ecs/index.js +16 -0
- package/aws/glue/AwsGlueNamespace.d.ts +12 -0
- package/aws/glue/AwsGlueNamespace.js +70 -0
- package/aws/glue/index.d.ts +3 -0
- package/aws/glue/index.js +16 -0
- package/aws/index.d.ts +9 -0
- package/aws/index.js +34 -0
- package/aws/isResponse200.d.ts +4 -0
- package/aws/isResponse200.js +16 -0
- package/aws/lambda/AwsLambdaNamespace.d.ts +21 -0
- package/aws/lambda/AwsLambdaNamespace.js +110 -0
- package/aws/lambda/index.d.ts +4 -0
- package/aws/lambda/index.js +21 -0
- package/aws/s3/AwsS3Namespace.d.ts +60 -0
- package/aws/s3/AwsS3Namespace.js +401 -0
- package/aws/s3/index.d.ts +25 -0
- package/aws/s3/index.js +36 -0
- package/aws/s3/payload.d.ts +42 -0
- package/aws/s3/payload.js +46 -0
- package/aws/ses/AwsSesNamespace.d.ts +18 -0
- package/aws/ses/AwsSesNamespace.js +69 -0
- package/aws/ses/SimpleEmail.d.ts +56 -0
- package/aws/ses/SimpleEmail.js +106 -0
- package/aws/ses/index.d.ts +4 -0
- package/aws/ses/index.js +18 -0
- package/aws/sqs/AwsSqsNamespace.d.ts +34 -0
- package/aws/sqs/AwsSqsNamespace.js +96 -0
- package/aws/sqs/index.d.ts +3 -0
- package/aws/sqs/index.js +16 -0
- package/aws/ssm/AwsSsmNamespace.d.ts +11 -0
- package/aws/ssm/AwsSsmNamespace.js +89 -0
- package/aws/ssm/index.d.ts +3 -0
- package/aws/ssm/index.js +16 -0
- package/axios/deleteRequest.d.ts +6 -0
- package/axios/deleteRequest.js +33 -0
- package/axios/get.d.ts +5 -0
- package/axios/get.js +31 -0
- package/axios/index.d.ts +3 -0
- package/axios/index.js +9 -0
- package/axios/post.d.ts +5 -0
- package/axios/post.js +32 -0
- package/boolean/getBoolean.d.ts +4 -0
- package/boolean/getBoolean.js +23 -0
- package/boolean/index.d.ts +1 -0
- package/boolean/index.js +5 -0
- package/brightData/index.d.ts +15 -0
- package/brightData/index.js +20 -0
- package/brightData/serpApi/buildGoogleSerpUrl.d.ts +32 -0
- package/brightData/serpApi/buildGoogleSerpUrl.js +116 -0
- package/brightData/serpApi/buildGoogleTrendsUrl.d.ts +22 -0
- package/brightData/serpApi/buildGoogleTrendsUrl.js +61 -0
- package/brightData/serpApi/getAsyncRequestId.d.ts +8 -0
- package/brightData/serpApi/getAsyncRequestId.js +36 -0
- package/brightData/serpApi/getAsyncResults.d.ts +7 -0
- package/brightData/serpApi/getAsyncResults.js +35 -0
- package/brightData/serpApi/getRealtime.d.ts +5 -0
- package/brightData/serpApi/getRealtime.js +30 -0
- package/brightData/serpApi/index.d.ts +14 -0
- package/brightData/serpApi/index.js +23 -0
- package/brightData/webScraperIde/getBatch.d.ts +7 -0
- package/brightData/webScraperIde/getBatch.js +28 -0
- package/brightData/webScraperIde/getRealtime.d.ts +7 -0
- package/brightData/webScraperIde/getRealtime.js +49 -0
- package/brightData/webScraperIde/index.d.ts +2 -0
- package/brightData/webScraperIde/index.js +7 -0
- package/cache/index.d.ts +2 -0
- package/cache/index.js +48 -0
- package/cache/test/cache.test.d.ts +1 -0
- package/cache/test/cache.test.js +10 -0
- package/crud/index.d.ts +6 -0
- package/crud/index.js +10 -0
- package/crypto/getDecrypt.d.ts +5 -0
- package/crypto/getDecrypt.js +47 -0
- package/crypto/getEncrypt.d.ts +5 -0
- package/crypto/getEncrypt.js +47 -0
- package/crypto/getRandom.d.ts +4 -0
- package/crypto/getRandom.js +12 -0
- package/crypto/getSha256.d.ts +5 -0
- package/crypto/getSha256.js +48 -0
- package/crypto/index.d.ts +4 -0
- package/crypto/index.js +11 -0
- package/date/calculation.d.ts +75 -0
- package/date/calculation.js +207 -0
- package/date/financialYear.d.ts +19 -0
- package/date/financialYear.js +85 -0
- package/date/format.d.ts +68 -0
- package/date/format.js +150 -0
- package/date/index.d.ts +35 -0
- package/date/index.js +57 -0
- package/environment/index.d.ts +32 -0
- package/environment/index.js +92 -0
- package/eskimi/getAgeGroup.d.ts +4 -0
- package/eskimi/getAgeGroup.js +15 -0
- package/eskimi/getData.d.ts +4 -0
- package/eskimi/getData.js +17 -0
- package/eskimi/getDevice.d.ts +4 -0
- package/eskimi/getDevice.js +15 -0
- package/eskimi/getGender.d.ts +4 -0
- package/eskimi/getGender.js +15 -0
- package/eskimi/index.d.ts +49 -0
- package/eskimi/index.js +96 -0
- package/file/createDirectory.d.ts +5 -0
- package/file/createDirectory.js +50 -0
- package/file/index.d.ts +1 -0
- package/file/index.js +5 -0
- package/geo/countries.d.ts +12 -0
- package/geo/countries.js +222 -0
- package/geo/index.d.ts +2 -0
- package/geo/index.js +7 -0
- package/geo/languages.d.ts +9 -0
- package/geo/languages.js +58 -0
- package/google/bigQuery/GoogleBigQueryNamespace.d.ts +51 -0
- package/google/bigQuery/GoogleBigQueryNamespace.js +165 -0
- package/google/bigQuery/index.d.ts +5 -0
- package/google/bigQuery/index.js +37 -0
- package/google/bigQuery/loadData.d.ts +19 -0
- package/google/bigQuery/loadData.js +18 -0
- package/google/index.d.ts +27 -0
- package/google/index.js +24 -0
- package/google/sheets/GoogleSheetsNamespace.d.ts +16 -0
- package/google/sheets/GoogleSheetsNamespace.js +81 -0
- package/google/sheets/getAssociatedData.d.ts +10 -0
- package/google/sheets/getAssociatedData.js +43 -0
- package/google/sheets/index.d.ts +8 -0
- package/google/sheets/index.js +37 -0
- package/google/storage/GoogleCloudStorageNamespace.d.ts +20 -0
- package/google/storage/GoogleCloudStorageNamespace.js +108 -0
- package/google/storage/index.d.ts +3 -0
- package/google/storage/index.js +30 -0
- package/googleAds/GoogleAdsNamespace.d.ts +11 -0
- package/googleAds/GoogleAdsNamespace.js +73 -0
- package/googleAds/index.d.ts +11 -0
- package/googleAds/index.js +30 -0
- package/googleAds/keywordPlanner/index.d.ts +40 -0
- package/googleAds/keywordPlanner/index.js +59 -0
- package/googlePageSpeed/GooglePageSpeedNamespace.d.ts +11 -0
- package/googlePageSpeed/GooglePageSpeedNamespace.js +35 -0
- package/googlePageSpeed/index.d.ts +17 -0
- package/googlePageSpeed/index.js +44 -0
- package/googleSearchIncidents/index.d.ts +69 -0
- package/googleSearchIncidents/index.js +46 -0
- package/greenDomain/index.d.ts +21 -0
- package/greenDomain/index.js +41 -0
- package/inngest/index.d.ts +6 -0
- package/inngest/index.js +10 -0
- package/json/getJsonNewline.d.ts +1 -0
- package/json/getJsonNewline.js +13 -0
- package/json/index.d.ts +2 -0
- package/json/index.js +7 -0
- package/json/isJson.d.ts +1 -0
- package/json/isJson.js +26 -0
- package/littleWarden/LittleWardenNamespace.d.ts +11 -0
- package/littleWarden/LittleWardenNamespace.js +38 -0
- package/littleWarden/getUrlStatus.d.ts +4 -0
- package/littleWarden/getUrlStatus.js +16 -0
- package/littleWarden/index.d.ts +29 -0
- package/littleWarden/index.js +74 -0
- package/lumar/api/buildRequest.d.ts +13 -0
- package/lumar/api/buildRequest.js +80 -0
- package/lumar/api/getData.d.ts +5 -0
- package/lumar/api/getData.js +13 -0
- package/lumar/api/index.d.ts +36 -0
- package/lumar/api/index.js +33 -0
- package/lumar/api/initClient.d.ts +6 -0
- package/lumar/api/initClient.js +26 -0
- package/lumar/graphql/columns.d.ts +28 -0
- package/lumar/graphql/columns.js +31 -0
- package/lumar/graphql/getData.d.ts +1 -0
- package/lumar/graphql/getData.js +20 -0
- package/lumar/graphql/index.d.ts +29 -0
- package/lumar/graphql/index.js +39 -0
- package/lumar/graphql/initClient.d.ts +5 -0
- package/lumar/graphql/initClient.js +25 -0
- package/lumar/graphql/queries/crawl.d.ts +5 -0
- package/lumar/graphql/queries/crawl.js +2 -0
- package/lumar/graphql/queries/getCrawls.d.ts +18 -0
- package/lumar/graphql/queries/getCrawls.js +33 -0
- package/lumar/graphql/queries/getReportDifferences.d.ts +24 -0
- package/lumar/graphql/queries/getReportDifferences.js +37 -0
- package/lumar/graphql/queries/getRows.d.ts +38 -0
- package/lumar/graphql/queries/getRows.js +57 -0
- package/lumar/graphql/queries/getTotals.d.ts +25 -0
- package/lumar/graphql/queries/getTotals.js +40 -0
- package/lumar/graphql/queries/row.d.ts +157 -0
- package/lumar/graphql/queries/row.js +2 -0
- package/lumar/graphql/reportTemplates.d.ts +67 -0
- package/lumar/graphql/reportTemplates.js +70 -0
- package/myTarget/request.d.ts +5 -0
- package/myTarget/request.js +17 -0
- package/nextAuth/index.d.ts +6 -0
- package/nextAuth/index.js +11 -0
- package/nextAuth/isSessionReady.d.ts +1 -0
- package/nextAuth/isSessionReady.js +13 -0
- package/nextJs/getIp.d.ts +6 -0
- package/nextJs/getIp.js +14 -0
- package/nextJs/getUserAgent.d.ts +6 -0
- package/nextJs/getUserAgent.js +8 -0
- package/nextJs/index.d.ts +2 -0
- package/nextJs/index.js +7 -0
- package/number/format.d.ts +12 -0
- package/number/format.js +20 -0
- package/number/formatCurrency.d.ts +5 -0
- package/number/formatCurrency.js +21 -0
- package/number/getDecimal.d.ts +4 -0
- package/number/getDecimal.js +12 -0
- package/number/getNumber.d.ts +4 -0
- package/number/getNumber.js +48 -0
- package/number/getPercentIncrease.d.ts +4 -0
- package/number/getPercentIncrease.js +16 -0
- package/number/getSafeDivide.d.ts +11 -0
- package/number/getSafeDivide.js +20 -0
- package/number/index.d.ts +6 -0
- package/number/index.js +15 -0
- package/object/index.d.ts +1 -0
- package/object/index.js +5 -0
- package/object/replaceKeys.d.ts +5 -0
- package/object/replaceKeys.js +25 -0
- package/onePassword/OnePasswordNamespace.d.ts +13 -0
- package/onePassword/OnePasswordNamespace.js +81 -0
- package/onePassword/index.d.ts +7 -0
- package/onePassword/index.js +25 -0
- package/openAi/OpenAiNamespace.d.ts +11 -0
- package/openAi/OpenAiNamespace.js +44 -0
- package/openAi/index.d.ts +5 -0
- package/openAi/index.js +30 -0
- package/package.json +2 -2
- package/prisma/PrismaNamespace.d.ts +8 -0
- package/prisma/PrismaNamespace.js +79 -0
- package/prisma/getDecimal.d.ts +4 -0
- package/prisma/getDecimal.js +23 -0
- package/prisma/index.d.ts +8 -0
- package/prisma/index.js +29 -0
- package/snapchat/SnapchatNamespace.d.ts +15 -0
- package/snapchat/SnapchatNamespace.js +30 -0
- package/snapchat/index.d.ts +7 -0
- package/snapchat/index.js +30 -0
- package/sorting/byNumberAscending.d.ts +4 -0
- package/sorting/byNumberAscending.js +19 -0
- package/sorting/byNumberDescending.d.ts +4 -0
- package/sorting/byNumberDescending.js +22 -0
- package/sorting/byStringAscending.d.ts +4 -0
- package/sorting/byStringAscending.js +16 -0
- package/sorting/byStringDescending.d.ts +4 -0
- package/sorting/byStringDescending.js +16 -0
- package/sorting/index.d.ts +4 -0
- package/sorting/index.js +11 -0
- package/stream/index.d.ts +1 -0
- package/stream/index.js +5 -0
- package/stream/sort.d.ts +13 -0
- package/stream/sort.js +51 -0
- package/string/getCapitalised.d.ts +5 -0
- package/string/getCapitalised.js +18 -0
- package/string/getClean.d.ts +18 -0
- package/string/getClean.js +51 -0
- package/string/getFolder.d.ts +4 -0
- package/string/getFolder.js +15 -0
- package/string/getProperCase.d.ts +11 -0
- package/string/getProperCase.js +25 -0
- package/string/getString.d.ts +4 -0
- package/string/getString.js +34 -0
- package/string/getStringFromStream.d.ts +5 -0
- package/string/getStringFromStream.js +17 -0
- package/string/getUnescaped.d.ts +6 -0
- package/string/getUnescaped.js +26 -0
- package/string/getWithoutAccents.d.ts +5 -0
- package/string/getWithoutAccents.js +13 -0
- package/string/getWithoutHtmlTags.d.ts +5 -0
- package/string/getWithoutHtmlTags.js +12 -0
- package/string/getWithoutPunctuation.d.ts +5 -0
- package/string/getWithoutPunctuation.js +13 -0
- package/string/getWithoutUnderscores.d.ts +4 -0
- package/string/getWithoutUnderscores.js +11 -0
- package/string/getWithoutWhitespaces.d.ts +5 -0
- package/string/getWithoutWhitespaces.js +13 -0
- package/string/index.d.ts +12 -0
- package/string/index.js +27 -0
- package/swr/index.d.ts +42 -0
- package/swr/index.js +59 -0
- package/upTimeRobot/UpTimeRobotNamespace.d.ts +31 -0
- package/upTimeRobot/UpTimeRobotNamespace.js +52 -0
- package/upTimeRobot/index.d.ts +38 -0
- package/upTimeRobot/index.js +63 -0
- package/url/index.d.ts +19 -0
- package/url/index.js +70 -0
- package/url/writeUrlContents.d.ts +6 -0
- package/url/writeUrlContents.js +75 -0
- package/util/defaultTo.d.ts +4 -0
- package/util/defaultTo.js +44 -0
- package/util/getBrotliCompressed.d.ts +5 -0
- package/util/getBrotliCompressed.js +23 -0
- package/util/getBrotliDecompressed.d.ts +5 -0
- package/util/getBrotliDecompressed.js +24 -0
- package/util/getClean.d.ts +11 -0
- package/util/getClean.js +23 -0
- package/util/getGzipCompressed.d.ts +5 -0
- package/util/getGzipCompressed.js +23 -0
- package/util/getGzipDecompressed.d.ts +5 -0
- package/util/getGzipDecompressed.js +24 -0
- package/util/getWithoutHash.d.ts +4 -0
- package/util/getWithoutHash.js +18 -0
- package/util/getWithoutParameter.d.ts +4 -0
- package/util/getWithoutParameter.js +18 -0
- package/util/index.d.ts +11 -0
- package/util/index.js +25 -0
- package/util/isUndefined.d.ts +4 -0
- package/util/isUndefined.js +13 -0
- package/util/promiseChunks.d.ts +5 -0
- package/util/promiseChunks.js +19 -0
- package/util/sleep.d.ts +1 -0
- package/util/sleep.js +7 -0
- package/webWorker/index.d.ts +5 -0
- package/webWorker/index.js +9 -0
- package/xml/getXml.d.ts +1 -0
- package/xml/getXml.js +18 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.GoogleBigQueryNamespace = void 0;
|
|
37
|
+
const _class_1 = require("../../_class");
|
|
38
|
+
const index_1 = require("../index");
|
|
39
|
+
class GoogleBigQueryNamespace extends _class_1.BaseNamespace {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
42
|
+
this.client = null;
|
|
43
|
+
this.ensureInit = async () => {
|
|
44
|
+
if (!this.client) {
|
|
45
|
+
try {
|
|
46
|
+
const { BigQuery } = await Promise.resolve().then(() => __importStar(require("@google-cloud/bigquery")));
|
|
47
|
+
const formattedConfig = (0, index_1.getConfig)(this.config);
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
this.client = new BigQuery(formattedConfig);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
throw new Error("Google BigQuery Client not installed");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Create a Dataset if it doesn't already exist.
|
|
58
|
+
* Returns table instance.
|
|
59
|
+
*/
|
|
60
|
+
this.createDataset = async (datasetId, options = {}) => {
|
|
61
|
+
await this.ensureInit();
|
|
62
|
+
const datasetExists = await this.datasetExists(datasetId);
|
|
63
|
+
if (!datasetExists) {
|
|
64
|
+
await this.client.createDataset(datasetId, options || {});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Check to see whether a given BigQuery dataset exists.
|
|
69
|
+
* Based off:
|
|
70
|
+
* https://github.com/googleapis/nodejs-bigquery/blob/main/samples/getDataset.js
|
|
71
|
+
*/
|
|
72
|
+
this.datasetExists = async (datasetId) => {
|
|
73
|
+
await this.ensureInit();
|
|
74
|
+
let response;
|
|
75
|
+
try {
|
|
76
|
+
await this.client.dataset(datasetId)
|
|
77
|
+
.get();
|
|
78
|
+
response = true;
|
|
79
|
+
}
|
|
80
|
+
catch (exception) {
|
|
81
|
+
response = false;
|
|
82
|
+
}
|
|
83
|
+
return response;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Retrieve all the Datasets
|
|
87
|
+
*/
|
|
88
|
+
this.getDataset = async () => {
|
|
89
|
+
await this.ensureInit();
|
|
90
|
+
let response = [];
|
|
91
|
+
const datasets = await this.client.getDatasets();
|
|
92
|
+
if (datasets?.[0]) {
|
|
93
|
+
for (let i = 0; i < datasets[0].length; i++) {
|
|
94
|
+
response.push({
|
|
95
|
+
id: datasets[0][i].id,
|
|
96
|
+
location: datasets[0][i].location,
|
|
97
|
+
projectId: datasets[0][i].bigQuery.projectId,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return response;
|
|
102
|
+
};
|
|
103
|
+
this.query = async (props) => {
|
|
104
|
+
await this.ensureInit();
|
|
105
|
+
let queryString = "string" === typeof props ? props : props.query;
|
|
106
|
+
let options = "string" === typeof props ? {} : props?.params;
|
|
107
|
+
const apiResponse = await this.client.query({
|
|
108
|
+
query: queryString,
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
options,
|
|
111
|
+
});
|
|
112
|
+
return apiResponse;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Create a Table if it doesn't already exist.
|
|
116
|
+
*/
|
|
117
|
+
this.createTable = async (datasetId, datasetOptions = {}, tableId, options = {}) => {
|
|
118
|
+
await this.ensureInit();
|
|
119
|
+
// Create the BigQuery table if it doesn't exist
|
|
120
|
+
await this.createDataset(datasetId, datasetOptions);
|
|
121
|
+
const tableExists = await this.tableExists(datasetId, tableId);
|
|
122
|
+
if (!tableExists) {
|
|
123
|
+
await this.client
|
|
124
|
+
.dataset(datasetId)
|
|
125
|
+
.createTable(tableId, options || {});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Check to see whether a given BigQuery table exists.
|
|
130
|
+
* https://cloud.google.com/bigquery/docs/samples/bigquery-table-exists
|
|
131
|
+
*/
|
|
132
|
+
this.tableExists = async (datasetId, tableId) => {
|
|
133
|
+
await this.ensureInit();
|
|
134
|
+
let response;
|
|
135
|
+
const dataset = this.client.dataset(datasetId);
|
|
136
|
+
try {
|
|
137
|
+
await dataset.table(tableId)
|
|
138
|
+
.get();
|
|
139
|
+
response = true;
|
|
140
|
+
}
|
|
141
|
+
catch (exception) {
|
|
142
|
+
response = false;
|
|
143
|
+
}
|
|
144
|
+
return response;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Retrieve all the Tables from a given Project/Dataset.
|
|
148
|
+
*/
|
|
149
|
+
this.getTable = async (datasetId) => {
|
|
150
|
+
await this.ensureInit();
|
|
151
|
+
let response = [];
|
|
152
|
+
const tables = await this.client.dataset(datasetId)
|
|
153
|
+
.getTables();
|
|
154
|
+
if (tables?.[0]) {
|
|
155
|
+
for (let i = 0; i < tables[0].length; i++) {
|
|
156
|
+
response.push({
|
|
157
|
+
id: tables[0][i].id,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return response;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.GoogleBigQueryNamespace = GoogleBigQueryNamespace;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GoogleBigQueryNamespace } from "./GoogleBigQueryNamespace";
|
|
2
|
+
import type { GoogleAuthOptions } from "@google-cloud/common";
|
|
3
|
+
export declare const googleBigQueryClient: (key?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string) => Promise<GoogleBigQueryNamespace>;
|
|
4
|
+
export declare const getHandlerPath: (input: string) => string;
|
|
5
|
+
export { loadData } from "./loadData";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadData = exports.getHandlerPath = exports.googleBigQueryClient = void 0;
|
|
4
|
+
const GoogleBigQueryNamespace_1 = require("./GoogleBigQueryNamespace");
|
|
5
|
+
const onePassword_1 = require("../../onePassword");
|
|
6
|
+
const googleBigQueryNamespaces = new Map();
|
|
7
|
+
const googleBigQueryClient = async (key = "default", config, vaultId, itemId) => {
|
|
8
|
+
if (googleBigQueryNamespaces.has(key)) {
|
|
9
|
+
return googleBigQueryNamespaces.get(key);
|
|
10
|
+
}
|
|
11
|
+
let instanceConfig;
|
|
12
|
+
if (config) {
|
|
13
|
+
instanceConfig = config;
|
|
14
|
+
}
|
|
15
|
+
else if (vaultId && itemId) {
|
|
16
|
+
instanceConfig = await (await (0, onePassword_1.onePasswordClient)())
|
|
17
|
+
.getJsonNote(vaultId, itemId);
|
|
18
|
+
}
|
|
19
|
+
else if ("default" === key && process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
|
|
20
|
+
instanceConfig = await (await (0, onePassword_1.onePasswordClient)())
|
|
21
|
+
.getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(`Config required for namespace '${key}'`);
|
|
25
|
+
}
|
|
26
|
+
const namespace = new GoogleBigQueryNamespace_1.GoogleBigQueryNamespace(key, instanceConfig);
|
|
27
|
+
googleBigQueryNamespaces.set(key, namespace);
|
|
28
|
+
return namespace;
|
|
29
|
+
};
|
|
30
|
+
exports.googleBigQueryClient = googleBigQueryClient;
|
|
31
|
+
const getHandlerPath = (input) => {
|
|
32
|
+
return `${input.split(process.cwd())[1].substring(1)
|
|
33
|
+
.replace(/\\/g, "/")}`;
|
|
34
|
+
};
|
|
35
|
+
exports.getHandlerPath = getHandlerPath;
|
|
36
|
+
var loadData_1 = require("./loadData");
|
|
37
|
+
Object.defineProperty(exports, "loadData", { enumerable: true, get: function () { return loadData_1.loadData; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GoogleBigQueryNamespace } from "./GoogleBigQueryNamespace";
|
|
2
|
+
type LoadData = {
|
|
3
|
+
googleBigQueryClient: GoogleBigQueryNamespace;
|
|
4
|
+
googleCloudStorageClient: any;
|
|
5
|
+
file: {
|
|
6
|
+
bucket: string;
|
|
7
|
+
key: string;
|
|
8
|
+
metadata: object;
|
|
9
|
+
};
|
|
10
|
+
table: {
|
|
11
|
+
datasetId: string;
|
|
12
|
+
tableId: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Load data into a given table using Google Cloud Storage.
|
|
17
|
+
*/
|
|
18
|
+
export declare const loadData: ({ file, googleBigQueryClient, googleCloudStorageClient, table }: LoadData) => Promise<void>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadData = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Load data into a given table using Google Cloud Storage.
|
|
6
|
+
*/
|
|
7
|
+
const loadData = async ({ file, googleBigQueryClient, googleCloudStorageClient, table }) => {
|
|
8
|
+
const tableExists = await googleBigQueryClient.tableExists(table.datasetId, table.tableId);
|
|
9
|
+
if (tableExists) {
|
|
10
|
+
await googleBigQueryClient.client
|
|
11
|
+
.dataset(table.datasetId)
|
|
12
|
+
.table(table.tableId)
|
|
13
|
+
.load(googleCloudStorageClient.client
|
|
14
|
+
.bucket(file.bucket)
|
|
15
|
+
.file(file.key), file.metadata);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.loadData = loadData;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type GoogleCloudConfig = {
|
|
2
|
+
type: string;
|
|
3
|
+
project_id: string;
|
|
4
|
+
private_key_id: string;
|
|
5
|
+
private_key: string;
|
|
6
|
+
client_email: string;
|
|
7
|
+
client_id: string;
|
|
8
|
+
auth_uri: string;
|
|
9
|
+
token_uri: string;
|
|
10
|
+
auth_provider_x509_cert_url: string;
|
|
11
|
+
client_x509_cert_url: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Using the response from Parameter Store and format it ready to be used with Google API.
|
|
15
|
+
*/
|
|
16
|
+
export declare const getConfig: (parameter: GoogleCloudConfig) => {
|
|
17
|
+
type: string;
|
|
18
|
+
project_id: string;
|
|
19
|
+
private_key_id: string;
|
|
20
|
+
private_key: string;
|
|
21
|
+
client_email: string;
|
|
22
|
+
client_id: string;
|
|
23
|
+
auth_uri: string;
|
|
24
|
+
token_uri: string;
|
|
25
|
+
auth_provider_x509_cert_url: string;
|
|
26
|
+
client_x509_cert_url: string;
|
|
27
|
+
};
|
package/google/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConfig = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Using the response from Parameter Store and format it ready to be used with Google API.
|
|
6
|
+
*/
|
|
7
|
+
const getConfig = (parameter) => {
|
|
8
|
+
// Format the private key to be in the same format as required by Google
|
|
9
|
+
const privateKey = parameter["private_key"].replace(/\\n/g, "\n");
|
|
10
|
+
const response = {
|
|
11
|
+
type: parameter["type"],
|
|
12
|
+
project_id: parameter["project_id"],
|
|
13
|
+
private_key_id: parameter["private_key_id"],
|
|
14
|
+
private_key: privateKey,
|
|
15
|
+
client_email: parameter["client_email"],
|
|
16
|
+
client_id: parameter["client_id"],
|
|
17
|
+
auth_uri: parameter["auth_uri"],
|
|
18
|
+
token_uri: parameter["token_uri"],
|
|
19
|
+
auth_provider_x509_cert_url: parameter["auth_provider_x509_cert_url"],
|
|
20
|
+
client_x509_cert_url: parameter["client_x509_cert_url"],
|
|
21
|
+
};
|
|
22
|
+
return response;
|
|
23
|
+
};
|
|
24
|
+
exports.getConfig = getConfig;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseNamespace } from "../../_class";
|
|
2
|
+
import { GoogleCloudConfig } from "../index";
|
|
3
|
+
import type { GoogleAuth } from "googleapis-common";
|
|
4
|
+
type GetBatchDataProps = {
|
|
5
|
+
spreadsheetId: string;
|
|
6
|
+
ranges: string[];
|
|
7
|
+
dateTimeRender?: string;
|
|
8
|
+
valueRender?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class GoogleSheetsNamespace extends BaseNamespace {
|
|
11
|
+
client: GoogleAuth | null;
|
|
12
|
+
config: GoogleCloudConfig | null;
|
|
13
|
+
ensureInit: () => Promise<void>;
|
|
14
|
+
getBatchData: (props: GetBatchDataProps) => Promise<import("@googleapis/sheets").sheets_v4.Schema$BatchGetValuesResponse>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.GoogleSheetsNamespace = void 0;
|
|
37
|
+
const _class_1 = require("../../_class");
|
|
38
|
+
const index_1 = require("../index");
|
|
39
|
+
class GoogleSheetsNamespace extends _class_1.BaseNamespace {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
42
|
+
// Stores auth only for Google Sheets
|
|
43
|
+
this.client = null;
|
|
44
|
+
this.config = null;
|
|
45
|
+
this.ensureInit = async () => {
|
|
46
|
+
if (!this.client) {
|
|
47
|
+
try {
|
|
48
|
+
const googleApisSheets = await Promise.resolve().then(() => __importStar(require("@googleapis/sheets")));
|
|
49
|
+
const formattedConfig = (0, index_1.getConfig)(this.config);
|
|
50
|
+
this.client = new googleApisSheets.auth.GoogleAuth({
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
credentials: formattedConfig,
|
|
53
|
+
scopes: [
|
|
54
|
+
"https://www.googleapis.com/auth/spreadsheets",
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw new Error("Google Sheets Client not installed");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
this.getBatchData = async (props) => {
|
|
64
|
+
await this.ensureInit();
|
|
65
|
+
const googleApisSheets = await Promise.resolve().then(() => __importStar(require("@googleapis/sheets")));
|
|
66
|
+
// Make the API request
|
|
67
|
+
const apiResponse = await googleApisSheets.sheets("v4")
|
|
68
|
+
.spreadsheets
|
|
69
|
+
.values
|
|
70
|
+
.batchGet({
|
|
71
|
+
auth: this.client,
|
|
72
|
+
dateTimeRenderOption: props?.dateTimeRender || "FORMATTED_STRING",
|
|
73
|
+
ranges: props.ranges,
|
|
74
|
+
spreadsheetId: props.spreadsheetId,
|
|
75
|
+
valueRenderOption: props?.valueRender || "UNFORMATTED_VALUE"
|
|
76
|
+
});
|
|
77
|
+
return apiResponse.data;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.GoogleSheetsNamespace = GoogleSheetsNamespace;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type GetAssociatedDataProps = {
|
|
2
|
+
data: any;
|
|
3
|
+
dateTimeRender: 'FORMATTED_STRING' | 'SERIAL_NUMBER';
|
|
4
|
+
valueRender: 'FORMATTED_VALUE' | 'UNFORMATTED_VALUE' | 'FORMULA';
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Pass a batch request using getBatchData and format the data into a key => value object per row.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getAssociatedData: (props: GetAssociatedDataProps) => Promise<object[]>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAssociatedData = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Pass a batch request using getBatchData and format the data into a key => value object per row.
|
|
6
|
+
*/
|
|
7
|
+
const getAssociatedData = async (props) => {
|
|
8
|
+
let template = [];
|
|
9
|
+
let response = [];
|
|
10
|
+
// Missing ranges or too many ranges
|
|
11
|
+
if (4 !== props.data.valueRanges.length) {
|
|
12
|
+
throw new Error("Associated data response length must be 4.");
|
|
13
|
+
}
|
|
14
|
+
// Get the first data range
|
|
15
|
+
const initialRangeLength = props.data.valueRanges[0].values[0].length;
|
|
16
|
+
// Loop through the headings
|
|
17
|
+
for (let i = 0; i < initialRangeLength; i++) {
|
|
18
|
+
template.push({
|
|
19
|
+
format: props.data.valueRanges[0].values[0][i],
|
|
20
|
+
default: props.data.valueRanges[1].values[0][i],
|
|
21
|
+
heading: props.data.valueRanges[2].values[0][i],
|
|
22
|
+
index: i,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
// console.log('template', template);
|
|
26
|
+
// Loop through each row of data
|
|
27
|
+
if (undefined !== props.data.valueRanges[3].values) {
|
|
28
|
+
for (let rowIndex = 0; rowIndex < props.data.valueRanges[3].values.length; rowIndex++) {
|
|
29
|
+
let row = {};
|
|
30
|
+
// Loop through each column within the row
|
|
31
|
+
for (let columnIndex = 0; columnIndex < props.data.valueRanges[3].values[rowIndex].length; columnIndex++) {
|
|
32
|
+
const refValue = props.data.valueRanges[3].values[rowIndex][columnIndex];
|
|
33
|
+
const value = ('' === refValue ? template[columnIndex]['default'] : refValue);
|
|
34
|
+
// Add this to our row
|
|
35
|
+
row[template[columnIndex]['heading']] = value;
|
|
36
|
+
}
|
|
37
|
+
// Add the row to our response
|
|
38
|
+
response.push(row);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return response;
|
|
42
|
+
};
|
|
43
|
+
exports.getAssociatedData = getAssociatedData;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GoogleSheetsNamespace } from "./GoogleSheetsNamespace";
|
|
2
|
+
import type { GoogleAuthOptions } from "@google-cloud/common";
|
|
3
|
+
export declare const googleSheetsAuths: (key?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string) => Promise<GoogleSheetsNamespace>;
|
|
4
|
+
/**
|
|
5
|
+
* Noticed sometimes Google Sheets can struggle with import XML resulting to N/A values.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isCellNa: (input: any) => boolean;
|
|
8
|
+
export { getAssociatedData } from "./getAssociatedData";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAssociatedData = exports.isCellNa = exports.googleSheetsAuths = void 0;
|
|
4
|
+
const GoogleSheetsNamespace_1 = require("./GoogleSheetsNamespace");
|
|
5
|
+
const onePassword_1 = require("../../onePassword");
|
|
6
|
+
const googleSheetsNamespaces = new Map();
|
|
7
|
+
const googleSheetsAuths = async (key = "default", config, vaultId, itemId) => {
|
|
8
|
+
if (googleSheetsNamespaces.has(key)) {
|
|
9
|
+
return googleSheetsNamespaces.get(key);
|
|
10
|
+
}
|
|
11
|
+
let instanceConfig;
|
|
12
|
+
if (config) {
|
|
13
|
+
instanceConfig = config;
|
|
14
|
+
}
|
|
15
|
+
else if (vaultId && itemId) {
|
|
16
|
+
instanceConfig = await (await (0, onePassword_1.onePasswordClient)())
|
|
17
|
+
.getJsonNote(vaultId, itemId);
|
|
18
|
+
}
|
|
19
|
+
else if ('default' === key && process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
|
|
20
|
+
instanceConfig = await (await (0, onePassword_1.onePasswordClient)())
|
|
21
|
+
.getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(`Config required for namespace '${key}'`);
|
|
25
|
+
}
|
|
26
|
+
const namespace = new GoogleSheetsNamespace_1.GoogleSheetsNamespace(key, instanceConfig);
|
|
27
|
+
googleSheetsNamespaces.set(key, namespace);
|
|
28
|
+
return namespace;
|
|
29
|
+
};
|
|
30
|
+
exports.googleSheetsAuths = googleSheetsAuths;
|
|
31
|
+
/**
|
|
32
|
+
* Noticed sometimes Google Sheets can struggle with import XML resulting to N/A values.
|
|
33
|
+
*/
|
|
34
|
+
const isCellNa = (input) => "#N/A" === input;
|
|
35
|
+
exports.isCellNa = isCellNa;
|
|
36
|
+
var getAssociatedData_1 = require("./getAssociatedData");
|
|
37
|
+
Object.defineProperty(exports, "getAssociatedData", { enumerable: true, get: function () { return getAssociatedData_1.getAssociatedData; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseNamespace } from "../../_class";
|
|
2
|
+
import type { Storage } from "@google-cloud/storage";
|
|
3
|
+
import { GoogleCloudConfig } from "../index";
|
|
4
|
+
export declare class GoogleCloudStorageNamespace extends BaseNamespace {
|
|
5
|
+
client: Storage | null;
|
|
6
|
+
config: GoogleCloudConfig;
|
|
7
|
+
ensureInit: () => Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Copy a local file to Google Cloud Storage.
|
|
10
|
+
*/
|
|
11
|
+
copyToCloud: (bucket: string, localFile: string, options?: {}) => Promise<import("@google-cloud/storage").UploadResponse>;
|
|
12
|
+
/**
|
|
13
|
+
* Check to see if a file exists but don't get the contents.
|
|
14
|
+
*/
|
|
15
|
+
fileExists: (bucket: string, key: string) => Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Write a file to Google Cloud Storage.
|
|
18
|
+
*/
|
|
19
|
+
writeFile: (bucket: string, key: string, data: any, options?: {}) => Promise<unknown>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.GoogleCloudStorageNamespace = void 0;
|
|
37
|
+
const _class_1 = require("../../_class");
|
|
38
|
+
const index_1 = require("../index");
|
|
39
|
+
class GoogleCloudStorageNamespace extends _class_1.BaseNamespace {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
42
|
+
this.client = null;
|
|
43
|
+
this.ensureInit = async () => {
|
|
44
|
+
if (!this.client) {
|
|
45
|
+
try {
|
|
46
|
+
const { Storage } = await Promise.resolve().then(() => __importStar(require("@google-cloud/storage")));
|
|
47
|
+
const formattedConfig = (0, index_1.getConfig)(this.config);
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
this.client = new Storage(formattedConfig);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
throw new Error("Google Cloud Storage Client not installed");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Copy a local file to Google Cloud Storage.
|
|
58
|
+
*/
|
|
59
|
+
this.copyToCloud = async (bucket, localFile, options = {}) => {
|
|
60
|
+
await this.ensureInit();
|
|
61
|
+
const apiResponse = await this.client
|
|
62
|
+
.bucket(bucket)
|
|
63
|
+
.upload(localFile, options);
|
|
64
|
+
return apiResponse;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Check to see if a file exists but don't get the contents.
|
|
68
|
+
*/
|
|
69
|
+
this.fileExists = async (bucket, key) => {
|
|
70
|
+
await this.ensureInit();
|
|
71
|
+
const googleFile = await this.client
|
|
72
|
+
.bucket(bucket)
|
|
73
|
+
.file(key)
|
|
74
|
+
.exists();
|
|
75
|
+
const response = googleFile?.[0];
|
|
76
|
+
return response;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Write a file to Google Cloud Storage.
|
|
80
|
+
*/
|
|
81
|
+
this.writeFile = async (bucket, key, data, options = {}) => {
|
|
82
|
+
await this.ensureInit();
|
|
83
|
+
const stream = await Promise.resolve().then(() => __importStar(require("stream")));
|
|
84
|
+
const dataStream = new stream.PassThrough();
|
|
85
|
+
const googleFile = this.client
|
|
86
|
+
.bucket(bucket)
|
|
87
|
+
.file(key);
|
|
88
|
+
dataStream.push(data);
|
|
89
|
+
dataStream.push(null);
|
|
90
|
+
return await new Promise((resolve, reject) => {
|
|
91
|
+
dataStream.pipe(googleFile.createWriteStream({
|
|
92
|
+
contentType: "auto",
|
|
93
|
+
resumable: false,
|
|
94
|
+
validation: false,
|
|
95
|
+
metadata: {},
|
|
96
|
+
...options,
|
|
97
|
+
}))
|
|
98
|
+
.on("error", (error) => {
|
|
99
|
+
reject(error);
|
|
100
|
+
})
|
|
101
|
+
.on("finish", () => {
|
|
102
|
+
resolve(true);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.GoogleCloudStorageNamespace = GoogleCloudStorageNamespace;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GoogleCloudStorageNamespace } from "./GoogleCloudStorageNamespace";
|
|
2
|
+
import type { GoogleAuthOptions } from "@google-cloud/common";
|
|
3
|
+
export declare const googleCloudStorageClient: (key?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string) => Promise<GoogleCloudStorageNamespace>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.googleCloudStorageClient = void 0;
|
|
4
|
+
const GoogleCloudStorageNamespace_1 = require("./GoogleCloudStorageNamespace");
|
|
5
|
+
const onePassword_1 = require("../../onePassword");
|
|
6
|
+
const googleCloudStorageNamespaces = new Map();
|
|
7
|
+
const googleCloudStorageClient = async (key = "default", config, vaultId, itemId) => {
|
|
8
|
+
if (googleCloudStorageNamespaces.has(key)) {
|
|
9
|
+
return googleCloudStorageNamespaces.get(key);
|
|
10
|
+
}
|
|
11
|
+
let instanceConfig;
|
|
12
|
+
if (config) {
|
|
13
|
+
instanceConfig = config;
|
|
14
|
+
}
|
|
15
|
+
else if (vaultId && itemId) {
|
|
16
|
+
instanceConfig = await (await (0, onePassword_1.onePasswordClient)())
|
|
17
|
+
.getJsonNote(vaultId, itemId);
|
|
18
|
+
}
|
|
19
|
+
else if ('default' === key && process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
|
|
20
|
+
instanceConfig = await (await (0, onePassword_1.onePasswordClient)())
|
|
21
|
+
.getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(`Config required for namespace '${key}'`);
|
|
25
|
+
}
|
|
26
|
+
const namespace = new GoogleCloudStorageNamespace_1.GoogleCloudStorageNamespace(key, instanceConfig);
|
|
27
|
+
googleCloudStorageNamespaces.set(key, namespace);
|
|
28
|
+
return namespace;
|
|
29
|
+
};
|
|
30
|
+
exports.googleCloudStorageClient = googleCloudStorageClient;
|