@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,21 @@
|
|
|
1
|
+
import { BaseNamespace } from "../../_class";
|
|
2
|
+
import { AwsConfig } from "../index";
|
|
3
|
+
import type { LambdaClient } from "@aws-sdk/client-lambda";
|
|
4
|
+
type InvokeProps = {
|
|
5
|
+
awaitResponse?: boolean;
|
|
6
|
+
functionName: string;
|
|
7
|
+
isJson?: boolean;
|
|
8
|
+
payload?: object;
|
|
9
|
+
};
|
|
10
|
+
export declare class AwsLambdaNamespace extends BaseNamespace {
|
|
11
|
+
client: LambdaClient | null;
|
|
12
|
+
config: AwsConfig;
|
|
13
|
+
ensureInit: () => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Invoke a AWS Lambda function by passing in the Function name and optional Payload data.
|
|
16
|
+
* Runs asynchronously, doesn't wait for function to fully end.
|
|
17
|
+
* Library: @aws-sdk/client-lambda
|
|
18
|
+
*/
|
|
19
|
+
invoke: (props: InvokeProps) => Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
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.AwsLambdaNamespace = void 0;
|
|
37
|
+
const _class_1 = require("../../_class");
|
|
38
|
+
const __1 = require("../");
|
|
39
|
+
const api_1 = require("../../api");
|
|
40
|
+
class AwsLambdaNamespace extends _class_1.BaseNamespace {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.client = null;
|
|
44
|
+
this.ensureInit = async () => {
|
|
45
|
+
if (!this.client) {
|
|
46
|
+
try {
|
|
47
|
+
const { LambdaClient } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-lambda")));
|
|
48
|
+
this.client = new LambdaClient(this.config);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
throw new Error("AWS Lambda Client not installed");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Invoke a AWS Lambda function by passing in the Function name and optional Payload data.
|
|
57
|
+
* Runs asynchronously, doesn't wait for function to fully end.
|
|
58
|
+
* Library: @aws-sdk/client-lambda
|
|
59
|
+
*/
|
|
60
|
+
this.invoke = async (props) => {
|
|
61
|
+
await this.ensureInit();
|
|
62
|
+
const { InvokeCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-lambda")));
|
|
63
|
+
let response = false;
|
|
64
|
+
const params = {
|
|
65
|
+
FunctionName: props.functionName,
|
|
66
|
+
InvocationType: true === props.awaitResponse ? "RequestResponse" : "Event",
|
|
67
|
+
};
|
|
68
|
+
// Payload is defined add to parameters
|
|
69
|
+
if (undefined !== props.payload) {
|
|
70
|
+
params["Payload"] = new Uint8Array(Buffer.from(JSON.stringify(props.payload)));
|
|
71
|
+
}
|
|
72
|
+
// Create the Lambda Command
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
const command = new InvokeCommand(params);
|
|
75
|
+
// Fire the event but don't wait for it to complete
|
|
76
|
+
const apiResponse = await this.client.send(command);
|
|
77
|
+
// Success
|
|
78
|
+
if ((0, __1.isResponse200)(apiResponse)) {
|
|
79
|
+
// Return the data
|
|
80
|
+
if (props.awaitResponse && undefined !== apiResponse.Payload) {
|
|
81
|
+
const asciiDecoder = new TextDecoder("ascii");
|
|
82
|
+
response = asciiDecoder.decode(apiResponse.Payload);
|
|
83
|
+
// Decode string as JSON object
|
|
84
|
+
if (true === props.isJson) {
|
|
85
|
+
response = JSON.parse(response);
|
|
86
|
+
// If it's still a string, double decode it
|
|
87
|
+
if ("string" === typeof response) {
|
|
88
|
+
response = JSON.parse(response);
|
|
89
|
+
}
|
|
90
|
+
// If the response is a ApiResponse compatible
|
|
91
|
+
if (undefined !== response &&
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
undefined !== response?.error &&
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
undefined !== response?.state) {
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
response = (new api_1.ApiResponseClass()).fromJson(response);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Success but not waiting for response
|
|
102
|
+
else {
|
|
103
|
+
response = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return response;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.AwsLambdaNamespace = AwsLambdaNamespace;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AwsLambdaNamespace } from "./AwsLambdaNamespace";
|
|
2
|
+
import { AwsConfig } from "../index";
|
|
3
|
+
export declare const awsLambdaClient: (key?: string, config?: AwsConfig, vaultId?: string, itemId?: string) => Promise<AwsLambdaNamespace>;
|
|
4
|
+
export declare const getHandlerPath: (input: string) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHandlerPath = exports.awsLambdaClient = void 0;
|
|
4
|
+
const AwsLambdaNamespace_1 = require("./AwsLambdaNamespace");
|
|
5
|
+
const index_1 = require("../index");
|
|
6
|
+
const awsLambdaNamespaces = new Map();
|
|
7
|
+
const awsLambdaClient = async (key = "default", config, vaultId, itemId) => {
|
|
8
|
+
if (awsLambdaNamespaces.has(key)) {
|
|
9
|
+
return awsLambdaNamespaces.get(key);
|
|
10
|
+
}
|
|
11
|
+
const instanceConfig = await (0, index_1.getConfig)(key, config, vaultId, itemId);
|
|
12
|
+
const namespace = new AwsLambdaNamespace_1.AwsLambdaNamespace(key, instanceConfig);
|
|
13
|
+
awsLambdaNamespaces.set(key, namespace);
|
|
14
|
+
return namespace;
|
|
15
|
+
};
|
|
16
|
+
exports.awsLambdaClient = awsLambdaClient;
|
|
17
|
+
const getHandlerPath = (input) => {
|
|
18
|
+
return `${input.split(process.cwd())[1].substring(1)
|
|
19
|
+
.replace(/\\/g, "/")}`;
|
|
20
|
+
};
|
|
21
|
+
exports.getHandlerPath = getHandlerPath;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BaseNamespace } from "../../_class";
|
|
2
|
+
import { AwsConfig } from "../index";
|
|
3
|
+
import type { S3Client } from "@aws-sdk/client-s3";
|
|
4
|
+
import { Modified, ReadFileResponse } from "./index";
|
|
5
|
+
export type ReadBufferResponse = Modified & {
|
|
6
|
+
buffer: any;
|
|
7
|
+
};
|
|
8
|
+
type Options = {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
11
|
+
type WritePresignedPostProps = {
|
|
12
|
+
bucket: string;
|
|
13
|
+
fields: any;
|
|
14
|
+
file: any;
|
|
15
|
+
key: string;
|
|
16
|
+
url: string;
|
|
17
|
+
};
|
|
18
|
+
export declare class AwsS3Namespace extends BaseNamespace {
|
|
19
|
+
client: S3Client | null;
|
|
20
|
+
config: AwsConfig;
|
|
21
|
+
ensureInit: () => Promise<void>;
|
|
22
|
+
copy: (fromBucket: string, fromKey: string, toBucket: string, toKey: string) => Promise<void>;
|
|
23
|
+
deleteFile: (bucket: string, key: string) => Promise<void>;
|
|
24
|
+
deleteFiles: (bucket: string, keys: string[]) => Promise<void>;
|
|
25
|
+
deleteFolder: (bucket: string, folder: string) => Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* List the files in the given bucket and option folder
|
|
28
|
+
*/
|
|
29
|
+
listFiles: (bucket: string, folder?: string) => Promise<string[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Fetch all the files within a given directory recursively
|
|
32
|
+
*/
|
|
33
|
+
filesIteratively: (bucket: string, folder: string) => Promise<string[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Sub function
|
|
36
|
+
*/
|
|
37
|
+
private iterateFolders;
|
|
38
|
+
/**
|
|
39
|
+
* List the files in the given bucket and option folder.
|
|
40
|
+
*/
|
|
41
|
+
listFolders: (bucket: string, folder: string) => Promise<string[]>;
|
|
42
|
+
move: (fromBucket: string, fromKey: string, toBucket: string, toKey: string) => Promise<void>;
|
|
43
|
+
readBrotli: (bucket: string, key: string, isJson?: boolean) => Promise<ReadFileResponse>;
|
|
44
|
+
readBuffer: (bucket: string, key: string) => Promise<ReadBufferResponse>;
|
|
45
|
+
fileExists: (bucket: string, key: string) => Promise<boolean>;
|
|
46
|
+
readFile: (bucket: string, key: string, isJson?: boolean) => Promise<ReadFileResponse>;
|
|
47
|
+
readGzip: (bucket: string, key: string, isJson?: boolean) => Promise<ReadFileResponse>;
|
|
48
|
+
writeBrotli: (bucket: string, key: string, data: any, isJson?: boolean, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
49
|
+
writeFile: (bucket: string, key: string, data: any, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
50
|
+
writeGzip: (bucket: string, key: string, data: any, isJson?: boolean, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
51
|
+
/**
|
|
52
|
+
* Get a presigned post URL so we can upload directly to S3 via frontend.
|
|
53
|
+
*/
|
|
54
|
+
presignedPost: (props: WritePresignedPostProps) => Promise<null | string>;
|
|
55
|
+
/**
|
|
56
|
+
* Download a file and write to S3.
|
|
57
|
+
*/
|
|
58
|
+
urlContents: (bucket: string, key: string, url: string) => Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,401 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.AwsS3Namespace = void 0;
|
|
40
|
+
const _class_1 = require("../../_class");
|
|
41
|
+
const index_1 = require("../index");
|
|
42
|
+
const string_1 = require("../../string");
|
|
43
|
+
const util_1 = require("../../util");
|
|
44
|
+
const index_2 = require("./index");
|
|
45
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
46
|
+
const date_1 = require("../../date");
|
|
47
|
+
const axios_1 = __importDefault(require("axios"));
|
|
48
|
+
class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(...arguments);
|
|
51
|
+
this.client = null;
|
|
52
|
+
this.ensureInit = async () => {
|
|
53
|
+
if (!this.client) {
|
|
54
|
+
try {
|
|
55
|
+
const { S3Client } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
56
|
+
this.client = new S3Client(this.config);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw new Error("AWS S3 Client not installed");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
this.copy = async (fromBucket, fromKey, toBucket, toKey) => {
|
|
64
|
+
await this.ensureInit();
|
|
65
|
+
const { CopyObjectCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
66
|
+
await this.client.send(new CopyObjectCommand({
|
|
67
|
+
Bucket: toBucket,
|
|
68
|
+
CopySource: encodeURIComponent(`${fromBucket}/${fromKey}`),
|
|
69
|
+
Key: toKey,
|
|
70
|
+
}));
|
|
71
|
+
};
|
|
72
|
+
this.deleteFile = async (bucket, key) => {
|
|
73
|
+
await this.ensureInit();
|
|
74
|
+
const { DeleteObjectCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
75
|
+
await this.client.send(new DeleteObjectCommand({
|
|
76
|
+
Bucket: bucket,
|
|
77
|
+
Key: key,
|
|
78
|
+
}));
|
|
79
|
+
};
|
|
80
|
+
this.deleteFiles = async (bucket, keys) => {
|
|
81
|
+
await this.ensureInit();
|
|
82
|
+
const { DeleteObjectsCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
83
|
+
await this.client.send(new DeleteObjectsCommand({
|
|
84
|
+
Bucket: bucket,
|
|
85
|
+
Delete: {
|
|
86
|
+
Objects: keys.map(key => ({
|
|
87
|
+
Key: key,
|
|
88
|
+
})),
|
|
89
|
+
},
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
this.deleteFolder = async (bucket, folder) => {
|
|
93
|
+
await this.ensureInit();
|
|
94
|
+
const { ListObjectsV2Command, DeleteObjectsCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
95
|
+
const cleanFolder = (0, string_1.getFolder)(folder);
|
|
96
|
+
// Get a list of all files to be deleted
|
|
97
|
+
const apiResponse = await this.client.send(new ListObjectsV2Command({
|
|
98
|
+
Bucket: bucket,
|
|
99
|
+
Prefix: ("" === cleanFolder ? "" : cleanFolder + "/"),
|
|
100
|
+
}));
|
|
101
|
+
// No files to be deleted
|
|
102
|
+
if (apiResponse.Contents.length === 0) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// Map each of the files
|
|
106
|
+
const keys = apiResponse.Contents.map(file => ({ Key: file.Key }));
|
|
107
|
+
// Delete the files
|
|
108
|
+
await this.client.send(new DeleteObjectsCommand({
|
|
109
|
+
Bucket: bucket,
|
|
110
|
+
Delete: {
|
|
111
|
+
Objects: keys,
|
|
112
|
+
},
|
|
113
|
+
}));
|
|
114
|
+
// If we didn't get all files, run it again
|
|
115
|
+
if (apiResponse.IsTruncated) {
|
|
116
|
+
await this.deleteFolder(bucket, folder);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* List the files in the given bucket and option folder
|
|
121
|
+
*/
|
|
122
|
+
this.listFiles = async (bucket, folder = "") => {
|
|
123
|
+
await this.ensureInit();
|
|
124
|
+
const { ListObjectsV2Command } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
125
|
+
const cleanFolder = (0, string_1.getFolder)(folder);
|
|
126
|
+
let response = [];
|
|
127
|
+
let valid = [];
|
|
128
|
+
const apiResponse = await this.client.send(new ListObjectsV2Command({
|
|
129
|
+
Bucket: bucket,
|
|
130
|
+
Delimiter: "/",
|
|
131
|
+
Prefix: ("" === cleanFolder ? "" : cleanFolder + "/"),
|
|
132
|
+
}));
|
|
133
|
+
// Ensure the data exists
|
|
134
|
+
if (undefined !== apiResponse["Contents"]) {
|
|
135
|
+
// Return an array of files
|
|
136
|
+
valid = apiResponse["Contents"].filter(content => {
|
|
137
|
+
const keyExploded = content["Key"].split("/");
|
|
138
|
+
return keyExploded[keyExploded.length - 1].indexOf(".") > -1;
|
|
139
|
+
});
|
|
140
|
+
if (valid.length) {
|
|
141
|
+
response = valid.map(entry => entry["Key"]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return response;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Fetch all the files within a given directory recursively
|
|
148
|
+
*/
|
|
149
|
+
this.filesIteratively = async (bucket, folder) => {
|
|
150
|
+
await this.ensureInit();
|
|
151
|
+
const response = await this.iterateFolders(bucket, folder);
|
|
152
|
+
return response;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Sub function
|
|
156
|
+
*/
|
|
157
|
+
this.iterateFolders = async (bucket, folder) => {
|
|
158
|
+
let response = [];
|
|
159
|
+
const folders = await this.listFolders(bucket, folder);
|
|
160
|
+
for (let i = 0; i < folders.length; i++) {
|
|
161
|
+
const subFolderFiles = await this.listFolders(bucket, `${folder}/${folders[i]}`);
|
|
162
|
+
const files = await this.listFiles(bucket, `${folder}/${folders[i]}`);
|
|
163
|
+
response = [
|
|
164
|
+
...response,
|
|
165
|
+
...files,
|
|
166
|
+
...subFolderFiles,
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
return response;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* List the files in the given bucket and option folder.
|
|
173
|
+
*/
|
|
174
|
+
this.listFolders = async (bucket, folder) => {
|
|
175
|
+
await this.ensureInit();
|
|
176
|
+
const { ListObjectsV2Command } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
177
|
+
const cleanFolder = (0, string_1.getFolder)(folder);
|
|
178
|
+
let response = [];
|
|
179
|
+
const apiResponse = await this.client.send(new ListObjectsV2Command({
|
|
180
|
+
Bucket: bucket,
|
|
181
|
+
Delimiter: "/",
|
|
182
|
+
Prefix: ("" === cleanFolder ? "" : cleanFolder + "/"),
|
|
183
|
+
}));
|
|
184
|
+
// Ensure the data exists
|
|
185
|
+
if (undefined !== apiResponse["CommonPrefixes"]) {
|
|
186
|
+
// Return an array of folders removing the trailing folder
|
|
187
|
+
response = apiResponse["CommonPrefixes"].map(prefix => {
|
|
188
|
+
// Remove the trailing slash then split by slash
|
|
189
|
+
const fileFolders = prefix.Prefix.slice(0, -1)
|
|
190
|
+
.split("/");
|
|
191
|
+
// Return the last folder without a trailing slash
|
|
192
|
+
return fileFolders[fileFolders.length - 1];
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return response;
|
|
196
|
+
};
|
|
197
|
+
this.move = async (fromBucket, fromKey, toBucket, toKey) => {
|
|
198
|
+
await this.ensureInit();
|
|
199
|
+
const { CopyObjectCommand, DeleteObjectCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
200
|
+
await this.client.send(new CopyObjectCommand({
|
|
201
|
+
Bucket: toBucket,
|
|
202
|
+
CopySource: encodeURIComponent(`${fromBucket}/${fromKey}`),
|
|
203
|
+
Key: toKey,
|
|
204
|
+
}));
|
|
205
|
+
await this.client.send(new DeleteObjectCommand({
|
|
206
|
+
Bucket: fromBucket,
|
|
207
|
+
Key: fromKey,
|
|
208
|
+
}));
|
|
209
|
+
};
|
|
210
|
+
this.readBrotli = async (bucket, key, isJson = true) => {
|
|
211
|
+
await this.ensureInit();
|
|
212
|
+
let response = await this.readFile(bucket, key, isJson);
|
|
213
|
+
// Cache exists and is still within our caching timeframe
|
|
214
|
+
if (undefined !== response.body) {
|
|
215
|
+
response.body = await (0, util_1.getBrotliDecompressed)(response.body);
|
|
216
|
+
if (false !== isJson) {
|
|
217
|
+
response.body = JSON.parse(response.body);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return response;
|
|
221
|
+
};
|
|
222
|
+
this.readBuffer = async (bucket, key) => {
|
|
223
|
+
await this.ensureInit();
|
|
224
|
+
const { GetObjectCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
225
|
+
let response = {
|
|
226
|
+
...index_2.readFileDefault,
|
|
227
|
+
buffer: undefined,
|
|
228
|
+
};
|
|
229
|
+
const apiResponse = await this.client.send(new GetObjectCommand({
|
|
230
|
+
Bucket: bucket,
|
|
231
|
+
Key: key,
|
|
232
|
+
}));
|
|
233
|
+
if ((0, index_1.isResponse200)(apiResponse)) {
|
|
234
|
+
const chunks = [];
|
|
235
|
+
// Store the response
|
|
236
|
+
response.buffer = await new Promise((resolve, reject) => {
|
|
237
|
+
// @ts-ignore
|
|
238
|
+
apiResponse.Body.on("data", (chunk) => chunks.push(chunk));
|
|
239
|
+
// @ts-ignore
|
|
240
|
+
apiResponse.Body.on("error", (err) => reject(err));
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
apiResponse.Body.on("end", () => resolve(Buffer.concat(chunks)));
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
throw new Error("Error reading file.");
|
|
247
|
+
}
|
|
248
|
+
return response;
|
|
249
|
+
};
|
|
250
|
+
this.fileExists = async (bucket, key) => {
|
|
251
|
+
await this.ensureInit();
|
|
252
|
+
let response = false;
|
|
253
|
+
try {
|
|
254
|
+
const { HeadObjectCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
255
|
+
// Fetch from S3
|
|
256
|
+
const apiResponse = await this.client.send(new HeadObjectCommand({
|
|
257
|
+
Bucket: bucket,
|
|
258
|
+
Key: key,
|
|
259
|
+
}));
|
|
260
|
+
// If the status is 200 then it does exist
|
|
261
|
+
response = (0, index_1.isResponse200)(apiResponse);
|
|
262
|
+
}
|
|
263
|
+
catch (exception) {
|
|
264
|
+
response = false;
|
|
265
|
+
}
|
|
266
|
+
return response;
|
|
267
|
+
};
|
|
268
|
+
this.readFile = async (bucket, key, isJson = true) => {
|
|
269
|
+
await this.ensureInit();
|
|
270
|
+
let response = (0, cloneDeep_1.default)(index_2.readFileDefault);
|
|
271
|
+
const today = (0, date_1.getToday)();
|
|
272
|
+
const midnight = (0, date_1.getToday)(true);
|
|
273
|
+
try {
|
|
274
|
+
response.now = today.toUnixInteger();
|
|
275
|
+
const { GetObjectCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
276
|
+
//console.log('GetObjectCommand', GetObjectCommand);
|
|
277
|
+
const apiResponse = await this.client.send(new GetObjectCommand({
|
|
278
|
+
Bucket: bucket,
|
|
279
|
+
Key: key,
|
|
280
|
+
}));
|
|
281
|
+
//console.log('apiResponse', apiResponse);
|
|
282
|
+
if ((0, index_1.isResponse200)(apiResponse)) {
|
|
283
|
+
let modified = (0, date_1.getDate)(apiResponse.LastModified);
|
|
284
|
+
// Convert the date to unix
|
|
285
|
+
response.modified.unix = modified.toUnixInteger();
|
|
286
|
+
// Compare now to unix
|
|
287
|
+
response.modified.vs_now.months = today.diff(modified, 'months').months;
|
|
288
|
+
response.modified.vs_now.days = today.diff(modified, 'days').days;
|
|
289
|
+
response.modified.vs_now.hours = today.diff(modified, 'hours').hours;
|
|
290
|
+
response.modified.vs_now.minutes = today.diff(modified, 'minutes').minutes;
|
|
291
|
+
// Compare now to midnight
|
|
292
|
+
response.modified.vs_midnight.hours = today.diff(midnight, 'hours').hours;
|
|
293
|
+
response.modified.vs_midnight.minutes = today.diff(midnight, 'minutes').hours;
|
|
294
|
+
// Convert stream into a string
|
|
295
|
+
response.body = await (0, string_1.getStringFromStream)(apiResponse.Body);
|
|
296
|
+
// If we need to return JSON, parse it. On error return undefined
|
|
297
|
+
if (false !== isJson) {
|
|
298
|
+
response.body = JSON.parse(response.body) || null;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
response.body = null;
|
|
304
|
+
response.error = error;
|
|
305
|
+
}
|
|
306
|
+
return response;
|
|
307
|
+
};
|
|
308
|
+
this.readGzip = async (bucket, key, isJson = true) => {
|
|
309
|
+
await this.ensureInit();
|
|
310
|
+
let response = await this.readFile(bucket, key, isJson);
|
|
311
|
+
// Cache exists and is still within our caching timeframe
|
|
312
|
+
if (undefined !== response.body) {
|
|
313
|
+
response.body = await (0, util_1.getGzipDecompressed)(response.body);
|
|
314
|
+
if (false !== isJson) {
|
|
315
|
+
response.body = JSON.parse(response.body);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return response;
|
|
319
|
+
};
|
|
320
|
+
this.writeBrotli = async (bucket, key, data, isJson = true, options = {}) => {
|
|
321
|
+
await this.ensureInit();
|
|
322
|
+
let finalData = data;
|
|
323
|
+
if (false !== isJson) {
|
|
324
|
+
finalData = JSON.stringify(data);
|
|
325
|
+
}
|
|
326
|
+
// Compress the data
|
|
327
|
+
const brotliData = await (0, util_1.getBrotliCompressed)({
|
|
328
|
+
input: finalData,
|
|
329
|
+
});
|
|
330
|
+
const apiResponse = await this.writeFile(bucket, key, brotliData, options);
|
|
331
|
+
return apiResponse;
|
|
332
|
+
};
|
|
333
|
+
this.writeFile = async (bucket, key, data, options = {}) => {
|
|
334
|
+
await this.ensureInit();
|
|
335
|
+
const { PutObjectCommand } = await Promise.resolve().then(() => __importStar(require("@aws-sdk/client-s3")));
|
|
336
|
+
const apiResponse = await this.client.send(new PutObjectCommand({
|
|
337
|
+
Bucket: bucket,
|
|
338
|
+
Body: data,
|
|
339
|
+
Key: key,
|
|
340
|
+
...options,
|
|
341
|
+
}));
|
|
342
|
+
return apiResponse;
|
|
343
|
+
};
|
|
344
|
+
this.writeGzip = async (bucket, key, data, isJson = true, options = {}) => {
|
|
345
|
+
await this.ensureInit();
|
|
346
|
+
let finalData = data;
|
|
347
|
+
if (false !== isJson) {
|
|
348
|
+
finalData = JSON.stringify(data);
|
|
349
|
+
}
|
|
350
|
+
// Compress the data
|
|
351
|
+
const gzipData = await (0, util_1.getGzipCompressed)(finalData);
|
|
352
|
+
const apiResponse = await this.writeFile(bucket, key, gzipData, options);
|
|
353
|
+
return apiResponse;
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Get a presigned post URL so we can upload directly to S3 via frontend.
|
|
357
|
+
*/
|
|
358
|
+
this.presignedPost = async (props) => {
|
|
359
|
+
await this.ensureInit();
|
|
360
|
+
return new Promise(async (resolve, reject) => {
|
|
361
|
+
let response = null;
|
|
362
|
+
const formData = new FormData();
|
|
363
|
+
Object.entries({ fields: props.fields, file: props.file })
|
|
364
|
+
.forEach(([key, value]) => {
|
|
365
|
+
formData.append(key, value);
|
|
366
|
+
});
|
|
367
|
+
const upload = await fetch(props.url, {
|
|
368
|
+
method: "POST",
|
|
369
|
+
body: formData,
|
|
370
|
+
});
|
|
371
|
+
// Uploaded to S3
|
|
372
|
+
if (upload.ok) {
|
|
373
|
+
response = `https://${props.bucket}.s3.${this.config.region}.amazonaws.com/${props.key}`;
|
|
374
|
+
resolve(response);
|
|
375
|
+
}
|
|
376
|
+
// Failed to upload to S3
|
|
377
|
+
else {
|
|
378
|
+
response = null;
|
|
379
|
+
reject(response);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* Download a file and write to S3.
|
|
385
|
+
*/
|
|
386
|
+
this.urlContents = async (bucket, key, url) => {
|
|
387
|
+
await this.ensureInit();
|
|
388
|
+
return (0, axios_1.default)(url, {
|
|
389
|
+
responseType: "arraybuffer",
|
|
390
|
+
responseEncoding: "binary",
|
|
391
|
+
})
|
|
392
|
+
.then(async (response) => {
|
|
393
|
+
await this.writeFile(bucket, response.data, key, {
|
|
394
|
+
ContentType: response.headers["content-type"],
|
|
395
|
+
ContentLength: response.headers["content-length"],
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
exports.AwsS3Namespace = AwsS3Namespace;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AwsS3Namespace } from "./AwsS3Namespace";
|
|
2
|
+
import { AwsConfig } from "../index";
|
|
3
|
+
export declare const awsS3Client: (key?: string, config?: AwsConfig, vaultId?: string, itemId?: string) => Promise<AwsS3Namespace>;
|
|
4
|
+
export type Modified = {
|
|
5
|
+
now: number;
|
|
6
|
+
modified: {
|
|
7
|
+
unix: null | number;
|
|
8
|
+
vs_now: {
|
|
9
|
+
months: number;
|
|
10
|
+
days: number;
|
|
11
|
+
hours: number;
|
|
12
|
+
minutes: number;
|
|
13
|
+
};
|
|
14
|
+
vs_midnight: {
|
|
15
|
+
hours: number;
|
|
16
|
+
minutes: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type ReadFileResponse = Modified & {
|
|
21
|
+
body: any;
|
|
22
|
+
error: any;
|
|
23
|
+
};
|
|
24
|
+
export declare const readFileDefault: ReadFileResponse;
|
|
25
|
+
export { payloadSchema, PayloadSchemaType } from "./payload";
|
package/aws/s3/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.payloadSchema = exports.readFileDefault = exports.awsS3Client = void 0;
|
|
4
|
+
const AwsS3Namespace_1 = require("./AwsS3Namespace");
|
|
5
|
+
const index_1 = require("../index");
|
|
6
|
+
const awsS3Namespaces = new Map();
|
|
7
|
+
const awsS3Client = async (key = "default", config, vaultId, itemId) => {
|
|
8
|
+
if (awsS3Namespaces.has(key)) {
|
|
9
|
+
return awsS3Namespaces.get(key);
|
|
10
|
+
}
|
|
11
|
+
const instanceConfig = await (0, index_1.getConfig)(key, config, vaultId, itemId);
|
|
12
|
+
const namespace = new AwsS3Namespace_1.AwsS3Namespace(key, instanceConfig);
|
|
13
|
+
awsS3Namespaces.set(key, namespace);
|
|
14
|
+
return namespace;
|
|
15
|
+
};
|
|
16
|
+
exports.awsS3Client = awsS3Client;
|
|
17
|
+
exports.readFileDefault = {
|
|
18
|
+
body: undefined,
|
|
19
|
+
now: undefined,
|
|
20
|
+
error: undefined,
|
|
21
|
+
modified: {
|
|
22
|
+
unix: null,
|
|
23
|
+
vs_now: {
|
|
24
|
+
months: 0,
|
|
25
|
+
days: 0,
|
|
26
|
+
hours: 0,
|
|
27
|
+
minutes: 0,
|
|
28
|
+
},
|
|
29
|
+
vs_midnight: {
|
|
30
|
+
hours: 0,
|
|
31
|
+
minutes: 0,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
var payload_1 = require("./payload");
|
|
36
|
+
Object.defineProperty(exports, "payloadSchema", { enumerable: true, get: function () { return payload_1.payloadSchema; } });
|