@8ms/helpers 2.2.9 → 2.2.12
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 +3 -0
- package/_class/BaseClass.js +43 -52
- package/_class/BaseNamespace.js +17 -20
- package/_class/index.js +2 -7
- package/adverity/getJobs.js +7 -11
- package/adverity/index.js +51 -54
- package/adverity/server.js +1 -5
- package/api/ApiResponseClass.js +84 -88
- package/api/functions.js +13 -22
- package/api/index.js +3 -19
- package/api/types.js +5 -9
- package/array/index.js +3 -11
- package/atInternet/index.js +10 -13
- package/aws/ec2/AwsEc2Namespace.js +34 -74
- package/aws/ec2/server.js +5 -9
- package/aws/ecs/AwsEcsNamespace.js +110 -150
- package/aws/ecs/server.js +5 -9
- package/aws/glue/AwsGlueNamespace.js +26 -66
- package/aws/glue/server.js +5 -9
- package/aws/isResponse200.js +3 -7
- package/aws/lambda/AwsLambdaNamespace.js +62 -102
- package/aws/lambda/server.js +6 -11
- package/aws/s3/AwsS3Namespace.js +347 -390
- package/aws/s3/payload.js +29 -32
- package/aws/s3/server.js +9 -14
- package/aws/server.js +5 -10
- package/aws/ses/AwsSesNamespace.js +36 -76
- package/aws/ses/SimpleEmail.js +267 -304
- package/aws/ses/server.js +6 -11
- package/aws/sqs/AwsSqsNamespace.js +49 -89
- package/aws/sqs/server.js +5 -9
- package/aws/ssm/AwsSsmNamespace.js +43 -79
- package/aws/ssm/server.js +5 -9
- package/axios/deleteRequest.js +8 -15
- package/axios/get.js +8 -15
- package/axios/index.js +3 -9
- package/axios/post.js +8 -15
- package/boolean/index.js +3 -10
- package/brightData/serpApi/buildGoogleSerpUrl.js +1 -5
- package/brightData/serpApi/buildGoogleTrendsUrl.js +1 -5
- package/brightData/serpApi/getAsyncRequestId.js +8 -12
- package/brightData/serpApi/getAsyncResults.js +8 -12
- package/brightData/serpApi/getRealtime.js +3 -7
- package/brightData/serpApi/server.js +6 -14
- package/brightData/server.js +2 -7
- package/brightData/webScraperIde/getBatch.js +3 -7
- package/brightData/webScraperIde/getRealtime.js +11 -15
- package/brightData/webScraperIde/server.js +2 -7
- package/cache/server.js +2 -7
- package/cache/test/cache.test.js +4 -6
- package/crud/index.js +1 -4
- package/crypto/getDecrypt.js +2 -39
- package/crypto/getEncrypt.js +2 -39
- package/crypto/getRandom.js +1 -5
- package/crypto/getSha256.js +4 -41
- package/crypto/index.js +4 -11
- package/date/calculation.js +70 -99
- package/date/financialYear.js +16 -23
- package/date/format.js +40 -61
- package/date/index.js +4 -20
- package/date/type.js +4 -7
- package/environment/index.js +15 -25
- package/eskimi/getAgeGroup.js +3 -7
- package/eskimi/getData.js +3 -7
- package/eskimi/getDevice.js +3 -7
- package/eskimi/getGender.js +3 -7
- package/eskimi/server.js +23 -26
- package/file/index.js +8 -46
- package/geo/countries.js +1 -4
- package/geo/index.js +2 -7
- package/geo/languages.js +1 -4
- package/google/bigQuery/GoogleBigQueryNamespace.js +108 -148
- package/google/bigQuery/loadData.js +1 -5
- package/google/bigQuery/server.js +8 -14
- package/google/server.js +1 -5
- package/google/sheets/GoogleSheetsNamespace.js +34 -74
- package/google/sheets/getAssociatedData.js +1 -5
- package/google/sheets/server.js +8 -14
- package/google/storage/GoogleCloudStorageNamespace.js +62 -102
- package/google/storage/server.js +6 -10
- package/googleAds/GoogleAdsNamespace.js +28 -68
- package/googleAds/keywordPlanner/server.js +32 -35
- package/googleAds/server.js +6 -10
- package/googlePageSpeed/GooglePageSpeedNamespace.js +21 -28
- package/googlePageSpeed/server.js +8 -12
- package/googleSearchIncidents/server.js +28 -32
- package/greenDomain/server.js +17 -21
- package/inngest/server.js +1 -4
- package/json/getJsonNewline.js +3 -7
- package/json/index.js +2 -7
- package/json/isJson.js +1 -5
- package/littleWarden/LittleWardenNamespace.js +24 -31
- package/littleWarden/getUrlStatus.js +3 -7
- package/littleWarden/server.js +14 -22
- package/lumar/api/buildRequest.js +14 -18
- package/lumar/api/getData.js +3 -7
- package/lumar/api/initClient.js +3 -7
- package/lumar/api/server.js +6 -12
- package/lumar/graphql/columns.js +1 -4
- package/lumar/graphql/getData.js +3 -7
- package/lumar/graphql/initClient.js +3 -7
- package/lumar/graphql/queries/crawl.js +1 -2
- package/lumar/graphql/queries/getCrawls.js +1 -3
- package/lumar/graphql/queries/getReportDifferences.js +3 -5
- package/lumar/graphql/queries/getRows.js +1 -3
- package/lumar/graphql/queries/getTotals.js +1 -3
- package/lumar/graphql/queries/row.js +1 -2
- package/lumar/graphql/reportTemplates.js +1 -4
- package/lumar/graphql/server.js +7 -15
- package/myTarget/server.js +3 -7
- package/nextAuth/index.js +2 -6
- package/nextAuth/isSessionReady.js +1 -5
- package/nextJs/client/LazyLoad.js +5 -12
- package/nextJs/client.js +1 -5
- package/nextJs/index.js +2 -7
- package/number/format.js +3 -7
- package/number/formatCurrency.js +1 -5
- package/number/getDecimal.js +3 -7
- package/number/getNumber.js +3 -7
- package/number/getPercentIncrease.js +4 -8
- package/number/getSafeDivide.js +6 -10
- package/number/index.js +6 -15
- package/object/index.js +1 -5
- package/object/replaceKeys.js +3 -7
- package/onePassword/OnePasswordNamespace.js +36 -76
- package/onePassword/server.js +3 -7
- package/openAi/OpenAiNamespace.js +32 -39
- package/openAi/server.js +6 -10
- package/package.json +224 -122
- package/prisma/PrismaNamespace.js +53 -93
- package/prisma/getDecimal.js +5 -12
- package/prisma/server.js +4 -9
- package/scripts/generate-exports.js +50 -0
- package/snapchat/SnapchatNamespace.js +20 -27
- package/snapchat/server.js +6 -10
- package/sorting/byNumberAscending.js +1 -5
- package/sorting/byNumberDescending.js +1 -5
- package/sorting/byStringAscending.js +1 -5
- package/sorting/byStringDescending.js +1 -5
- package/sorting/index.js +4 -11
- package/stream/server.js +1 -5
- package/stream/sort.js +1 -5
- package/string/getCapitalised.js +3 -7
- package/string/getClean.js +17 -21
- package/string/getFolder.js +3 -10
- package/string/getProperCase.js +4 -8
- package/string/getString.js +8 -15
- package/string/getStringFromStream.js +1 -5
- package/string/getUnescaped.js +3 -10
- package/string/getWithoutAccents.js +1 -5
- package/string/getWithoutHtmlTags.js +1 -5
- package/string/getWithoutPunctuation.js +1 -5
- package/string/getWithoutUnderscores.js +1 -5
- package/string/getWithoutWhitespaces.js +1 -5
- package/string/index.js +12 -27
- package/string/reservedWords.js +5 -9
- package/swr/index.js +9 -18
- package/upTimeRobot/UpTimeRobotNamespace.js +32 -42
- package/upTimeRobot/server.js +11 -15
- package/url/index.js +12 -23
- package/url/server.js +1 -5
- package/url/writeUrlContents.js +6 -46
- package/util/defaultTo.js +5 -12
- package/util/getBrotliCompressed.js +3 -10
- package/util/getBrotliDecompressed.js +3 -10
- package/util/getClean.js +5 -9
- package/util/getError.js +1 -5
- package/util/getGzipCompressed.js +3 -10
- package/util/getGzipDecompressed.js +3 -10
- package/util/getWithoutHash.js +1 -5
- package/util/getWithoutParameter.js +1 -5
- package/util/index.js +7 -17
- package/util/isUndefined.js +3 -7
- package/util/promiseChunks.js +6 -10
- package/util/server.js +4 -11
- package/util/sleep.js +1 -5
- package/webWorker/index.js +1 -4
- package/xml/getXml.js +3 -7
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadData = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Load data into a given table using Google Cloud Storage.
|
|
6
3
|
*/
|
|
7
|
-
const loadData = async ({ file, googleBigQueryClient, googleCloudStorageClient, table }) => {
|
|
4
|
+
export const loadData = async ({ file, googleBigQueryClient, googleCloudStorageClient, table }) => {
|
|
8
5
|
const tableExists = await googleBigQueryClient.tableExists(table.datasetId, table.tableId);
|
|
9
6
|
if (tableExists) {
|
|
10
7
|
await googleBigQueryClient.client
|
|
@@ -15,4 +12,3 @@ const loadData = async ({ file, googleBigQueryClient, googleCloudStorageClient,
|
|
|
15
12
|
.file(file.key), file.metadata);
|
|
16
13
|
}
|
|
17
14
|
};
|
|
18
|
-
exports.loadData = loadData;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.loadData = exports.getHandlerPath = exports.googleBigQueryClient = void 0;
|
|
4
|
-
const GoogleBigQueryNamespace_1 = require("./GoogleBigQueryNamespace");
|
|
5
|
-
const server_1 = require("../../onePassword/server");
|
|
1
|
+
import { GoogleBigQueryNamespace } from "./GoogleBigQueryNamespace";
|
|
2
|
+
import { onePasswordClient } from "../../onePassword/server";
|
|
6
3
|
const googleBigQueryNamespaces = new Map();
|
|
7
|
-
const googleBigQueryClient = async (key = "default", projectId, config, vaultId, itemId) => {
|
|
4
|
+
export const googleBigQueryClient = async (key = "default", projectId, config, vaultId, itemId) => {
|
|
8
5
|
if (googleBigQueryNamespaces.has(key)) {
|
|
9
6
|
return googleBigQueryNamespaces.get(key);
|
|
10
7
|
}
|
|
@@ -16,7 +13,7 @@ const googleBigQueryClient = async (key = "default", projectId, config, vaultId,
|
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
else if (vaultId && itemId) {
|
|
19
|
-
const onePasswordConfig = await (await
|
|
16
|
+
const onePasswordConfig = await (await onePasswordClient())
|
|
20
17
|
.getJsonNote(vaultId, itemId);
|
|
21
18
|
instanceConfig = {
|
|
22
19
|
...onePasswordConfig,
|
|
@@ -24,7 +21,7 @@ const googleBigQueryClient = async (key = "default", projectId, config, vaultId,
|
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
23
|
else if (process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
|
|
27
|
-
const onePasswordConfig = await (await
|
|
24
|
+
const onePasswordConfig = await (await onePasswordClient())
|
|
28
25
|
.getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
|
|
29
26
|
instanceConfig = {
|
|
30
27
|
...onePasswordConfig,
|
|
@@ -34,15 +31,12 @@ const googleBigQueryClient = async (key = "default", projectId, config, vaultId,
|
|
|
34
31
|
else {
|
|
35
32
|
throw new Error(`Config required for namespace '${key}'`);
|
|
36
33
|
}
|
|
37
|
-
const namespace = new
|
|
34
|
+
const namespace = new GoogleBigQueryNamespace(key, instanceConfig);
|
|
38
35
|
googleBigQueryNamespaces.set(key, namespace);
|
|
39
36
|
return namespace;
|
|
40
37
|
};
|
|
41
|
-
|
|
42
|
-
const getHandlerPath = (input) => {
|
|
38
|
+
export const getHandlerPath = (input) => {
|
|
43
39
|
return `${input.split(process.cwd())[1].substring(1)
|
|
44
40
|
.replace(/\\/g, "/")}`;
|
|
45
41
|
};
|
|
46
|
-
|
|
47
|
-
var loadData_1 = require("./loadData");
|
|
48
|
-
Object.defineProperty(exports, "loadData", { enumerable: true, get: function () { return loadData_1.loadData; } });
|
|
42
|
+
export { loadData } from "./loadData";
|
package/google/server.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfig = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Using the response from Parameter Store and format it ready to be used with Google API.
|
|
6
3
|
*/
|
|
7
|
-
const getConfig = (parameter, projectId) => {
|
|
4
|
+
export const getConfig = (parameter, projectId) => {
|
|
8
5
|
// Format the private key to be in the same format as required by Google
|
|
9
6
|
const privateKey = parameter["private_key"].replace(/\\n/g, "\n");
|
|
10
7
|
let response = {
|
|
@@ -26,4 +23,3 @@ const getConfig = (parameter, projectId) => {
|
|
|
26
23
|
}
|
|
27
24
|
return response;
|
|
28
25
|
};
|
|
29
|
-
exports.getConfig = getConfig;
|
|
@@ -1,77 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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);
|
|
1
|
+
import { BaseNamespace } from "../../_class";
|
|
2
|
+
import { getConfig } from "../server";
|
|
3
|
+
export class GoogleSheetsNamespace extends BaseNamespace {
|
|
4
|
+
ensureInit = async () => {
|
|
5
|
+
if (!this.client) {
|
|
6
|
+
try {
|
|
7
|
+
const googleApisSheets = await import("@googleapis/sheets");
|
|
8
|
+
const formattedConfig = getConfig(this.config, this.config?.projectId);
|
|
9
|
+
this.client = new googleApisSheets.auth.GoogleAuth({
|
|
10
|
+
...formattedConfig,
|
|
11
|
+
scopes: [
|
|
12
|
+
"https://www.googleapis.com/auth/spreadsheets",
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
throw new Error("Google Sheets Client not installed");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
26
20
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
getBatchData = async (props) => {
|
|
22
|
+
await this.ensureInit();
|
|
23
|
+
const googleApisSheets = await import("@googleapis/sheets");
|
|
24
|
+
// Make the API request
|
|
25
|
+
const apiResponse = await googleApisSheets.sheets("v4")
|
|
26
|
+
.spreadsheets
|
|
27
|
+
.values
|
|
28
|
+
.batchGet({
|
|
29
|
+
auth: this.client,
|
|
30
|
+
dateTimeRenderOption: props?.dateTimeRender || "FORMATTED_STRING",
|
|
31
|
+
ranges: props.ranges,
|
|
32
|
+
spreadsheetId: props.spreadsheetId,
|
|
33
|
+
valueRenderOption: props?.valueRender || "UNFORMATTED_VALUE"
|
|
34
|
+
});
|
|
35
|
+
return apiResponse.data;
|
|
33
36
|
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.GoogleSheetsNamespace = void 0;
|
|
37
|
-
const _class_1 = require("../../_class");
|
|
38
|
-
const server_1 = require("../server");
|
|
39
|
-
class GoogleSheetsNamespace extends _class_1.BaseNamespace {
|
|
40
|
-
constructor() {
|
|
41
|
-
super(...arguments);
|
|
42
|
-
this.ensureInit = async () => {
|
|
43
|
-
if (!this.client) {
|
|
44
|
-
try {
|
|
45
|
-
const googleApisSheets = await Promise.resolve().then(() => __importStar(require("@googleapis/sheets")));
|
|
46
|
-
const formattedConfig = (0, server_1.getConfig)(this.config, this.config?.projectId);
|
|
47
|
-
this.client = new googleApisSheets.auth.GoogleAuth({
|
|
48
|
-
...formattedConfig,
|
|
49
|
-
scopes: [
|
|
50
|
-
"https://www.googleapis.com/auth/spreadsheets",
|
|
51
|
-
],
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
throw new Error("Google Sheets Client not installed");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
this.getBatchData = async (props) => {
|
|
60
|
-
await this.ensureInit();
|
|
61
|
-
const googleApisSheets = await Promise.resolve().then(() => __importStar(require("@googleapis/sheets")));
|
|
62
|
-
// Make the API request
|
|
63
|
-
const apiResponse = await googleApisSheets.sheets("v4")
|
|
64
|
-
.spreadsheets
|
|
65
|
-
.values
|
|
66
|
-
.batchGet({
|
|
67
|
-
auth: this.client,
|
|
68
|
-
dateTimeRenderOption: props?.dateTimeRender || "FORMATTED_STRING",
|
|
69
|
-
ranges: props.ranges,
|
|
70
|
-
spreadsheetId: props.spreadsheetId,
|
|
71
|
-
valueRenderOption: props?.valueRender || "UNFORMATTED_VALUE"
|
|
72
|
-
});
|
|
73
|
-
return apiResponse.data;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
37
|
}
|
|
77
|
-
exports.GoogleSheetsNamespace = GoogleSheetsNamespace;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAssociatedData = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Pass a batch request using getBatchData and format the data into a key => value object per row.
|
|
6
3
|
*/
|
|
7
|
-
const getAssociatedData = async (props) => {
|
|
4
|
+
export const getAssociatedData = async (props) => {
|
|
8
5
|
let template = [];
|
|
9
6
|
let response = [];
|
|
10
7
|
// Missing ranges or too many ranges
|
|
@@ -40,4 +37,3 @@ const getAssociatedData = async (props) => {
|
|
|
40
37
|
}
|
|
41
38
|
return response;
|
|
42
39
|
};
|
|
43
|
-
exports.getAssociatedData = getAssociatedData;
|
package/google/sheets/server.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getAssociatedData = exports.isCellNa = exports.googleSheetsAuths = void 0;
|
|
4
|
-
const GoogleSheetsNamespace_1 = require("./GoogleSheetsNamespace");
|
|
5
|
-
const server_1 = require("../../onePassword/server");
|
|
1
|
+
import { GoogleSheetsNamespace } from "./GoogleSheetsNamespace";
|
|
2
|
+
import { onePasswordClient } from "../../onePassword/server";
|
|
6
3
|
const googleSheetsNamespaces = new Map();
|
|
7
|
-
const googleSheetsAuths = async (key = "default", projectId, config, vaultId, itemId) => {
|
|
4
|
+
export const googleSheetsAuths = async (key = "default", projectId, config, vaultId, itemId) => {
|
|
8
5
|
if (googleSheetsNamespaces.has(key)) {
|
|
9
6
|
return googleSheetsNamespaces.get(key);
|
|
10
7
|
}
|
|
@@ -16,7 +13,7 @@ const googleSheetsAuths = async (key = "default", projectId, config, vaultId, it
|
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
else if (vaultId && itemId) {
|
|
19
|
-
const onePasswordConfig = await (await
|
|
16
|
+
const onePasswordConfig = await (await onePasswordClient())
|
|
20
17
|
.getJsonNote(vaultId, itemId);
|
|
21
18
|
instanceConfig = {
|
|
22
19
|
...onePasswordConfig,
|
|
@@ -24,7 +21,7 @@ const googleSheetsAuths = async (key = "default", projectId, config, vaultId, it
|
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
23
|
else if (process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
|
|
27
|
-
const onePasswordConfig = await (await
|
|
24
|
+
const onePasswordConfig = await (await onePasswordClient())
|
|
28
25
|
.getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
|
|
29
26
|
instanceConfig = {
|
|
30
27
|
...onePasswordConfig,
|
|
@@ -34,15 +31,12 @@ const googleSheetsAuths = async (key = "default", projectId, config, vaultId, it
|
|
|
34
31
|
else {
|
|
35
32
|
throw new Error(`Config required for namespace '${key}'`);
|
|
36
33
|
}
|
|
37
|
-
const namespace = new
|
|
34
|
+
const namespace = new GoogleSheetsNamespace(key, instanceConfig);
|
|
38
35
|
googleSheetsNamespaces.set(key, namespace);
|
|
39
36
|
return namespace;
|
|
40
37
|
};
|
|
41
|
-
exports.googleSheetsAuths = googleSheetsAuths;
|
|
42
38
|
/**
|
|
43
39
|
* Noticed sometimes Google Sheets can struggle with import XML resulting to N/A values.
|
|
44
40
|
*/
|
|
45
|
-
const isCellNa = (input) => "#N/A" === input;
|
|
46
|
-
|
|
47
|
-
var getAssociatedData_1 = require("./getAssociatedData");
|
|
48
|
-
Object.defineProperty(exports, "getAssociatedData", { enumerable: true, get: function () { return getAssociatedData_1.getAssociatedData; } });
|
|
41
|
+
export const isCellNa = (input) => "#N/A" === input;
|
|
42
|
+
export { getAssociatedData } from "./getAssociatedData";
|
|
@@ -1,106 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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);
|
|
1
|
+
import { BaseNamespace } from "../../_class";
|
|
2
|
+
import { getConfig } from "../server";
|
|
3
|
+
export class GoogleCloudStorageNamespace extends BaseNamespace {
|
|
4
|
+
ensureInit = async () => {
|
|
5
|
+
if (!this.client) {
|
|
6
|
+
try {
|
|
7
|
+
const { Storage } = await import("@google-cloud/storage");
|
|
8
|
+
const formattedConfig = getConfig(this.config, this.config?.projectId);
|
|
9
|
+
this.client = new Storage(formattedConfig);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
throw new Error("Google Cloud Storage Client not installed");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
26
15
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Copy a local file to Google Cloud Storage.
|
|
18
|
+
*/
|
|
19
|
+
copyToCloud = async (bucket, localFile, options = {}) => {
|
|
20
|
+
await this.ensureInit();
|
|
21
|
+
const apiResponse = await this.client
|
|
22
|
+
.bucket(bucket)
|
|
23
|
+
.upload(localFile, options);
|
|
24
|
+
return apiResponse;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.file(key)
|
|
72
|
-
.exists();
|
|
73
|
-
const response = googleFile?.[0];
|
|
74
|
-
return response;
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Write a file to Google Cloud Storage.
|
|
78
|
-
*/
|
|
79
|
-
this.writeFile = async (bucket, key, data, options = {}) => {
|
|
80
|
-
await this.ensureInit();
|
|
81
|
-
const stream = await Promise.resolve().then(() => __importStar(require("stream")));
|
|
82
|
-
const dataStream = new stream.PassThrough();
|
|
83
|
-
const googleFile = this.client
|
|
84
|
-
.bucket(bucket)
|
|
85
|
-
.file(key);
|
|
86
|
-
dataStream.push(data);
|
|
87
|
-
dataStream.push(null);
|
|
88
|
-
return await new Promise((resolve, reject) => {
|
|
89
|
-
dataStream.pipe(googleFile.createWriteStream({
|
|
90
|
-
contentType: "auto",
|
|
91
|
-
resumable: false,
|
|
92
|
-
validation: false,
|
|
93
|
-
metadata: {},
|
|
94
|
-
...options,
|
|
95
|
-
}))
|
|
96
|
-
.on("error", (error) => {
|
|
97
|
-
reject(error);
|
|
98
|
-
})
|
|
99
|
-
.on("finish", () => {
|
|
100
|
-
resolve(true);
|
|
101
|
-
});
|
|
26
|
+
/**
|
|
27
|
+
* Check to see if a file exists but don't get the contents.
|
|
28
|
+
*/
|
|
29
|
+
fileExists = async (bucket, key) => {
|
|
30
|
+
await this.ensureInit();
|
|
31
|
+
const googleFile = await this.client
|
|
32
|
+
.bucket(bucket)
|
|
33
|
+
.file(key)
|
|
34
|
+
.exists();
|
|
35
|
+
const response = googleFile?.[0];
|
|
36
|
+
return response;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Write a file to Google Cloud Storage.
|
|
40
|
+
*/
|
|
41
|
+
writeFile = async (bucket, key, data, options = {}) => {
|
|
42
|
+
await this.ensureInit();
|
|
43
|
+
const stream = await import("stream");
|
|
44
|
+
const dataStream = new stream.PassThrough();
|
|
45
|
+
const googleFile = this.client
|
|
46
|
+
.bucket(bucket)
|
|
47
|
+
.file(key);
|
|
48
|
+
dataStream.push(data);
|
|
49
|
+
dataStream.push(null);
|
|
50
|
+
return await new Promise((resolve, reject) => {
|
|
51
|
+
dataStream.pipe(googleFile.createWriteStream({
|
|
52
|
+
contentType: "auto",
|
|
53
|
+
resumable: false,
|
|
54
|
+
validation: false,
|
|
55
|
+
metadata: {},
|
|
56
|
+
...options,
|
|
57
|
+
}))
|
|
58
|
+
.on("error", (error) => {
|
|
59
|
+
reject(error);
|
|
60
|
+
})
|
|
61
|
+
.on("finish", () => {
|
|
62
|
+
resolve(true);
|
|
102
63
|
});
|
|
103
|
-
};
|
|
104
|
-
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
105
66
|
}
|
|
106
|
-
exports.GoogleCloudStorageNamespace = GoogleCloudStorageNamespace;
|
package/google/storage/server.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.googleCloudStorageClient = void 0;
|
|
4
|
-
const GoogleCloudStorageNamespace_1 = require("./GoogleCloudStorageNamespace");
|
|
5
|
-
const server_1 = require("../../onePassword/server");
|
|
1
|
+
import { GoogleCloudStorageNamespace } from "./GoogleCloudStorageNamespace";
|
|
2
|
+
import { onePasswordClient } from "../../onePassword/server";
|
|
6
3
|
const googleCloudStorageNamespaces = new Map();
|
|
7
|
-
const googleCloudStorageClient = async (key = "default", projectId, config, vaultId, itemId) => {
|
|
4
|
+
export const googleCloudStorageClient = async (key = "default", projectId, config, vaultId, itemId) => {
|
|
8
5
|
if (googleCloudStorageNamespaces.has(key)) {
|
|
9
6
|
return googleCloudStorageNamespaces.get(key);
|
|
10
7
|
}
|
|
@@ -16,7 +13,7 @@ const googleCloudStorageClient = async (key = "default", projectId, config, vaul
|
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
else if (vaultId && itemId) {
|
|
19
|
-
const onePasswordConfig = await (await
|
|
16
|
+
const onePasswordConfig = await (await onePasswordClient())
|
|
20
17
|
.getJsonNote(vaultId, itemId);
|
|
21
18
|
instanceConfig = {
|
|
22
19
|
...onePasswordConfig,
|
|
@@ -24,7 +21,7 @@ const googleCloudStorageClient = async (key = "default", projectId, config, vaul
|
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
23
|
else if (process.env.GOOGLE_CLOUD_VAULT_ID && process.env.GOOGLE_CLOUD_ITEM_ID) {
|
|
27
|
-
const onePasswordConfig = await (await
|
|
24
|
+
const onePasswordConfig = await (await onePasswordClient())
|
|
28
25
|
.getJsonNote(process.env.GOOGLE_CLOUD_VAULT_ID, process.env.GOOGLE_CLOUD_ITEM_ID);
|
|
29
26
|
instanceConfig = {
|
|
30
27
|
...onePasswordConfig,
|
|
@@ -34,8 +31,7 @@ const googleCloudStorageClient = async (key = "default", projectId, config, vaul
|
|
|
34
31
|
else {
|
|
35
32
|
throw new Error(`Config required for namespace '${key}'`);
|
|
36
33
|
}
|
|
37
|
-
const namespace = new
|
|
34
|
+
const namespace = new GoogleCloudStorageNamespace(key, instanceConfig);
|
|
38
35
|
googleCloudStorageNamespaces.set(key, namespace);
|
|
39
36
|
return namespace;
|
|
40
37
|
};
|
|
41
|
-
exports.googleCloudStorageClient = googleCloudStorageClient;
|
|
@@ -1,71 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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);
|
|
1
|
+
import { BaseNamespace } from "../_class";
|
|
2
|
+
export class GoogleAdsNamespace extends BaseNamespace {
|
|
3
|
+
mccAccountId = "";
|
|
4
|
+
refreshToken = "";
|
|
5
|
+
ensureInit = async () => {
|
|
6
|
+
if (!this.client) {
|
|
7
|
+
try {
|
|
8
|
+
const { GoogleAdsApi } = await import("google-ads-api");
|
|
9
|
+
this.client = new GoogleAdsApi({
|
|
10
|
+
client_id: this.config.client.clientId,
|
|
11
|
+
client_secret: this.config.client.clientSecret,
|
|
12
|
+
developer_token: this.config.client.developerToken,
|
|
13
|
+
});
|
|
14
|
+
this.mccAccountId = this.config.mccAccountId;
|
|
15
|
+
this.refreshToken = this.config.refreshToken;
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
throw new Error("Google Sheets Client not installed");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
26
21
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
getCustomer = async (customerId) => {
|
|
23
|
+
await this.ensureInit();
|
|
24
|
+
const customer = this.client.Customer({
|
|
25
|
+
customer_id: customerId,
|
|
26
|
+
login_customer_id: global.googleAdsClient.mccAccountId,
|
|
27
|
+
refresh_token: global.googleAdsClient.refreshToken,
|
|
28
|
+
});
|
|
29
|
+
return customer;
|
|
33
30
|
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.GoogleAdsNamespace = void 0;
|
|
37
|
-
const _class_1 = require("../_class");
|
|
38
|
-
class GoogleAdsNamespace extends _class_1.BaseNamespace {
|
|
39
|
-
constructor() {
|
|
40
|
-
super(...arguments);
|
|
41
|
-
this.mccAccountId = "";
|
|
42
|
-
this.refreshToken = "";
|
|
43
|
-
this.ensureInit = async () => {
|
|
44
|
-
if (!this.client) {
|
|
45
|
-
try {
|
|
46
|
-
const { GoogleAdsApi } = await Promise.resolve().then(() => __importStar(require("google-ads-api")));
|
|
47
|
-
this.client = new GoogleAdsApi({
|
|
48
|
-
client_id: this.config.client.clientId,
|
|
49
|
-
client_secret: this.config.client.clientSecret,
|
|
50
|
-
developer_token: this.config.client.developerToken,
|
|
51
|
-
});
|
|
52
|
-
this.mccAccountId = this.config.mccAccountId;
|
|
53
|
-
this.refreshToken = this.config.refreshToken;
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
throw new Error("Google Sheets Client not installed");
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
this.getCustomer = async (customerId) => {
|
|
61
|
-
await this.ensureInit();
|
|
62
|
-
const customer = this.client.Customer({
|
|
63
|
-
customer_id: customerId,
|
|
64
|
-
login_customer_id: global.googleAdsClient.mccAccountId,
|
|
65
|
-
refresh_token: global.googleAdsClient.refreshToken,
|
|
66
|
-
});
|
|
67
|
-
return customer;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
31
|
}
|
|
71
|
-
exports.GoogleAdsNamespace = GoogleAdsNamespace;
|