@pi-r/aws-lib 0.6.0 → 0.6.2
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/index.js +18 -4
- package/package.json +2 -4
- package/types/index.d.ts +25 -3
package/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBucketKey = exports.checkBucketCannedACL = exports.setDatabaseEndpoint = exports.setEndpoint = exports.getPrivatePolicy = exports.getBucketPublicReadPolicy = exports.getPublicReadPolicy = exports.isDatabaseDefined = exports.isProviderChainDefined = exports.isSharedCredentialsDefined = exports.isEnvDefined = exports.isAccessDefined = void 0;
|
|
4
|
-
const types_1 = require("@e-mc/types");
|
|
3
|
+
exports.getBucketKey = exports.formatDefaultRetention = exports.checkBucketCannedACL = exports.setDatabaseEndpoint = exports.setEndpoint = exports.getPrivatePolicy = exports.getBucketPublicReadPolicy = exports.getPublicReadPolicy = exports.isDatabaseDefined = exports.isProviderChainDefined = exports.isSharedCredentialsDefined = exports.isEnvDefined = exports.isAccessDefined = void 0;
|
|
5
4
|
function isAccessDefined(credential) {
|
|
6
5
|
return !!(credential.accessKeyId && credential.secretAccessKey);
|
|
7
6
|
}
|
|
@@ -68,14 +67,14 @@ exports.getPrivatePolicy = getPrivatePolicy;
|
|
|
68
67
|
function setEndpoint(config, instance, fallbackRegion) {
|
|
69
68
|
let { region, endpoint } = config;
|
|
70
69
|
if (!endpoint) {
|
|
71
|
-
const location =
|
|
70
|
+
const location = typeof region === 'string' && region || process.env.AWS_REGION || fallbackRegion;
|
|
72
71
|
if (location) {
|
|
73
72
|
endpoint = `https://${instance}.${location}.amazonaws.com`;
|
|
74
73
|
config.endpoint = endpoint;
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
if (!region) {
|
|
78
|
-
region = (
|
|
77
|
+
region = (typeof endpoint === 'string' && new RegExp(`\\b${instance}\\.([^.]+)\\.`, 'i').exec(endpoint)?.[1] || process.env.AWS_REGION || fallbackRegion)?.toLowerCase();
|
|
79
78
|
if (region && region !== "us-east-1" /* STRINGS.REGION */) {
|
|
80
79
|
config.region = region;
|
|
81
80
|
}
|
|
@@ -96,5 +95,20 @@ function checkBucketCannedACL(value) {
|
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
exports.checkBucketCannedACL = checkBucketCannedACL;
|
|
98
|
+
function formatDefaultRetention(retention) {
|
|
99
|
+
const { Years = 0, Days = 0, Mode } = retention;
|
|
100
|
+
const status = [];
|
|
101
|
+
if (Years > 0) {
|
|
102
|
+
status.push(Years.toString() + 'Y');
|
|
103
|
+
}
|
|
104
|
+
if (Days > 0) {
|
|
105
|
+
status.push(Days.toString() + 'D');
|
|
106
|
+
}
|
|
107
|
+
if (Mode) {
|
|
108
|
+
status.push(status.length ? `(${Mode})` : Mode);
|
|
109
|
+
}
|
|
110
|
+
return status.join(' ');
|
|
111
|
+
}
|
|
112
|
+
exports.formatDefaultRetention = formatDefaultRetention;
|
|
99
113
|
const getBucketKey = (credential, bucket, acl, service, sdk) => JSON.stringify(credential) + bucket + '_' + (acl || '') + service + sdk;
|
|
100
114
|
exports.getBucketKey = getBucketKey;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/aws-lib",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "AWS cloud utility functions for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -20,7 +20,5 @@
|
|
|
20
20
|
"author": "An Pham <anpham6@gmail.com>",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@e-mc/types": "^0.8.3"
|
|
25
|
-
}
|
|
23
|
+
"dependencies": {}
|
|
26
24
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { CloudDatabase } from '@e-mc/types/lib/cloud';
|
|
2
|
-
|
|
3
1
|
declare namespace AWS {
|
|
4
2
|
type BucketCannedACL = "authenticated-read" | "private" | "public-read" | "public-read-write";
|
|
5
3
|
type ObjectCannedACL = BucketCannedACL | "bucket-owner-full-control" | "bucket-owner-read";
|
|
@@ -65,18 +63,42 @@ declare namespace AWS {
|
|
|
65
63
|
protocol: string;
|
|
66
64
|
}
|
|
67
65
|
|
|
66
|
+
interface DefaultRetention {
|
|
67
|
+
/**
|
|
68
|
+
* @public
|
|
69
|
+
* <p>The default Object Lock retention mode you want to apply to new objects placed in the
|
|
70
|
+
* specified bucket. Must be used with either <code>Days</code> or <code>Years</code>.</p>
|
|
71
|
+
*/
|
|
72
|
+
Mode?: ObjectLockRetentionMode;
|
|
73
|
+
/**
|
|
74
|
+
* @public
|
|
75
|
+
* <p>The number of days that you want to specify for the default retention period. Must be
|
|
76
|
+
* used with <code>Mode</code>.</p>
|
|
77
|
+
*/
|
|
78
|
+
Days?: number;
|
|
79
|
+
/**
|
|
80
|
+
* @public
|
|
81
|
+
* <p>The number of years that you want to specify for the default retention period. Must be
|
|
82
|
+
* used with <code>Mode</code>.</p>
|
|
83
|
+
*/
|
|
84
|
+
Years?: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
68
87
|
type Provider<T> = () => Promise<T>;
|
|
88
|
+
type ObjectLockRetentionMode = "GOVERNANCE" | "COMPLIANCE" | string; // eslint-disable-line @typescript-eslint/no-redundant-type-constituents
|
|
69
89
|
|
|
70
90
|
function isAccessDefined(credential: AccessConfig): boolean;
|
|
71
91
|
function isEnvDefined(): boolean;
|
|
72
92
|
function isSharedCredentialsDefined(): boolean;
|
|
73
93
|
function isProviderChainDefined(): boolean;
|
|
74
|
-
function isDatabaseDefined(credential: unknown, data:
|
|
94
|
+
function isDatabaseDefined(credential: unknown, data: unknown): boolean;
|
|
75
95
|
function getPublicReadPolicy(bucket: string, authenticated?: boolean, write?: boolean): string;
|
|
76
96
|
function getBucketPublicReadPolicy(bucket: string): string;
|
|
77
97
|
function getPrivatePolicy(bucket: string): string;
|
|
78
98
|
function setDatabaseEndpoint(config: EndpointConfig, fallbackRegion?: string): void;
|
|
79
99
|
function setEndpoint(config: EndpointConfig, instance: string, fallbackRegion?: string): void;
|
|
100
|
+
function checkBucketCannedACL(value: unknown): BucketCannedACL | undefined;
|
|
101
|
+
function formatDefaultRetention(retention: DefaultRetention): string;
|
|
80
102
|
function getBucketKey(credential: unknown, bucket: string, acl: string | undefined, service: string, sdk: string): string;
|
|
81
103
|
}
|
|
82
104
|
|